Пример #1
0
 def test_error_anonymous_bad_sprout(self):
     data = {'tuber': 'HAMMMMMMMMMMMMM', 'sprout': ''}
     serializer = PotatoCaptchaSerializer(data=data, context=self.context)
     eq_(serializer.is_valid(), False)
Пример #2
0
 def test_error_anonymous_bad_tuber_and_sprout(self):
     serializer = PotatoCaptchaSerializer(data={}, context=self.context)
     eq_(serializer.is_valid(), False)
Пример #3
0
 def test_success_authenticated(self):
     self.request.user = User.objects.get(id=999)
     self.request.user.is_authenticated = lambda: True
     serializer = PotatoCaptchaSerializer(data={}, context=self.context)
     eq_(serializer.is_valid(), True)
Пример #4
0
 def test_success_anonymous(self):
     data = {'tuber': '', 'sprout': 'potato'}
     serializer = PotatoCaptchaSerializer(data=data, context=self.context)
     eq_(serializer.is_valid(), True)
Пример #5
0
 def test_error_anonymous_bad_tuber_and_sprout(self):
     serializer = PotatoCaptchaSerializer(data={}, context=self.context)
     eq_(serializer.is_valid(), False)
Пример #6
0
 def test_error_anonymous_bad_sprout(self):
     data = {'tuber': 'HAMMMMMMMMMMMMM', 'sprout': ''}
     serializer = PotatoCaptchaSerializer(data=data, context=self.context)
     eq_(serializer.is_valid(), False)
Пример #7
0
 def test_no_context(self):
     data = {'tuber': '', 'sprout': 'potato'}
     with self.assertRaises(ValidationError):
         PotatoCaptchaSerializer(data=data)
Пример #8
0
 def test_success_anonymous(self):
     data = {'tuber': '', 'sprout': 'potato'}
     serializer = PotatoCaptchaSerializer(data=data, context=self.context)
     eq_(serializer.is_valid(), True)
Пример #9
0
 def test_success_authenticated(self):
     self.request.user = UserProfile.objects.get(id=999)
     self.request.user.is_authenticated = lambda: True
     serializer = PotatoCaptchaSerializer(data={}, context=self.context)
     eq_(serializer.is_valid(), True)