def execute(self, *args, **kwargs): valid_user = User(username=self.username, email=self.email) self._validate(valid_user) user = User(username=self.username, email=self.email, is_active=True) return self.user_repo.create_user(user=user, password=self.password)
def test_user_serializer(self): users = [] for i in range(3): user = User(id=i, username='******' % i, email='*****@*****.**' % i, is_active=True, is_staff=False) users.append(user) serilalizer = [ { 'id': 0, 'username': '******', 'email': '*****@*****.**', 'is_active': True, 'is_staff': False }, { 'id': 1, 'username': '******', 'email': '*****@*****.**', 'is_active': True, 'is_staff': False }, { 'id': 2, 'username': '******', 'email': '*****@*****.**', 'is_active': True, 'is_staff': False }, ] self.assertListEqual(UserListSerializer.serialize(users), serilalizer)
def _decode_db_user(self, db_user): fileds = { 'id': db_user.id, 'username': db_user.username, 'email': db_user.email, 'is_active': db_user.is_active, 'is_staff': db_user.is_staff, } return User(**fileds)
def test_user_serializer(self): user = User(id=1, username='******', email='*****@*****.**', is_active=True, is_staff=False) serilalizer = { 'id': 1, 'username': '******', 'email': '*****@*****.**', 'is_active': True, 'is_staff': False, } self.assertDictEqual(UserSerializer.serialize(user), serilalizer)
def test_function_validate_email_except(self): user = User(username='******', email='*****@*****.**') with self.assertRaises(InvalidEntityException): validate_email('exampleamil.ru', user=user) with self.assertRaises(InvalidEntityException): validate_email('@exampleamil.ru', user=user) with self.assertRaises(InvalidEntityException): validate_email('exampleamil.ru@', user=user) with self.assertRaises(InvalidEntityException): validate_email('[email protected]', user=user) with self.assertRaises(InvalidEntityException): validate_email('exampleamil.@ru', user=user)
def test_function_validate_email(self): user = User(username='******', email='*****@*****.**') self.assertIsNone(validate_email('*****@*****.**', user=user))
def setUp(self): self.user = User(username='******', email='*****@*****.**')