Пример #1
0
 def test_register_duplicate_user(self):
     user = UserModel('test', 'password', True)
     user.save_to_db()
     response = self.client.post(
         '/register',
         data=json.dumps({
             'username': '******',
             'password': '******'
         }),
         headers={'Content-Type': 'application/json'})
     self.assertEqual(response.status_code, 400)
     expected = {"message": "A user with that username already exists"}
     self.assertDictEqual(expected, json.loads(response.data))
Пример #2
0
 def setUp(self):
     super(TeamTest, self).setUp()
     UserModel('test', 'password', True).save_to_db()
     auth_response = self.client.post('/login',
                                      data=json.dumps({'username': '******', 'password': '******'}),
                                      headers={'Content-Type': 'application/json'})
     self.token = 'Bearer {}'.format(json.loads(auth_response.data).get('access_token'))
Пример #3
0
 def test_register_and_login(self):
     UserModel('test', 'password', True).save_to_db()
     auth_response = self.client.post(
         '/login',
         data=json.dumps({
             'username': '******',
             'password': '******'
         }),
         headers={'Content-Type': 'application/json'})
     self.assertIn('access_token', json.loads(auth_response.data).keys())
Пример #4
0
 def test_register_user(self):
     response = self.client.post(
         '/register',
         data=json.dumps({
             'username': '******',
             'password': '******'
         }),
         headers={'Content-Type': 'application/json'})
     self.assertEqual(response.status_code, 201)
     self.assertIsNotNone(UserModel.find_by_username('test'))
     expected = {"message": "User 'test' created successfully."}
     self.assertDictEqual(expected, json.loads(response.data))
Пример #5
0
    def test_user_crud(self):
        user = UserModel('Test', 'password', False)

        self.assertIsNone(
            user.find_by_username('Test'),
            "Found a user with name '{}', but expected not to.".format(
                user.username))
        self.assertIsNone(user.find_by_id(1),
                          "Found a user with id: 1, but expected not to.")

        user.save_to_db()

        self.assertIsNotNone(
            user.find_by_username('Test'),
            "Did not find a user with name '{}', but expected to.".format(
                user.username))
        self.assertIsNotNone(
            user.find_by_id(1),
            "Did not find a user with id: 1, but expected to.")

        user.delete_from_db()

        self.assertIsNone(
            user.find_by_username('Test'),
            "Found a user with name '{}', but expected not to.".format(
                user.username))
        self.assertIsNone(user.find_by_id(1),
                          "Found a user with id: 1, but expected not to.")
Пример #6
0
    def test_create_user(self):
        user = UserModel('Test', 'password', False)

        self.assertIsNotNone(user)
        self.assertEqual(user.username, 'Test')
        self.assertEqual(user.password, 'password')
Пример #7
0
 def test_user_json(self):
     user = UserModel('Test', 'password', False)
     expected = {'username': '******'}
     self.assertDictEqual(user.json(), expected)