def test_deserialize_address_key_error(self):
     """ Test address deserialization from incomplete data """
     data = {
         "street": "100 W 100 St.",
         "apartment": "100",
         "state": "New York",
         "zip_code": "100"
     }
     addr = Address()
     with self.assertRaises(DataValidationError) as error:
         addr.deserialize(data)
     self.assertEqual(str(error.exception), 'Invalid address: '\
                      'missing city')
Esempio n. 2
0
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 test_deserialize_an_address(self):
     """ Test deserialization of a customer """
     data = {
         "street": "100 W 100 St.",
         "apartment": "100",
         "city": "New York",
         "state": "New York",
         "zip_code": "100"
     }
     addr = Address()
     addr.deserialize(data)
     self.assertNotEqual(addr, None)
     self.assertEqual(addr.customer_id, None)
     self.assertEqual(addr.street, "100 W 100 St.")
     self.assertEqual(addr.apartment, "100")
     self.assertEqual(addr.city, "New York")
     self.assertEqual(addr.state, "New York")
     self.assertEqual(addr.zip_code, "100")
Esempio n. 4
0
 def post(self):
     """
     Creates a Customer
     This endpoint will create a Customer based the data in the body that is posted
     """
     app.logger.info('Request to create a customer')
     check_content_type('application/json')
     cust = Customer()
     cust.deserialize(api.payload)
     cust.save()
     customer_id = cust.customer_id
     addr = Address()
     addr.deserialize(api.payload['address'])
     addr.customer_id = customer_id
     addr.save()
     cust.address_id = addr.id
     cust.save()
     message = cust.serialize()
     location_url = api.url_for(CustomerResource, user_id=cust.user_id, _external=True)
     return message, status.HTTP_201_CREATED, {'Location': location_url}