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_add_a_account(self): """ Create an account and add it to the database """ accounts = Account.all() self.assertEqual(accounts, []) account = self._create_account() 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)
def test_delete_an_account(self): """ Delete an account from the database """ accounts = Account.all() self.assertEqual(accounts, []) account = self._create_account() 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) account = accounts[0] account.delete() accounts = Account.all() self.assertEqual(len(accounts), 0)
def list_accounts(): """ Returns all of the Accounts """ app.logger.info("Request for Account list") accounts = [] name = request.args.get("name") if name: accounts = Account.find_by_name(name) else: accounts = Account.all() results = [account.serialize() for account in accounts] return make_response(jsonify(results), status.HTTP_200_OK)
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)