def test_query_by_zip(self): """ Query Customers by Zip Code """ customers = self._create_customers(10) test_zip = Address.find(customers[0].address_id)['zip_code'] zip_customers = [ cust for cust in customers if Address.find(cust.address_id)['zip_code'] == test_zip ] resp = self.app.get('/customers', query_string='zip_code={}'.format(test_zip)) self.assertEqual(resp.status_code, status.HTTP_200_OK) data = resp.get_json() self.assertEqual(len(data), len(zip_customers)) # check the data just to be sure for customer in data: self.assertEqual(customer['address']['zip_code'], test_zip)
def delete_addresses(account_id, address_id): """ Delete an Address This endpoint will delete an Address based the id specified in the path """ app.logger.info("Request to delete account with id: %s", account_id) address = Address.find(address_id) if address: address.delete() return make_response("", status.HTTP_204_NO_CONTENT)
def test_update_customer(self): """ Update an existing Customer """ # create a customer to update customers = self._create_customers(5) test_customer = customers[0] test_customer.first_name = 'Cow' cust_json = test_customer.internal_serialize() cust_json["address"] = Address.find(test_customer.address_id) resp = self.app.put('/customers/{}'.format(test_customer.user_id), json=cust_json, content_type='application/json') print(resp.get_json()) self.assertEqual(resp.status_code, status.HTTP_200_OK) updated_customer = resp.get_json() self.assertEqual(updated_customer['first_name'], 'Cow')