Ejemplo n.º 1
0
    def test_add_user_duplicate_email(self):
        add_user('justatest', '*****@*****.**', 'greaterthaneight')

        duplicate_user = User(username='******',
                              email='*****@*****.**',
                              password='******')

        db.session.add(duplicate_user)
        self.assertRaises(IntegrityError, db.session.commit)
Ejemplo n.º 2
0
 def test_main_with_users(self):
     """Ensure the main route behaves correctly when
     users have been added to the database."""
     add_user('michael', '*****@*****.**', 'greaterthaneight')
     add_user('fletcher', '*****@*****.**', 'greaterthaneight')
     with self.client:
         response = self.client.get('/')
         self.assertEqual(response.status_code, 200)
         self.assertIn(b'<h1>All Users</h1>', response.data)
         self.assertNotIn(b'<p>No users!</p>', response.data)
         self.assertIn(b'michael', response.data)
         self.assertIn(b'fletcher', response.data)
Ejemplo n.º 3
0
 def test_all_users(self):
     """Ensure get all users behaves correctly."""
     add_user('michael', '*****@*****.**', 'greaterthaneight')
     add_user('fletcher', '*****@*****.**', 'greaterthaneight')
     with self.client:
         response = self.client.get(f'/users')
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 200)
         self.assertEqual(len(data['data']['users']), 2)
         self.assertIn('michael', data['data']['users'][0]['username'])
         self.assertIn('*****@*****.**',
                       data['data']['users'][0]['email'])
         self.assertIn('fletcher', data['data']['users'][1]['username'])
         self.assertIn('*****@*****.**',
                       data['data']['users'][1]['email'])
         self.assertIn('success', data['status'])
Ejemplo n.º 4
0
    def test_add_user(self):
        user = add_user('justatest', '*****@*****.**', 'greaterthaneight')

        self.assertTrue(user.id)
        self.assertEqual(user.username, 'justatest')
        self.assertEqual(user.email, '*****@*****.**')
        self.assertTrue(user.active)
Ejemplo n.º 5
0
 def test_single_user(self):
     """Ensure get single user behaves correctly."""
     user = add_user('michael', '*****@*****.**', 'greaterthaneight')
     with self.client:
         response = self.client.get(f'/users/{user.id}')
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 200)
         self.assertIn('michael', data['data']['username'])
         self.assertIn('*****@*****.**', data['data']['email'])
         self.assertIn('success', data['status'])
Ejemplo n.º 6
0
 def test_decode_auth_token(self):
     user = add_user('justatest', '*****@*****.**', 'test')
     auth_token = User.encode_auth_token(user.id)
     self.assertEqual(User.decode_auth_token(auth_token), user.id)
Ejemplo n.º 7
0
 def test_encode_auth_token(self):
     user = add_user('justatest', '*****@*****.**', 'test')
     auth_token = User.encode_auth_token(user.id)
     self.assertTrue(isinstance(auth_token, bytes))
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def test_to_json(self):
        user = add_user('justatest', '*****@*****.**', 'greaterthaneight')

        self.assertTrue(isinstance(user.to_json(), dict))