From f85f14d2aaa14f821290815dc63540bd31ae28d3 Mon Sep 17 00:00:00 2001 From: ArtemGordinsky Date: Thu, 2 Apr 2020 14:59:19 +0200 Subject: [PATCH] Implement named property fetching --- hubspot3/properties.py | 8 ++++++++ hubspot3/test/test_properties.py | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/hubspot3/properties.py b/hubspot3/properties.py index 8efb721..8e8cafa 100644 --- a/hubspot3/properties.py +++ b/hubspot3/properties.py @@ -150,6 +150,14 @@ def get_all(self, object_type): "", method="GET", params={"properties": ["name", "label", "description"]} ) + def get(self, object_type: str, code: str): + """Retrieve a property.""" + + # Save the current object type. + self._object_type = object_type + + return self._call("named/{}".format(code), method="GET") + def delete(self, object_type, code): """Delete a custom property.""" diff --git a/hubspot3/test/test_properties.py b/hubspot3/test/test_properties.py index a990a35..d36533a 100644 --- a/hubspot3/test/test_properties.py +++ b/hubspot3/test/test_properties.py @@ -37,7 +37,7 @@ def properties_input_data(): ) -class TestContactsClient(object): +class TestPropertiesClient(object): @pytest.mark.parametrize( "object_type, api_version", [ @@ -153,3 +153,25 @@ def test_update( data, ) assert resp == response_body + + def test_get(self, properties_client, mock_connection, properties_input_data): + input_data = properties_input_data + response_body = { + "name": input_data["code"], + "label": input_data["label"], + "description": input_data["description"], + "groupName": "custom", + "type": "string", + "fieldType": "text", + "formField": True, + "displayOrder": 3, + "options": [], + } + mock_connection.set_response(200, json.dumps(response_body)) + resp = properties_client.get(OBJECT_TYPE_DEALS, input_data["code"]) + mock_connection.assert_num_requests(1) + mock_connection.assert_has_request( + "GET", + "/properties/v1/deals/properties/named/{}?".format(input_data["code"]), + ) + assert resp == response_body