From 5297b74262b8de4d9303e0e814380c046aaeff96 Mon Sep 17 00:00:00 2001 From: Ania Misiorek Date: Wed, 30 Aug 2023 17:12:23 -0400 Subject: [PATCH 1/2] implementation + testing --- Makefile | 2 +- linode_api4/objects/linode.py | 1 + test/fixtures/account_transfer.json | 14 ++++ test/fixtures/linode_types.json | 114 +++++++++++++++++++++++++--- test/integration/conftest.py | 2 +- test/unit/linode_client_test.py | 16 ++++ test/unit/objects/linode_test.py | 3 + 7 files changed, 141 insertions(+), 11 deletions(-) create mode 100644 test/fixtures/account_transfer.json diff --git a/Makefile b/Makefile index 7636f2192..4cd378b1c 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ release: build twine upload dist/* @PHONEY: install -install: clean +install: clean requirements python3 -m pip install . @PHONEY: requirements diff --git a/linode_api4/objects/linode.py b/linode_api4/objects/linode.py index 3bc402b0d..d928b31b6 100644 --- a/linode_api4/objects/linode.py +++ b/linode_api4/objects/linode.py @@ -232,6 +232,7 @@ class Type(Base): "label": Property(), "network_out": Property(), "price": Property(), + "region_prices": Property(), "addons": Property(), "memory": Property(), "transfer": Property(), diff --git a/test/fixtures/account_transfer.json b/test/fixtures/account_transfer.json new file mode 100644 index 000000000..ce4658a6a --- /dev/null +++ b/test/fixtures/account_transfer.json @@ -0,0 +1,14 @@ +{ + "quota": 471, + "used": 737373, + "billable": 0, + + "region_transfers": [ + { + "id": "ap-west", + "used": 1, + "quota": 5010, + "billable": 0 + } + ] +} \ No newline at end of file diff --git a/test/fixtures/linode_types.json b/test/fixtures/linode_types.json index b270da778..c864082e8 100644 --- a/test/fixtures/linode_types.json +++ b/test/fixtures/linode_types.json @@ -1,8 +1,8 @@ { -"results": 4, -"pages": 1, -"page": 1, -"data": [ + "results": 4, + "pages": 1, + "page": 1, + "data": [ { "disk": 20480, "memory": 1024, @@ -12,7 +12,19 @@ "price": { "hourly": 0.003, "monthly": 2 - } + }, + "region_prices": [ + { + "id": "ap-west", + "hourly": 0.02, + "monthly": 20 + }, + { + "id": "ap-northeast", + "hourly": 0.02, + "monthly": 20 + } + ] } }, "class": "nanode", @@ -25,6 +37,18 @@ "hourly": 0.0075, "monthly": 5 }, + "region_prices": [ + { + "id": "us-east", + "hourly": 0.02, + "monthly": 20 + }, + { + "id": "ap-northeast", + "hourly": 0.02, + "monthly": 20 + } + ], "successor": null }, { @@ -36,7 +60,19 @@ "price": { "hourly": 0.008, "monthly": 5 - } + }, + "region_prices": [ + { + "id": "ap-west", + "hourly": 0.02, + "monthly": 20 + }, + { + "id": "ap-northeast", + "hourly": 0.02, + "monthly": 20 + } + ] } }, "class": "highmem", @@ -49,6 +85,18 @@ "hourly": 0.09, "monthly": 60 }, + "region_prices": [ + { + "id": "us-east", + "hourly": 0.02, + "monthly": 20 + }, + { + "id": "ap-northeast", + "hourly": 0.02, + "monthly": 20 + } + ], "successor": null }, { @@ -60,7 +108,19 @@ "price": { "hourly": 0.004, "monthly": 2.5 - } + }, + "region_prices": [ + { + "id": "ap-west", + "hourly": 0.02, + "monthly": 20 + }, + { + "id": "ap-northeast", + "hourly": 0.02, + "monthly": 20 + } + ] } }, "class": "standard", @@ -73,6 +133,18 @@ "hourly": 0.015, "monthly": 10 }, + "region_prices": [ + { + "id": "us-east", + "hourly": 0.02, + "monthly": 20 + }, + { + "id": "ap-northeast", + "hourly": 0.02, + "monthly": 20 + } + ], "successor": null }, { @@ -84,7 +156,19 @@ "price": { "hourly": 0.008, "monthly": 5 - } + }, + "region_prices": [ + { + "id": "ap-west", + "hourly": 0.02, + "monthly": 20 + }, + { + "id": "ap-northeast", + "hourly": 0.02, + "monthly": 20 + } + ] } }, "class": "gpu", @@ -97,7 +181,19 @@ "hourly": 0.03, "monthly": 20 }, + "region_prices": [ + { + "id": "us-east", + "hourly": 0.02, + "monthly": 20 + }, + { + "id": "ap-northeast", + "hourly": 0.02, + "monthly": 20 + } + ], "successor": null } ] -} +} \ No newline at end of file diff --git a/test/integration/conftest.py b/test/integration/conftest.py index b3fa15fb2..69248b57a 100644 --- a/test/integration/conftest.py +++ b/test/integration/conftest.py @@ -3,7 +3,7 @@ import pytest -from linode_api4.linode_client import LinodeClient, LongviewSubscription +from linode_api4.linode_client import LinodeClient ENV_TOKEN_NAME = "LINODE_TOKEN" RUN_LONG_TESTS = "RUN_LONG_TESTS" diff --git a/test/unit/linode_client_test.py b/test/unit/linode_client_test.py index 512449aa3..acc689bdb 100644 --- a/test/unit/linode_client_test.py +++ b/test/unit/linode_client_test.py @@ -411,6 +411,22 @@ def test_payments(self): self.assertEqual(payment.date, datetime(2015, 1, 1, 5, 1, 2)) self.assertEqual(payment.usd, 1000) + def test_account_transfer(self): + """ + Tests that payments can be retrieved + """ + transfer = self.client.account.transfer() + + self.assertEqual(transfer.quota, 471) + self.assertEqual(transfer.used, 737373) + self.assertEqual(transfer.billable, 0) + + self.assertEqual(len(transfer.region_transfers), 1) + self.assertEqual(transfer.region_transfers[0].id, "ap-west") + self.assertEqual(transfer.region_transfers[0].used, 1) + self.assertEqual(transfer.region_transfers[0].quota, 5010) + self.assertEqual(transfer.region_transfers[0].billable, 0) + class BetaProgramGroupTest(ClientBaseCase): """ diff --git a/test/unit/objects/linode_test.py b/test/unit/objects/linode_test.py index 1f75f8c1a..2aa280fef 100644 --- a/test/unit/objects/linode_test.py +++ b/test/unit/objects/linode_test.py @@ -533,6 +533,8 @@ def test_get_types(self): self.assertIsNotNone(t.type_class) self.assertIsNotNone(t.gpus) self.assertIsNone(t.successor) + self.assertIsNotNone(t.region_prices) + self.assertIsNotNone(t.addons.backups.region_prices) def test_get_type_by_id(self): """ @@ -546,6 +548,7 @@ def test_get_type_by_id(self): self.assertEqual(t.label, "Linode 1024") self.assertEqual(t.disk, 20480) self.assertEqual(t.type_class, "nanode") + self.assertEqual(t.region_prices[0].id, "us-east") def test_get_type_gpu(self): """ From 98511ad2326185944ca35376a8f048138779ac92 Mon Sep 17 00:00:00 2001 From: Ania Misiorek Date: Wed, 30 Aug 2023 17:16:27 -0400 Subject: [PATCH 2/2] linting --- test/unit/linode_client_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/linode_client_test.py b/test/unit/linode_client_test.py index b47c64ade..24a6d8ac3 100644 --- a/test/unit/linode_client_test.py +++ b/test/unit/linode_client_test.py @@ -470,7 +470,7 @@ def test_account_transfer(self): self.assertEqual(transfer.region_transfers[0].quota, 5010) self.assertEqual(transfer.region_transfers[0].billable, 0) - + class BetaProgramGroupTest(ClientBaseCase): """ Tests methods of the BetaProgramGroup