def get_accounts(account_id): """ Retrieve a single Account This endpoint will return an Account based on it's id """ app.logger.info("Request for Account with id: %s", account_id) account = Account.find_or_404(account_id) return make_response(jsonify(account.serialize()), status.HTTP_200_OK)
def test_find_or_404(self): """ Find or throw 404 error """ 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_or_404(account.id) self.assertEqual(account.id, 1)
def create_addresses(account_id): """ Create an Address on an Account This endpoint will add an address to an account """ app.logger.info("Request to add an address to an account") check_content_type("application/json") account = Account.find_or_404(account_id) address = Address() address.deserialize(request.get_json()) account.addresses.append(address) account.save() message = address.serialize() return make_response(jsonify(message), status.HTTP_201_CREATED)
def list_addresses(account_id): """ Returns all of the Addresses for an Account """ app.logger.info("Request for Account Addresses...") account = Account.find_or_404(account_id) results = [address.serialize() for address in account.addresses] return make_response(jsonify(results), status.HTTP_200_OK)