def create_context(json_data=dict(), params=dict(), headers=dict(), form=dict(), files=dict()): ctx = QRContext(json_data, params, headers, form, files, repository=MockSearchRepository()) ctx.add_manager(MockTokenManager.get_name(), MockTokenManager()) return ctx
def test_failure(self): token = MockTokenManager().make_token(user_id=2) res = register_event( create_context(headers={'Authorization': token}, json_data={ 'time': 12345, 'event': 'a' })) self.assertEqual(500, res.status_code)
def test_failed_to_update(self): token = MockTokenManager().make_token(user_id=2) res = update_user( create_context(form={ 'login': '******', 'password': '******' }, headers={'Authorization': token})) self.assertEqual(500, res.status_code)
def test_login_not_exists(self): token = MockTokenManager().make_token(user_id=1) res = update_user( create_context(form={ 'login': '******', 'password': '******' }, headers={'Authorization': token})) self.assertEqual(500, res.status_code)
def test_success(self): token = MockTokenManager().make_token(user_id=1) res = update_user( create_context(form={ 'login': '******', 'password': '******', 'name': 'c' }, headers={'Authorization': token})) self.assertEqual(200, res.status_code)
def test_all_data(self): token = MockTokenManager().make_token(user_id=1) res = register_event( create_context(headers={'Authorization': token}, json_data={ 'time': 12345, 'event': 'a', 'data': { 'a': 'a', 'b': 'b' } })) self.assertEqual(200, res.status_code)
def test_success(self): token = MockTokenManager().make_token(user_id=1) res = user_info(create_context(headers={'Authorization': token})) self.assertEqual(200, res.status_code) self.assertEqual( { 'id': 1, 'name': 'a', 'last_name': 'a', 'avatar': None, 'email': '*****@*****.**', 'login': '******' }, res.result)
def test_success(self): token = MockTokenManager().make_token(user_id=1) res = get_book(create_context(headers={'Authorization': token}), 'a') self.assertEqual(200, res.status_code) self.assertEqual('a', res.result)
def test_failure(self): token = MockTokenManager().make_token(user_id=1) res = get_avatar(create_context(headers={'Authorization': token}), 'xxx') self.assertEqual('file not found', res.result)
def test_failure(self): token = MockTokenManager().make_token(user_id=2) res = delete_profile(create_context(headers={'Authorization': token})) self.assertEqual(500, res.status_code)
def test_not_found(self): token = MockTokenManager().make_token(user_id=2) res = user_info(create_context(headers={'Authorization': token})) self.assertEqual(500, res.status_code) self.assertNotEqual(res.result.find('not found'), -1)