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'])
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()
def test_to_json(self): user = add_user('justatest', '*****@*****.**', 'password') self.assertTrue(isinstance(user.to_json(), dict))
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)
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)
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))
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)