Exemplo n.º 1
0
 def test_missing_parameters(self):
     """
     If we don't pass in all the required parameters, get an error
     """
     self.assertEqual(0, self.session.query(User).count())
     for i in ['username', 'email', 'password']:
         self.request.json_body = deepcopy(self.new_account)
         del self.request.json_body[i]
         result = users_post_view(self.request)['d']
         self.assertEqual(
             result,
             error_dict(
                 'api_errors',
                 'username, email, and password are all required string fields'
             ))
     self.request.json_body = {}
     result = users_post_view(self.request)['d']
     self.assertEqual(
         result,
         error_dict(
             'api_errors',
             'username, email, and password are all required string fields')
     )
     self.request.json_body = {'username': '******'}
     result = users_post_view(self.request)['d']
     self.assertEqual(
         result,
         error_dict(
             'api_errors',
             'username, email, and password are all required string fields')
     )
Exemplo n.º 2
0
 def test_username_not_in_use(self):
     """
     If we provide a username that is not in use, get False
     """
     self.request.json_body = {'username': '******'}
     self.datautils.create_user({'username': '******', 'password': '******'})
     result = users_post_view(self.request)['d']
     self.assertIsInstance(result, dict)
     self.assertEqual(result, error_dict('api_errors', 'username, email, and password are all required string fields'))
Exemplo n.º 3
0
 def test_username_in_use(self):
     """
     If we provide a username that is in use, get True
     """
     self.request.json_body = {'username': '******'}
     self.datautils.create_user({'username': '******', 'password': '******'})
     result = users_post_view(self.request)['d']
     self.assertIsInstance(result, dict)
     self.assertEqual(result, error_dict('verification_error', 'username already in use: testuser'))
Exemplo n.º 4
0
 def test_username_taken(self):
     """
     If we try to create an account that is in use, get an api error
     """
     self.datautils.create_user({'username': '******'})
     self.assertEqual(1, self.session.query(User).count())
     self.request.json_body = deepcopy(self.new_account)
     result = users_post_view(self.request)['d']
     self.assertEqual(result, error_dict('verification_error',
                                         'username already in use: %s' % self.new_account['username']))
Exemplo n.º 5
0
 def test_get_user_and_token_after_creation(self):
     """
     If we create a user, we should get a user and a session back
     """
     self.request.json_body = deepcopy(self.new_account)
     result = users_post_view(self.request)['d']
     session = self.session.query(Session).one()
     user = self.session.query(User).one()
     expected = dict_from_row(user, remove_fields=removals)
     expected['session'] = dict_from_row(session, remove_fields=removals)
     self.assertEqual(result, expected)
Exemplo n.º 6
0
 def test_bad_parameters(self):
     """
     If we don't pass in all the right types, get an error
     """
     self.assertEqual(0, self.session.query(User).count())
     for i in ['username', 'email', 'password']:
         self.request.json_body = deepcopy(self.new_account)
         for val in [x for x in bad_data_typevals_list if not isinstance(x, basestring)]:
             self.request.json_body[i] = val
             result = users_post_view(self.request)['d']
             self.assertEqual(result, error_dict('api_errors',
                                                 'username, email, and password are all required string fields'))
Exemplo n.º 7
0
 def test_password_is_hashed(self):
     """
     If we create a user, their password should be a hash
     """
     self.request.json_body = deepcopy(self.new_account)
     result = users_post_view(self.request)['d']
     user = self.session.query(User).one()
     expected = dict_from_row(user, remove_fields=removals)
     session = self.session.query(Session).one()
     expected['session'] = dict_from_row(session, remove_fields=removals)
     self.assertEqual(result, expected)
     user = self.session.query(User).one()
     self.assertNotEqual(user.password, self.new_account['password'])