Skip to content

Commit

Permalink
shopinvader_api_address: support partial update
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbeau committed Oct 15, 2023
1 parent c900e70 commit b228598
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
14 changes: 1 addition & 13 deletions shopinvader_api_address/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,7 @@ class AddressUpdate(StrictExtendableBaseModel):
country_id: int | None = None

def to_res_partner_vals(self) -> dict:
vals = {
"name": self.name,
"street": self.street,
"street2": self.street2,
"zip": self.zip,
"city": self.city,
"phone": self.phone,
"email": self.email,
"state_id": self.state_id,
"country_id": self.country_id,
}

return vals
return self.model_dump(exclude_unset=True)


class AddressSearch(StrictExtendableBaseModel):
Expand Down
33 changes: 33 additions & 0 deletions shopinvader_api_address/tests/test_shopinvader_address_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,36 @@ def test_update_shipping_address(self):
)
self.assertEqual(new_address.name, data.get("name"))
self.assertEqual(new_address.street, data.get("street"))

def test_update_partial_shipping_address(self):
"""
Test to update shipping address
"""
new_address = self.env["res.partner"].create(
{
"name": "test New Addr",
"street": "test Street",
"zip": "5000",
"city": "Namur",
"country_id": self.env.ref("base.be").id,
"parent_id": self.test_partner.id,
"type": "delivery",
}
)

data = {
"name": "test Addr2 Changed",
}

with self._create_test_client(router=address_router) as test_client:
response: Response = test_client.post(
f"/addresses/shipping/{new_address.id}", content=json.dumps(data)
)

self.assertEqual(
response.status_code,
status.HTTP_200_OK,
msg=f"error message: {response.text}",
)
self.assertEqual(new_address.name, "test Addr2 Changed")
self.assertEqual(new_address.street, "test Street")

0 comments on commit b228598

Please sign in to comment.