def setUp(self): self.adam = User.objects.create_user( 'adam', '*****@*****.**', 'password' ) self.eve = User.objects.create_user('eve', '*****@*****.**', 'password') self.andre = User.objects.create_user( 'andré', '*****@*****.**', 'password' ) self.dummy = DummyModel() self.dummy.save() self.client = Client() self.request = RequestFactory()
class TestItCase(TestCase): def setUp(self): self.adam = User.objects.create_user( 'adam', '*****@*****.**', 'password' ) self.eve = User.objects.create_user('eve', '*****@*****.**', 'password') self.andre = User.objects.create_user( 'andré', '*****@*****.**', 'password' ) self.dummy = DummyModel() self.dummy.save() self.client = Client() self.request = RequestFactory() def test_monkey(self): # Are we using the autocomplete widget? form = EditDummyForm(self.request, instance=self.dummy) self.failUnless( isinstance(form.fields['user'].widget, AutoCompleteWidget) ) def test_json(self): # Find our token in cache for token, pickled in _simple_autocomplete_queryset_cache.items(): app_label, model_name, dc = pickle.loads(pickled) if (app_label == 'auth') and (model_name == 'user'): break url = reverse('simple-autocomplete', args=[token]) response = self.client.get(url, {'q': 'ada'}) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, """[[1, "adam"]]""") def test_unicode(self): # Find our token in cache for token, pickled in _simple_autocomplete_queryset_cache.items(): app_label, model_name, dc = pickle.loads(pickled) if (app_label == 'auth') and (model_name == 'user'): break url = reverse('simple-autocomplete', args=[token]) response = self.client.get(url, {'q': 'andr'}) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, """[[3, "andr\u00e9"]]""")