Пример #1
0
 def test_user_registration_duplicate_username(self):
     add_user('test', '*****@*****.**', 'test')
     with self.client:
         response = self.client.post(
             '/auth/register',
             data=json.dumps({
                 'username': '******',
                 'email': '[email protected]',
                 'password': '******'
             }),
             content_type='application/json',
         )
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 400)
         self.assertIn(
             'Sorry. That user already exists.', data['message'])
         self.assertIn('fail', data['status'])
Пример #2
0
 def test_add_user_duplicate_username(self):
     user = add_user('justatest', '*****@*****.**', 'password')
     duplicate_user = User(
         username='******',
         email='*****@*****.**',
         password='******',
     )
     db.session.add(duplicate_user)
     with self.assertRaises(IntegrityError):
         db.session.commit()
Пример #3
0
 def test_to_json(self):
     user = add_user('justatest', '*****@*****.**', 'password')
     self.assertTrue(isinstance(user.to_json(), dict))
Пример #4
0
 def test_passwords_are_random(self):
     user_one = add_user('justatest', '*****@*****.**', 'greaterthaneight')
     user_two = add_user('justatest2', '*****@*****.**', 'greaterthaneight')
     self.assertNotEqual(user_one.password, user_two.password)
Пример #5
0
 def test_decode_auth_token(self):
     user = add_user('justatest', '*****@*****.**', 'test')
     auth_token = user.encode_auth_token(user.id)
     self.assertTrue(isinstance(auth_token, bytes))
     self.assertEqual(User.decode_auth_token(auth_token), user.id)
Пример #6
0
 def test_encode_auth_token(self):
     user = add_user('justatest', '*****@*****.**', 'test')
     auth_token = user.encode_auth_token(user.id)
     print(auth_token)
     self.assertTrue(isinstance(auth_token, bytes))
Пример #7
0
 def test_add_user(self):
     user = add_user('justatest', '*****@*****.**', 'password')
     self.assertTrue(user.id)
     self.assertEqual(user.username, 'justatest')
     self.assertEqual(user.email, '*****@*****.**')
     self.assertTrue(user.active)