def test_user_login_success(self): """With correct values, is a valid user logged in?""" # Log in user demo_json = loads(self.demo) test_utils.mock_with_file( httpretty.POST, "http://0.0.0.0:3000/api/v1/Demos/DemoGUID/loginAs", "server/tests/mocks/POST_api_v1_Demos_DemoGUID_loginAs_200.json", 200) auth_data = user_service.login(demo_json.get('guid'), demo_json.get('users')[0].get('id')) # TODO: Update to use assertIsInstance(a,b) # Check all expected object values are present self.assertTrue(auth_data.get('loopback_token')) self.assertTrue(auth_data.get('user')) user_json = auth_data.get('user') self.assertTrue(user_json.get('id')) self.assertTrue(user_json.get('demoId')) self.assertTrue(user_json.get('username')) self.assertTrue(user_json.get('email')) if user_json.get('roles'): for role_json in user_json.get('roles'): self.assertTrue(role_json.get('id')) self.assertTrue(role_json.get('name')) self.assertTrue(role_json.get('created')) self.assertTrue(role_json.get('modified'))
def setUp(self): # Create demo test_utils.mock_with_file( httpretty.POST, "http://0.0.0.0:3000/api/v1/Demos", "server/tests/mocks/POST_api_v1_Demos_200.json", 200) self.demo = test_utils.create_demo() demo_json = loads(self.demo) demo_guid = demo_json.get('guid') demo_user_id = demo_json.get('users')[0].get('id') # Log in user auth_data = user_service.login(demo_guid, demo_user_id) self.loopback_token = auth_data.get('loopback_token')
def setUp(self): # Create demo test_utils.mock_with_file( httpretty.POST, "http://0.0.0.0:3000/api/v1/Demos", "server/tests/mocks/POST_api_v1_Demos_200.json", 200) test_utils.mock_with_file( httpretty.GET, "http://0.0.0.0:3000/api/v1/Demos/DemoGUID/retailers", "server/tests/mocks/GET_api_v1_Demos_DemoGUID_retailers_200.json", 200) self.demo = test_utils.create_demo() self.retailers = demo_service.get_demo_retailers( loads(self.demo).get('guid'))
def test_user_login_invalid_inputs(self): """With invalid inputs, are correct errors thrown?""" demo_json = loads(self.demo) test_utils.mock_with_file( httpretty.POST, "http://0.0.0.0:3000/api/v1/Demos/123321/loginAs", "server/tests/mocks/POST_api_v1_Demos_123321_loginAs_404.json", 404) self.assertRaises(ResourceDoesNotExistException, user_service.login, '123321', demo_json.get('users')[0].get('id')) test_utils.mock_with_file( httpretty.POST, "http://0.0.0.0:3000/api/v1/Demos/DemoGUID/loginAs", "server/tests/mocks/POST_api_v1_Demos_DemoGUID_loginAs_404.json", 404) self.assertRaises(ResourceDoesNotExistException, user_service.login, demo_json.get('guid'), '123321')
def test_user_create_success(self): """With correct values, is a valid user returned?""" # Create new user assigned to the first retailer test_utils.mock_with_file( httpretty.POST, "http://0.0.0.0:3000/api/v1/Demos/DemoGUID/createUser", "server/tests/mocks/POST_api_v1_Demos_DemoGUID_createUser_200.json", 200) user = user_service.create_user( loads(self.demo).get('guid'), loads(self.retailers)[0].get('id')) # TODO: Update to use assertIsInstance(a,b) # Check all expected object values are present user_json = loads(user) self.assertTrue(user_json.get('id')) self.assertTrue(user_json.get('demoId')) self.assertTrue(user_json.get('email')) self.assertTrue(user_json.get('username'))
def test_user_create_invalid_inputs(self): """With invalid inputs, are correct errors thrown?""" # Attempt to create user with invalid inputs # Invalid demo guid test_utils.mock_with_file( httpretty.POST, "http://0.0.0.0:3000/api/v1/Demos/123321/createUser", "server/tests/mocks/POST_api_v1_Demos_123321_createUser_404.json", 404) self.assertRaises(ResourceDoesNotExistException, user_service.create_user, '123321', loads(self.retailers)[0].get('id')) # Invalid retailer id test_utils.mock_with_file( httpretty.POST, "http://0.0.0.0:3000/api/v1/Demos/DemoGUID/createUser", "server/tests/mocks/POST_api_v1_Demos_DemoGUID_createUser_404.json", 404) self.assertRaises(ResourceDoesNotExistException, user_service.create_user, loads(self.demo).get('guid'), '123321')
def setUp(self): # Create demo test_utils.mock_with_file( httpretty.POST, "http://0.0.0.0:3000/api/v1/Demos", "server/tests/mocks/POST_api_v1_Demos_200.json", 200) self.demo = test_utils.create_demo()
def tearDown(self): test_utils.mock_with_file( httpretty.DELETE, "http://0.0.0.0:3000/api/v1/Demos/DemoGUID", "server/tests/mocks/DELETE_api_v1_Demos_DemoGUID_204.json", 204) test_utils.delete_demo(loads(self.demo).get('guid'))