def test_update_account_address(self): """ Update an accounts address """ accounts = Account.all() self.assertEqual(accounts, []) address = self._create_address() account = self._create_account(addresses=[address]) account.create() # Assert that it was assigned an id and shows up in the database self.assertEqual(account.id, 1) accounts = Account.all() self.assertEqual(len(accounts), 1) # Fetch it back account = Account.find(account.id) old_address = account.addresses[0] self.assertEqual(old_address.city, address.city) old_address.city = "XX" account.save() # Fetch it back again account = Account.find(account.id) address = account.addresses[0] self.assertEqual(address.city, "XX")
def test_update_account(self): """ Update an account """ account = self._create_account() account.create() # Assert that it was assigned an id and shows up in the database self.assertEqual(account.id, 1) # Fetch it back account = Account.find(account.id) account.email = "*****@*****.**" account.save() # Fetch it back again account = Account.find(account.id) self.assertEqual(account.email, "*****@*****.**")
def delete_accounts(account_id): """ Delete an Account This endpoint will delete an Account based the id specified in the path """ app.logger.info("Request to delete account with id: %s", account_id) account = Account.find(account_id) if account: account.delete() return make_response("", status.HTTP_204_NO_CONTENT)
def test_add_account_address(self): """ Create an account with an address and add it to the database """ accounts = Account.all() self.assertEqual(accounts, []) account = self._create_account() address = self._create_address() account.addresses.append(address) account.create() # Assert that it was assigned an id and shows up in the database self.assertEqual(account.id, 1) accounts = Account.all() self.assertEqual(len(accounts), 1) new_account = Account.find(account.id) self.assertEqual(account.addresses[0].name, address.name) address2 = self._create_address() account.addresses.append(address2) account.save() new_account = Account.find(account.id) self.assertEqual(len(account.addresses), 2) self.assertEqual(account.addresses[1].name, address2.name)
def update_accounts(account_id): """ Update an Account This endpoint will update an Account based the body that is posted """ app.logger.info("Request to update account with id: %s", account_id) check_content_type("application/json") account = Account.find(account_id) if not account: raise NotFound( "Account with id '{}' was not found.".format(account_id)) account.deserialize(request.get_json()) account.id = account_id account.save() return make_response(jsonify(account.serialize()), status.HTTP_200_OK)