Skip to content

Commit

Permalink
Merge pull request #643 from recurly/external-product-support
Browse files Browse the repository at this point in the history
Support for external products & references
  • Loading branch information
amandamfielding authored May 24, 2023
2 parents ad6cda7 + 97c5333 commit 0172a02
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 5 deletions.
15 changes: 14 additions & 1 deletion recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2177,13 +2177,26 @@ class ExternalProduct(Resource):
collection_path = 'external_products'

attributes = (
'plan',
'plan_code',
'name',
'created_at',
'updated_at',
'external_product_references'
)

def create_external_product_reference(self, external_product_reference):
"""Creates an external_product_reference on an existing product_reference. If you are
creating an product_reference, you can embed the external_product_references with the
request"""
url = urljoin(self._url, '/external_product_references')
return external_product_reference.post(url)

def get_external_product_reference(self, external_product_reference_uuid):
"""Fetch an external product reference from an external account."""
url = urljoin(self._url, '/external_product_references/{}'.format(external_product_reference_uuid))
resp, elem = ExternalProductReference().element_for_url(url)
return ExternalProductReference().from_element(elem)

class ExportDate(Resource):
nodename = 'export_date'
collection_path = 'export_dates'
Expand Down
25 changes: 25 additions & 0 deletions tests/fixtures/external-product-references/create.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
POST https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references HTTP/1.1
X-Api-Version: {api-version}
Accept: application/xml
Authorization: Basic YXBpa2V5Og==
User-Agent: {user-agent}
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<external_product_reference>
<external_connection_type>google_play_store</external_connection_type>
<reference_code>948eb638-bef5-4e48-a955-2646d7e353e5</reference_code>
</external_product_reference>

HTTP/1.1 201 Created
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references/swafyj8wqw6n

<?xml version="1.0" encoding="UTF-8"?>
<external_product_reference href="https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references/swafyj8wqw6n">
<id>swafyj8wqw6n</id>
<reference_code>948eb638-bef5-4e48-a955-2646d7e353e5</reference_code>
<external_connection_type>google_play_store</external_connection_type>
<created_at type="datetime">2023-05-15T18:46:48Z</created_at>
<updated_at type="datetime">2023-05-15T18:46:48Z</updated_at>
</external_product_reference>
8 changes: 8 additions & 0 deletions tests/fixtures/external-product-references/deleted.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DELETE https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references/ru1u1gn5otsv HTTP/1.1
X-Api-Version: {api-version}
Accept: application/xml
Authorization: Basic YXBpa2V5Og==
User-Agent: {user-agent}


HTTP/1.1 204 No Content
18 changes: 18 additions & 0 deletions tests/fixtures/external-product-references/get.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GET https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references/ru1u1gn5otsv HTTP/1.1
X-Api-Version: {api-version}
Accept: application/xml
Authorization: Basic YXBpa2V5Og==
User-Agent: {user-agent}


HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<external_product_reference href="https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references/ru1u1gn5otsv">
<id>ru1u1gn5otsv</id>
<reference_code>code_test_google</reference_code>
<external_connection_type>google_play_store</external_connection_type>
<created_at type="datetime">2022-11-03T21:12:35Z</created_at>
<updated_at type="datetime">2022-11-03T21:12:35Z</updated_at>
</external_product_reference>
8 changes: 8 additions & 0 deletions tests/fixtures/external-product/deleted.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DELETE https://api.recurly.com/v2/external_products/ru1u1gms4msk HTTP/1.1
X-Api-Version: {api-version}
Accept: application/xml
Authorization: Basic YXBpa2V5Og==
User-Agent: {user-agent}


HTTP/1.1 204 No Content
8 changes: 4 additions & 4 deletions tests/fixtures/external-product/get.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<external_product href="https://paulo.recurly.dev:3000/v2/external_products/ru1u1gms4msk">
<plan href="https://paulo.recurly.dev:3000/v2/plans/5_abril">
<external_product href="https://api.recurly.com/v2/external_products/ru1u1gms4msk">
<plan href="https://api.recurly.com/v2/plans/5_abril">
<plan_code>5_abril</plan_code>
<name>5 de abril</name>
</plan>
<name>product_name_teste</name>
<created_at type="datetime">2022-11-03T21:12:35Z</created_at>
<updated_at type="datetime">2022-11-03T21:12:35Z</updated_at>
<external_product_references type="array">
<external_product_reference>
<external_product_reference href="https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references/ru1u1gn5otsv">
<id>ru1u1gn5otsv</id>
<reference_code>code_teste_google</reference_code>
<external_connection_type>google_play_store</external_connection_type>
<created_at type="datetime">2022-11-03T21:12:35Z</created_at>
<updated_at type="datetime">2022-11-03T21:12:35Z</updated_at>
</external_product_reference>
<external_product_reference>
<external_product_reference href="https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references/ru1u1gn7ebod">
<id>ru1u1gn7ebod</id>
<reference_code>code_teste_apple</reference_code>
<external_connection_type>apple_app_store</external_connection_type>
Expand Down
43 changes: 43 additions & 0 deletions tests/fixtures/external-product/updated.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
PUT https://api.recurly.com/v2/external_products/ru1u1gms4msk HTTP/1.1
X-Api-Version: {api-version}
Accept: application/xml
Authorization: Basic YXBpa2V5Og==
User-Agent: {user-agent}
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<external_product>
<plan_code>test-plan</plan_code>
</external_product>

HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/external_products/ru1u1gms4msk

<?xml version="1.0" encoding="UTF-8"?>
<external_product href="https://api.recurly.com/v2/external_products/ru1u1gms4msk">
<id>sol7gvrm8vkh</id>
<plan href="https://api.recurly.com/v2/plans/5_abril">
<plan_code>5_abril</plan_code>
<name>5 de abril</name>
</plan>
<name>product_name_teste</name>
<created_at type="datetime">2022-11-03T21:12:35Z</created_at>
<updated_at type="datetime">2022-11-03T21:12:35Z</updated_at>
<external_product_references type="array">
<external_product_reference href="https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references/ru1u1gn5otsv">
<id>ru1u1gn5otsv</id>
<reference_code>code_teste_google</reference_code>
<external_connection_type>google_play_store</external_connection_type>
<created_at type="datetime">2022-11-03T21:12:35Z</created_at>
<updated_at type="datetime">2022-11-03T21:12:35Z</updated_at>
</external_product_reference>
<external_product_reference href="https://api.recurly.com/v2/external_products/ru1u1gms4msk/external_product_references/ru1u1gn7ebod">
<id>ru1u1gn7ebod</id>
<reference_code>code_teste_apple</reference_code>
<external_connection_type>apple_app_store</external_connection_type>
<created_at type="datetime">2022-11-03T21:12:35Z</created_at>
<updated_at type="datetime">2022-11-03T21:12:35Z</updated_at>
</external_product_reference>
</external_product_references>
</external_product>
45 changes: 45 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3165,6 +3165,51 @@ def test_get_external_product(self):
self.assertEqual(second_external_product_reference.created_at, datetime(2022, 11, 3, 21, 12, 35, tzinfo=second_external_product_reference.created_at.tzinfo))
self.assertEqual(second_external_product_reference.updated_at, datetime(2022, 11, 3, 21, 12, 35, tzinfo=second_external_product_reference.updated_at.tzinfo))

def test_update_external_product(self):
with self.mock_request('external-product/get.xml'):
external_product = ExternalProduct.get('ru1u1gms4msk')

external_product.plan_code = "test-plan"
with self.mock_request('external-product/updated.xml'):
external_product.save()

def test_delete_external_product(self):
with self.mock_request('external-product/get.xml'):
external_product = ExternalProduct.get('ru1u1gms4msk')

with self.mock_request('external-product/deleted.xml'):
external_product.delete()

def test_create_external_product_reference(self):
with self.mock_request('external-product/get.xml'):
external_product = ExternalProduct.get('ru1u1gms4msk')

external_product_reference = recurly.ExternalProductReference(
reference_code = '948eb638-bef5-4e48-a955-2646d7e353e5',
external_connection_type = 'google_play_store'
)
with self.mock_request('external-product-references/create.xml'):
external_product.create_external_product_reference(external_product_reference)

def test_get_external_product_reference(self):
with self.mock_request('external-product/get.xml'):
external_product = ExternalProduct.get('ru1u1gms4msk')
with self.mock_request('external-product-references/get.xml'):
external_product_reference = external_product.get_external_product_reference('ru1u1gn5otsv')

self.assertEqual(external_product_reference.reference_code, "code_test_google")
self.assertEqual(external_product_reference.external_connection_type, "google_play_store")

def test_delete_external_product_reference(self):
with self.mock_request('external-product/get.xml'):
external_product = ExternalProduct.get('ru1u1gms4msk')

with self.mock_request('external-product-references/get.xml'):
external_product_reference = external_product.get_external_product_reference('ru1u1gn5otsv')

with self.mock_request('external-product-references/deleted.xml'):
external_product_reference.delete()

def test_list_external_accounts(self):
account_code = 'testmock'
with self.mock_request('account/exists.xml'):
Expand Down

0 comments on commit 0172a02

Please sign in to comment.