Esempio n. 1
0
 def test_user_password_hash_fits_column(self):
     with self.create_storage() as storage:
         user = generate_user()
         user.password_hash = hash(user.password_hash)
         storage.add(user)
     with self.create_storage() as storage:
         read = storage.get_user_by_email(user.email)
         self.assertUser(user, read)
Esempio n. 2
0
 def test_user_password_hash_fits_column(self):
     with self.create_storage() as storage:
         user = generate_user()
         user.password_hash = hash(user.password_hash)
         storage.add(user)
     with self.create_storage() as storage:
         read = storage.get_user_by_email(user.email)
         self.assertUser(user, read)
Esempio n. 3
0
    def test_user_authenticate_success(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('pass1234'), True)
        self.add_user(user)

        request = {'email': u'*****@*****.**', 'password': u'pass1234'}
        user = users.authenticate(request)

        self.assertIsNotNone(user)
Esempio n. 4
0
    def test_user_authenticate_success(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('pass1234'), True)
        self.add_user(user)

        request = {'email': u'*****@*****.**', 'password': u'pass1234'}
        user = users.authenticate(request)

        self.assertIsNotNone(user)
Esempio n. 5
0
    def test_user_create_existing_email(self):
        users = self.get_users_service()
        existing = User(u'*****@*****.**', hash('pass123456'), True)
        self.add_user(existing)

        request = {'email': '*****@*****.**', 'password': '******'}

        with self.assertRaises(ServiceException) as context:
            users.create_new_user(request)
        self.assertEquals(context.exception.status_code, 400)
Esempio n. 6
0
    def test_user_create_existing_email(self):
        users = self.get_users_service()
        existing = User(u'*****@*****.**', hash('pass123456'), True)
        self.add_user(existing)

        request = {'user_domain': 'vladimir', 'email': '*****@*****.**', 'password': '******'}

        with self.assertRaises(ServiceException) as context:
            users.create_new_user(request)
        self.assertEquals(context.exception.status_code, 409)
Esempio n. 7
0
    def test_user_set_subscribed_false(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('pass'), True)
        self.add_user(user)

        request = {'subscribed': 'false'}
        users.user_set_subscribed(request, user.email)

        user = self.get_user(user.email)
        self.assertTrue(user.unsubscribed)
Esempio n. 8
0
    def test_user_authenticate_missing_password(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('otherpass1234'), True)
        self.add_user(user)

        request = {'email': '*****@*****.**'}
        with self.assertRaises(ServiceException) as context:
            users.authenticate(request)

        self.assertEquals(context.exception.status_code, 400)
Esempio n. 9
0
    def test_user_set_subscribed_false(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('pass'), True)
        self.add_user(user)

        request = {'subscribed': 'false'}
        users.user_set_subscribed(request, user.email)

        user = self.get_user(user.email)
        self.assertTrue(user.unsubscribed)
Esempio n. 10
0
    def test_user_authenticate_wrong_password(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('otherpass1234'), True)
        self.add_user(user)

        request = {'email': '*****@*****.**', 'password': '******'}
        with self.assertRaises(ServiceException) as context:
            users.authenticate(request)

        self.assertEquals(context.exception.status_code, 400)
Esempio n. 11
0
    def test_user_authenticate_non_active(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('pass1234'), active=False)
        user.enable_action(ActionType.ACTIVATE)
        self.add_user(user)

        request = {'email': '*****@*****.**', 'password': '******'}
        with self.assertRaises(ServiceException) as context:
            users.authenticate(request)

        self.assertEquals(context.exception.status_code, 403)
Esempio n. 12
0
    def test_user_authenticate_non_active(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('pass1234'), active=False)
        user.enable_action(ActionType.ACTIVATE)
        self.add_user(user)

        request = {'email': '*****@*****.**', 'password': '******'}
        with self.assertRaises(ServiceException) as context:
            users.authenticate(request)

        self.assertEquals(context.exception.status_code, 400)
Esempio n. 13
0
    def test_user_authenticate_missing_password(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('otherpass1234'), True)
        self.add_user(user)

        request = {'email': '*****@*****.**'}
        with self.assertRaises(ServiceException) as context:
            users.authenticate(request)

        exc = context.exception
        self.assertEquals(exc.status_code, 400)
        self.assertGreater(len(exc.message), 0)
        self.assertEquals(len(exc.parameters_errors), 1)
        self.assertGreater(len(exc.parameters_errors['password']), 0)
Esempio n. 14
0
    def test_user_authenticate_missing_password(self):
        users = self.get_users_service()
        user = User(u'*****@*****.**', hash('otherpass1234'), True)
        self.add_user(user)

        request = {'email': '*****@*****.**'}
        with self.assertRaises(ServiceException) as context:
            users.authenticate(request)

        exc = context.exception
        self.assertEquals(exc.status_code, 400)
        self.assertGreater(len(exc.message), 0)
        self.assertEquals(len(exc.parameters_errors), 1)
        self.assertGreater(len(exc.parameters_errors['password']), 0)
Esempio n. 15
0
 def test_not_equal_input(self):
     h1 = hash('some string')
     h2 = hash('some other string')
     self.assertNotEqual(h1, h2)
Esempio n. 16
0
 def test_empty(self):
     h = hash('non empty string')
     self.assertIsNotNone(h)
     self.assertIsNot('', h)
Esempio n. 17
0
def generate_user():
    email = unicode(create_token() + '@mail.com')
    user = User(email, hash('pass1234'), False)
    user.enable_action(ActionType.ACTIVATE)
    return user
Esempio n. 18
0
 def test_empty(self):
     h = hash('non empty string')
     self.assertIsNotNone(h)
     self.assertIsNot('', h)
Esempio n. 19
0
 def test_not_equal_input(self):
     h1 = hash('some string')
     h2 = hash('some other string')
     self.assertNotEqual(h1, h2)
Esempio n. 20
0
def generate_user():
    email = unicode(create_token() + '@mail.com')
    user = User(email, hash('pass1234'), False)
    user.enable_action(ActionType.ACTIVATE)
    return user