def authenticate(service_url, email, password): data = {"email": email, "password": password} response = AccountManagementPersistenceService.__post_json( "{}/authenticate".format(service_url), data=data) acc = CloudUser() acc.load_attributes_from_dict(response["result"]) return acc
def test_get_all_accounts(self): response = { "result": [{ "email": "james", "customerid": 11 }, { "email": "john", "customerid": 12 }, { "email": "jim", "customerid": 13 }] } self.httpretty_mock(httpretty.GET, "account", response_body=response) expected_list = [] for account_dict in response["result"]: acc = CloudUser() acc.load_attributes_from_dict(account_dict) expected_list.append(acc) result = AccountManagementPersistenceService.get_all_accounts( self.ams_url) for (expected, actual) in zip(expected_list, result): self.assertEqual(expected.customerid, actual.customerid) self.assertEqual(expected.email, actual.email) self.assertEqual(expected.password, actual.password)
def get_account(service_url, customerid): try: response = AccountManagementPersistenceService.__get_json( "{}/account/{}".format(service_url, customerid)) account = CloudUser() account.load_attributes_from_dict(response["result"]) return account except: return None
def get_all_accounts(service_url): response = AccountManagementPersistenceService.__get_json( "{}/account".format(service_url)) accounts = [] for account_dict in response["result"]: acc = CloudUser() acc.load_attributes_from_dict(account_dict) accounts.append(acc) return accounts
def test_modify_account(self): mocked_response = {"result": "result string"} self.httpretty_mock(httpretty.POST, "account/1", response_body=mocked_response) acc = CloudUser(1, "testemail", "testpassword", True) acc.devices = [CloudDevice("testdevice1")] response = AccountManagementPersistenceService.update_existing_account( self.ams_url, acc) self.assertTrue(response)
def test_add_new_account(self): account_dict = {"result": {"email": "james", "customerid": 11}} account_to_add = CloudUser() account_to_add.load_attributes_from_dict(account_dict["result"]) self.httpretty_mock(httpretty.PUT, "account", response_body=account_dict) response = AccountManagementPersistenceService.add_new_account( self.ams_url, account_to_add) self.assertTrue(response) self.assertEqual(account_to_add.customerid, 11)
def test_getaccountbyemail(self): response = {"result": {"email": "james", "customerid": 11}} self.httpretty_mock(httpretty.GET, "account/email/james", response_body=response) expected = CloudUser() expected.load_attributes_from_dict(response["result"]) actual = AccountManagementPersistenceService.get_account_by_email( self.ams_url, "james") self.assertEqual(expected.customerid, actual.customerid) self.assertEqual(expected.email, actual.email) self.assertEqual(expected.password, actual.password)
def test_authenticate(self): response_data = {"result": {"email": "james", "customerid": 11}} self.httpretty_mock(httpretty.POST, "authenticate", response_body=response_data) expected = CloudUser() expected.load_attributes_from_dict(response_data["result"]) actual = AccountManagementPersistenceService.authenticate( self.ams_url, "james", "testpassword") self.assertEqual(expected.customerid, actual.customerid) self.assertEqual(expected.email, actual.email) self.assertEqual(expected.password, actual.password)
def get_account_by_email(service_url, email): response = AccountManagementPersistenceService.__get_json( "{}/account/email/{}".format(service_url, email)) account = CloudUser() account.load_attributes_from_dict(response["result"]) return account