diff options
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r-- | archaeological_finds/tests.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 3c9995632..d9b79be89 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -937,6 +937,45 @@ class FindSearchTest(FindInit, TestCase): self._test_search(c, result) +class FindAutocompleteTest(FindInit, TestCase): + fixtures = WAREHOUSE_FIXTURES + model = models.Find + + def setUp(self): + self.create_finds(force=True) + self.create_finds(force=True) + self.create_finds(force=True) + self.create_finds(force=True) + self.username = 'myuser' + self.password = 'mypassword' + User.objects.create_superuser(self.username, 'myemail@test.com', + self.password) + self.client = Client() + + def test_autocomplete(self): + find = self.finds[0] + find.label = "test 012" + find.save() + find2 = self.finds[1] + find2.label = "test 12" + find2.save() + find3 = self.finds[2] + find3.label = "test 1" + find3.save() + find4 = self.finds[3] + find4.label = "test 0120" + find4.save() + c = Client() + c.login(username=self.username, password=self.password) + response = c.get(reverse('autocomplete-find') + "?term=12") + self.assertEqual(response.status_code, 200) + res = json.loads(response.content) + self.assertEqual(len(res), 3) + self.assertEqual(res[0]['id'], find2.pk) # " 12" - startswith + self.assertEqual(res[1]['id'], find.pk) # 12 - endswith + self.assertEqual(res[2]['id'], find4.pk) # 12 - contains + + class FindPermissionTest(FindInit, TestCase): fixtures = FIND_FIXTURES model = models.Find |