Ejemplo n.º 1
0
    def test_delete_address(self):
        """ Delete an Address """
        account = self._create_accounts(1)[0]
        address = AddressFactory()
        resp = self.app.post(
            "/accounts/{}/addresses".format(account.id), 
            json=address.serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
        data = resp.get_json()
        logging.debug(data)
        address_id = data["id"]

        # send delete request
        resp = self.app.delete(
            "/accounts/{}/addresses/{}".format(account.id, address_id),
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)

        # retrieve it back and make sure address is not there
        resp = self.app.get(
            "/accounts/{}/addresses/{}".format(account.id, address_id), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_404_NOT_FOUND)
Ejemplo n.º 2
0
    def test_get_address(self):
        """ Get an address from an account """
        # create a known address
        account = self._create_accounts(1)[0]
        address = AddressFactory()
        resp = self.app.post(
            "/accounts/{}/addresses".format(account.id), 
            json=address.serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        data = resp.get_json()
        logging.debug(data)
        address_id = data["id"]

        # retrieve it back
        resp = self.app.get(
            "/accounts/{}/addresses/{}".format(account.id, address_id), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        data = resp.get_json()
        logging.debug(data)
        self.assertEqual(data["account_id"], account.id)
        self.assertEqual(data["name"], address.name)
        self.assertEqual(data["street"], address.street)
        self.assertEqual(data["city"], address.city)
        self.assertEqual(data["state"], address.state)
        self.assertEqual(data["postalcode"], address.postalcode)
Ejemplo n.º 3
0
 def test_add_address(self):
     """ Add an address to an account """
     account = self._create_accounts(1)[0]
     address = AddressFactory()
     resp = self.app.post(
         "/accounts/{}/addresses".format(account.id), 
         json=address.serialize(), 
         content_type="application/json"
     )
     self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
     data = resp.get_json()
     logging.debug(data)
     self.assertEqual(data["account_id"], account.id)
     self.assertEqual(data["name"], address.name)
     self.assertEqual(data["street"], address.street)
     self.assertEqual(data["city"], address.city)
     self.assertEqual(data["state"], address.state)
     self.assertEqual(data["postalcode"], address.postalcode)
Ejemplo n.º 4
0
    def test_update_address(self):
        """ Update an address on an account """
        # create a known address
        account = self._create_accounts(1)[0]
        address = AddressFactory()
        resp = self.app.post(
            "/accounts/{}/addresses".format(account.id), 
            json=address.serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        data = resp.get_json()
        logging.debug(data)
        address_id = data["id"]
        data["name"] = "XXXX"

        # send the update back
        resp = self.app.put(
            "/accounts/{}/addresses/{}".format(account.id, address_id), 
            json=data, 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        # retrieve it back
        resp = self.app.get(
            "/accounts/{}/addresses/{}".format(account.id, address_id), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        data = resp.get_json()
        logging.debug(data)
        self.assertEqual(data["id"], address_id)
        self.assertEqual(data["account_id"], account.id)
        self.assertEqual(data["name"], "XXXX")