def test_it_should_not_validate_if_any_fields_missing(self): s = TokenObtainSerializer(data={}) self.assertFalse(s.is_valid()) self.assertIn(s.username_field, s.errors) self.assertIn('password', s.errors) s = TokenObtainSerializer(data={ TokenObtainSerializer.username_field: 'oieanrst', }) self.assertFalse(s.is_valid()) self.assertIn('password', s.errors) s = TokenObtainSerializer(data={ 'password': '******', }) self.assertFalse(s.is_valid()) self.assertIn(s.username_field, s.errors)
def test_it_should_not_validate_if_user_not_found(self): s = TokenObtainSerializer(data={ TokenObtainSerializer.username_field: 'missing', 'password': '******', }) self.assertFalse(s.is_valid()) self.assertIn('non_field_errors', s.errors)
def test_it_should_not_validate_if_user_not_active(self): self.user.is_active = False self.user.save() s = TokenObtainSerializer( data={ TokenObtainSerializer.username_field: self.username, 'password': self.password, }) self.assertFalse(s.is_valid()) self.assertIn('non_field_errors', s.errors)