def test_login_without_password(self): request = construct_dummy_request() request.json_body = {'nickname': 'Walter'} response = apiviews.user_login(request) self.assertIn('nickname', request.validated) self.assertEqual(400, response.status_code) self.assertIsInstance(response, httpexceptions.HTTPError)
def test_login_empty_user_is_not_allowed_to_login(self): request = construct_dummy_request(json_body={ 'nickname': '', 'password': '******' }) response = apiviews.user_login(request) self.assertEqual(401, response.status_code) self.assertIsInstance(response, httpexceptions.HTTPError)
def test_valid_login_attempt(self): request = construct_dummy_request(json_body={ 'nickname': 'Walter', 'password': '******' }) response = apiviews.user_login(request) self.assertIn('nickname', request.validated) self.assertIn('token', response) self.assertIn('nickname', response)
def test_login_wrong_user(self): request = construct_dummy_request(json_body={ 'nickname': r'¯\_(ツ)_/¯', 'password': '******' }) response = apiviews.user_login(request) self.assertIn('nickname', request.validated) self.assertEqual(401, response.status_code) self.assertIsInstance(response, httpexceptions.HTTPError)
def test_login_wrong_password(self, password: str): pwd = password.replace('\x00', '') pwd = pwd.replace('iamatestuser2016', r'¯\_(ツ)_/¯') request = construct_dummy_request(json_body={ 'nickname': 'Walter', 'password': pwd }) response = apiviews.user_login(request) self.assertIn('nickname', request.validated) self.assertEqual(401, response.status_code) self.assertIsInstance(response, httpexceptions.HTTPError)