Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 def test_function_validate_email(self):
     user = User(username='******', email='*****@*****.**')
     self.assertIsNone(validate_email('*****@*****.**', user=user))
Exemplo n.º 7
0
 def setUp(self):
     self.user = User(username='******', email='*****@*****.**')