Skip to content

Commit

Permalink
Fixup ! Fix black
Browse files Browse the repository at this point in the history
  • Loading branch information
jisson committed Oct 14, 2019
1 parent 3e98781 commit 0929914
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 60 deletions.
4 changes: 2 additions & 2 deletions hubspot3/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_product(self, product_id: str, properties: List[str] = None, **options):
method="GET",
params={"properties": ["name", "description", *properties]},
doseq=True,
**options
**options,
)

def get_all_products(
Expand All @@ -49,7 +49,7 @@ def get_all_products(
"properties": ["name", "description", *properties],
},
doseq=True,
**options
**options,
)
output.extend(
[
Expand Down
111 changes: 53 additions & 58 deletions hubspot3/test/test_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
testing hubspot3.products
"""
import json
import warnings
from unittest.mock import Mock, patch
from unittest.mock import Mock

import pytest

Expand All @@ -13,7 +12,7 @@
@pytest.fixture
def products_client(mock_connection):
client = products.ProductsClient(disable_auth=True)
client.options['connection_type'] = Mock(return_value=mock_connection)
client.options["connection_type"] = Mock(return_value=mock_connection)
return client


Expand All @@ -26,8 +25,14 @@ class TestProductsClient(object):

def test_get_path(self):
client = products.ProductsClient(disable_auth=True)
assert client._get_path("objects/products/42") == "crm-objects/v1/objects/products/42"
assert client._get_path("objects/products/paged") == "crm-objects/v1/objects/products/paged"
assert (
client._get_path("objects/products/42")
== "crm-objects/v1/objects/products/42"
)
assert (
client._get_path("objects/products/paged")
== "crm-objects/v1/objects/products/paged"
)

def test_get_product(self, products_client, mock_connection):
"""Test to retrieve a product from Hubspot by using the ProductsClient."""
Expand All @@ -38,9 +43,9 @@ def test_get_product(self, products_client, mock_connection):

mock_connection.assert_num_requests(1)
mock_connection.assert_has_request(
method='GET',
method="GET",
# Notes: name and description properties as the one returned by default.
url='/crm-objects/v1/objects/products/1642767?properties=name&properties=description',
url="/crm-objects/v1/objects/products/1642767?properties=name&properties=description",
data=None,
)
assert response == response_body
Expand All @@ -56,14 +61,13 @@ def test_get_product_with_extra_properties(self, products_client, mock_connectio

mock_connection.set_response(200, json.dumps(response_body))
response = products_client.get_product(
str(HUBSPOT_PRODUCT_ID),
['price', 'duration'],
str(HUBSPOT_PRODUCT_ID), ["price", "duration"]
)

mock_connection.assert_num_requests(1)
mock_connection.assert_has_request(
method='GET',
url='/crm-objects/v1/objects/products/1642767?properties=name&properties=description&properties=price&properties=duration', # noqa: E501
method="GET",
url="/crm-objects/v1/objects/products/1642767?properties=name&properties=description&properties=price&properties=duration", # noqa: E501
data=None,
)
assert response == response_body
Expand Down Expand Up @@ -103,7 +107,7 @@ def test_get_all_products(self, products_client, mock_connection):
"timestamp": 1525287810508,
"source": "API",
"sourceId": None,
},
}
},
"version": 1,
"isDeleted": False,
Expand All @@ -126,20 +130,19 @@ def test_get_all_products(self, products_client, mock_connection):

mock_connection.assert_num_requests(1)
mock_connection.assert_has_request(
method='GET',
url='/crm-objects/v1/objects/products/paged?limit=100&offset=0&properties=name&properties=description',
method="GET",
url="/crm-objects/v1/objects/products/paged?limit=100&offset=0&properties=name&properties=description",
data=None,
)
assert response == [{
'id': 1642736,
'name': 'An updated product',
'description': "This product has a name.",
}, {
'id': 1642767,
'description': "This product don't have a name.",
}, {
'id': 1642796,
}]
assert response == [
{
"id": 1642736,
"name": "An updated product",
"description": "This product has a name.",
},
{"id": 1642767, "description": "This product don't have a name."},
{"id": 1642796},
]

def test_create_product(self, products_client, mock_connection):
"""Test to create a new product on Hubspot."""
Expand All @@ -155,7 +158,7 @@ def test_create_product(self, products_client, mock_connection):
"timestamp": 1525287096980,
"source": "API",
"sourceId": None,
},
}
},
"description": {
"value": product_description,
Expand All @@ -166,25 +169,21 @@ def test_create_product(self, products_client, mock_connection):
}

mock_connection.set_response(200, json.dumps(response_body))
response = products_client.create(data=[{
'name': "name",
'value': product_name,
}, {
'name': "description",
'value': product_description,
}])
response = products_client.create(
data=[
{"name": "name", "value": product_name},
{"name": "description", "value": product_description},
]
)

mock_connection.assert_num_requests(1)
mock_connection.assert_has_request(
method='POST',
url='/crm-objects/v1/objects/products?',
data=[{
'name': "name",
'value': product_name,
}, {
'name': "description",
'value': product_description,
}],
method="POST",
url="/crm-objects/v1/objects/products?",
data=[
{"name": "name", "value": product_name},
{"name": "description", "value": product_description},
],
)
assert response == response_body

Expand All @@ -202,7 +201,7 @@ def test_update_product(self, products_client, mock_connection):
"timestamp": 1525287096980,
"source": "API",
"sourceId": None,
},
}
},
"description": {
"value": product_description,
Expand All @@ -215,25 +214,21 @@ def test_update_product(self, products_client, mock_connection):
mock_connection.set_response(200, json.dumps(response_body))
response = products_client.update(
str(HUBSPOT_PRODUCT_ID),
data=[{
'name': "name",
'value': product_name,
}, {
'name': "description",
'value': product_description,
}]
data=[
{"name": "name", "value": product_name},
{"name": "description", "value": product_description},
],
)

mock_connection.assert_num_requests(1)
mock_connection.assert_has_request(
method='PUT',
url='/crm-objects/v1/objects/products/{product_id}?'.format(product_id=HUBSPOT_PRODUCT_ID),
data=[{
'name': "name",
'value': product_name,
}, {
'name': "description",
'value': product_description,
}],
method="PUT",
url="/crm-objects/v1/objects/products/{product_id}?".format(
product_id=HUBSPOT_PRODUCT_ID
),
data=[
{"name": "name", "value": product_name},
{"name": "description", "value": product_description},
],
)
assert response == response_body

0 comments on commit 0929914

Please sign in to comment.