From 2291453071fd4990688889f058a508b99cba4645 Mon Sep 17 00:00:00 2001 From: sheilfer zepeda Date: Wed, 9 Nov 2022 10:08:17 -0800 Subject: [PATCH 1/3] refactor: folder restructure CF-552 --- synapsepy/__init__.py | 11 +++++------ synapsepy/{ => constants}/endpoints.py | 0 synapsepy/{ => helpers}/errors.py | 0 synapsepy/{ => helpers}/http_client.py | 2 +- synapsepy/{ => helpers}/node.py | 0 synapsepy/{ => helpers}/subnet.py | 0 synapsepy/{ => helpers}/subscription.py | 0 synapsepy/{ => helpers}/transaction.py | 0 synapsepy/{ => lib}/client.py | 14 +++++++------- synapsepy/{ => lib}/user.py | 10 +++++----- synapsepy/tests/client_tests.py | 15 +++++++-------- 11 files changed, 25 insertions(+), 27 deletions(-) rename synapsepy/{ => constants}/endpoints.py (100%) rename synapsepy/{ => helpers}/errors.py (100%) rename synapsepy/{ => helpers}/http_client.py (99%) rename synapsepy/{ => helpers}/node.py (100%) rename synapsepy/{ => helpers}/subnet.py (100%) rename synapsepy/{ => helpers}/subscription.py (100%) rename synapsepy/{ => helpers}/transaction.py (100%) rename synapsepy/{ => lib}/client.py (96%) rename synapsepy/{ => lib}/user.py (99%) diff --git a/synapsepy/__init__.py b/synapsepy/__init__.py index c613dcc..6da017e 100644 --- a/synapsepy/__init__.py +++ b/synapsepy/__init__.py @@ -1,6 +1,5 @@ -from .client import Client -from .user import User, Users -from .node import Node, Nodes -from .subnet import Subnet, Subnets -from .subscription import Subscription, Subscriptions -from .transaction import Trans, Transactions \ No newline at end of file +from lib.client import Client +from lib.user import User, Users + + +print("Success") \ No newline at end of file diff --git a/synapsepy/endpoints.py b/synapsepy/constants/endpoints.py similarity index 100% rename from synapsepy/endpoints.py rename to synapsepy/constants/endpoints.py diff --git a/synapsepy/errors.py b/synapsepy/helpers/errors.py similarity index 100% rename from synapsepy/errors.py rename to synapsepy/helpers/errors.py diff --git a/synapsepy/http_client.py b/synapsepy/helpers/http_client.py similarity index 99% rename from synapsepy/http_client.py rename to synapsepy/helpers/http_client.py index 2e3ae5d..9cc313c 100644 --- a/synapsepy/http_client.py +++ b/synapsepy/helpers/http_client.py @@ -2,7 +2,7 @@ import logging import requests import http.client as http_client -from . import errors as api_errors +import helpers.errors as api_errors class HttpClient(): """Handles HTTP requests (including headers) and API errors. diff --git a/synapsepy/node.py b/synapsepy/helpers/node.py similarity index 100% rename from synapsepy/node.py rename to synapsepy/helpers/node.py diff --git a/synapsepy/subnet.py b/synapsepy/helpers/subnet.py similarity index 100% rename from synapsepy/subnet.py rename to synapsepy/helpers/subnet.py diff --git a/synapsepy/subscription.py b/synapsepy/helpers/subscription.py similarity index 100% rename from synapsepy/subscription.py rename to synapsepy/helpers/subscription.py diff --git a/synapsepy/transaction.py b/synapsepy/helpers/transaction.py similarity index 100% rename from synapsepy/transaction.py rename to synapsepy/helpers/transaction.py diff --git a/synapsepy/client.py b/synapsepy/lib/client.py similarity index 96% rename from synapsepy/client.py rename to synapsepy/lib/client.py index bac1d34..686e359 100644 --- a/synapsepy/client.py +++ b/synapsepy/lib/client.py @@ -1,13 +1,13 @@ -from .http_client import HttpClient +from helpers.http_client import HttpClient -from .user import User, Users -from .node import Node, Nodes -from .transaction import Trans, Transactions -from .subscription import Subscription, Subscriptions -from . import errors as api_errors +from lib.user import User, Users +from helpers.node import Node, Nodes +from helpers.transaction import Trans, Transactions +from helpers.subscription import Subscription, Subscriptions +import helpers.errors as api_errors -from .endpoints import paths +from constants.endpoints import paths import sys import json diff --git a/synapsepy/user.py b/synapsepy/lib/user.py similarity index 99% rename from synapsepy/user.py rename to synapsepy/lib/user.py index 807b88c..ecc434b 100644 --- a/synapsepy/user.py +++ b/synapsepy/lib/user.py @@ -1,9 +1,9 @@ -from .endpoints import paths +from constants.endpoints import paths -from .node import Node, Nodes -from .subnet import Subnet, Subnets -from .transaction import Trans, Transactions +from helpers.node import Node, Nodes +from helpers.subnet import Subnet, Subnets +from helpers.transaction import Trans, Transactions from functools import partial @@ -11,7 +11,7 @@ import logging import requests import warnings -from . import errors as api_errors +import helpers.errors as api_errors class User(): """ User Record diff --git a/synapsepy/tests/client_tests.py b/synapsepy/tests/client_tests.py index c574af0..8f54ed7 100644 --- a/synapsepy/tests/client_tests.py +++ b/synapsepy/tests/client_tests.py @@ -1,16 +1,15 @@ import unittest from unittest import TestCase, mock -from .. import errors as api_errors -from .fixtures.user_fixtures import simple_response, users_resp -from .fixtures.subscription_fixtures import subs_resp, subss_resp -from .fixtures.node_fixtures import get_nodes_response +from fixtures.user_fixtures import simple_response, users_resp +from fixtures.subscription_fixtures import subs_resp, subss_resp +from fixtures.node_fixtures import get_nodes_response -from ..client import Client -from ..user import User, Users -from ..node import Node, Nodes -from ..subscription import Subscription, Subscriptions +# from ..lib.client import Client +# from ..lib.user import User, Users +from helpers.node import Node, Nodes +from helpers.subscription import Subscription, Subscriptions class ClientTests(TestCase): ''' From 899ed61f7c649b9c01a86e569c0c399c1f1aa77a Mon Sep 17 00:00:00 2001 From: sheilfer zepeda Date: Wed, 9 Nov 2022 10:25:14 -0800 Subject: [PATCH 2/3] refactor: folder restructure CF-552 --- synapsepy/__init__.py | 5 +---- synapsepy/tests/client_tests.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/synapsepy/__init__.py b/synapsepy/__init__.py index 6da017e..393ccac 100644 --- a/synapsepy/__init__.py +++ b/synapsepy/__init__.py @@ -1,5 +1,2 @@ from lib.client import Client -from lib.user import User, Users - - -print("Success") \ No newline at end of file +from lib.user import User, Users \ No newline at end of file diff --git a/synapsepy/tests/client_tests.py b/synapsepy/tests/client_tests.py index 8f54ed7..5cf1811 100644 --- a/synapsepy/tests/client_tests.py +++ b/synapsepy/tests/client_tests.py @@ -1,15 +1,16 @@ import unittest from unittest import TestCase, mock +from ..helpers.errors import errors as api_errors -from fixtures.user_fixtures import simple_response, users_resp -from fixtures.subscription_fixtures import subs_resp, subss_resp -from fixtures.node_fixtures import get_nodes_response +from .fixtures.user_fixtures import simple_response, users_resp +from .fixtures.subscription_fixtures import subs_resp, subss_resp +from .fixtures.node_fixtures import get_nodes_response -# from ..lib.client import Client -# from ..lib.user import User, Users -from helpers.node import Node, Nodes -from helpers.subscription import Subscription, Subscriptions +from ..lib.client import Client +from ..lib.user import User, Users +from ..helpers.node import Node, Nodes +from ..helpers.subscription import Subscription, Subscriptions class ClientTests(TestCase): ''' From 547f11e9d52df8a7cf459a2c1b56673484274581 Mon Sep 17 00:00:00 2001 From: sheilfer zepeda Date: Wed, 9 Nov 2022 11:29:22 -0800 Subject: [PATCH 3/3] tests: fix test results CF-552 --- synapsepy/__init__.py | 4 ++-- synapsepy/helpers/http_client.py | 2 +- synapsepy/lib/client.py | 14 +++++++------- synapsepy/lib/user.py | 10 +++++----- synapsepy/tests/client_tests.py | 30 +++++++++++++++--------------- synapsepy/tests/error_tests.py | 4 ++-- synapsepy/tests/user_tests.py | 18 +++++++++--------- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/synapsepy/__init__.py b/synapsepy/__init__.py index 393ccac..7bcef9c 100644 --- a/synapsepy/__init__.py +++ b/synapsepy/__init__.py @@ -1,2 +1,2 @@ -from lib.client import Client -from lib.user import User, Users \ No newline at end of file +from .lib.client import Client +from .lib.user import User, Users \ No newline at end of file diff --git a/synapsepy/helpers/http_client.py b/synapsepy/helpers/http_client.py index 9cc313c..2e3ae5d 100644 --- a/synapsepy/helpers/http_client.py +++ b/synapsepy/helpers/http_client.py @@ -2,7 +2,7 @@ import logging import requests import http.client as http_client -import helpers.errors as api_errors +from . import errors as api_errors class HttpClient(): """Handles HTTP requests (including headers) and API errors. diff --git a/synapsepy/lib/client.py b/synapsepy/lib/client.py index 686e359..da21818 100644 --- a/synapsepy/lib/client.py +++ b/synapsepy/lib/client.py @@ -1,13 +1,13 @@ -from helpers.http_client import HttpClient +from ..helpers.http_client import HttpClient -from lib.user import User, Users -from helpers.node import Node, Nodes -from helpers.transaction import Trans, Transactions -from helpers.subscription import Subscription, Subscriptions -import helpers.errors as api_errors +from .user import User, Users +from ..helpers.node import Node, Nodes +from ..helpers.transaction import Trans, Transactions +from ..helpers.subscription import Subscription, Subscriptions +from ..helpers import errors as api_errors -from constants.endpoints import paths +from ..constants.endpoints import paths import sys import json diff --git a/synapsepy/lib/user.py b/synapsepy/lib/user.py index ecc434b..d271570 100644 --- a/synapsepy/lib/user.py +++ b/synapsepy/lib/user.py @@ -1,9 +1,9 @@ -from constants.endpoints import paths +from ..constants.endpoints import paths -from helpers.node import Node, Nodes -from helpers.subnet import Subnet, Subnets -from helpers.transaction import Trans, Transactions +from ..helpers.node import Node, Nodes +from ..helpers.subnet import Subnet, Subnets +from ..helpers.transaction import Trans, Transactions from functools import partial @@ -11,7 +11,7 @@ import logging import requests import warnings -import helpers.errors as api_errors +from ..helpers import errors as api_errors class User(): """ User Record diff --git a/synapsepy/tests/client_tests.py b/synapsepy/tests/client_tests.py index 5cf1811..d0b4d2f 100644 --- a/synapsepy/tests/client_tests.py +++ b/synapsepy/tests/client_tests.py @@ -1,7 +1,7 @@ import unittest from unittest import TestCase, mock -from ..helpers.errors import errors as api_errors +from ..helpers import errors as api_errors from .fixtures.user_fixtures import simple_response, users_resp from .fixtures.subscription_fixtures import subs_resp, subss_resp @@ -32,7 +32,7 @@ def test_client_init(self): self.assertIsInstance(self.client, Client) @mock.patch( - 'synapsepy.http_client.HttpClient.post', + 'synapsepy.helpers.http_client.HttpClient.post', return_value = simple_response, autospec = True ) @@ -42,7 +42,7 @@ def test_create_user(self, mock_request): self.assertIsInstance(simple, User) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = simple_response, autospec = True ) @@ -52,7 +52,7 @@ def test_get_user(self, mock_request): self.assertIsInstance(simple, User) @mock.patch( - 'synapsepy.http_client.HttpClient.post', + 'synapsepy.helpers.http_client.HttpClient.post', return_value = subs_resp, autospec = True ) @@ -62,7 +62,7 @@ def test_create_subs(self, mock_request): self.assertIsInstance(sub, Subscription) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = subs_resp, autospec = True ) @@ -71,7 +71,7 @@ def test_get_subs(self, mock_request): self.assertIsInstance(subs, Subscription) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = {}, autospec = True ) @@ -80,7 +80,7 @@ def test_webhook_logs(self, mock_request): self.assertIsInstance(logs, dict) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = {}, autospec = True ) @@ -89,7 +89,7 @@ def test_crypto_quotes(self, mock_request): self.assertIsInstance(response, dict) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = {}, autospec = True ) @@ -98,7 +98,7 @@ def test_crypto_market_data(self, mock_request): self.assertIsInstance(response, dict) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = {}, autospec = True ) @@ -107,7 +107,7 @@ def test_trade_market_data(self, mock_request): self.assertIsInstance(response, dict) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = {}, autospec = True ) @@ -116,7 +116,7 @@ def test_locate_atms(self, mock_request): self.assertIsInstance(response, dict) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = {'public_key_obj':{}}, autospec = True ) @@ -126,7 +126,7 @@ def test_issue_pub_key(self, mock_request): self.assertIsInstance(key, dict) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = users_resp, autospec = True ) @@ -136,7 +136,7 @@ def test_get_users(self, mock_request): self.assertIsInstance(users, Users) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = subss_resp, autospec = True ) @@ -146,7 +146,7 @@ def test_get_subss(self, mock_request): self.assertIsInstance(subss, Subscriptions) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = get_nodes_response, autospec = True ) @@ -156,7 +156,7 @@ def test_get_nodes(self, mock_request): self.assertIsInstance(nodes, Nodes) @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value = {}, autospec = True ) diff --git a/synapsepy/tests/error_tests.py b/synapsepy/tests/error_tests.py index c764a03..4784cb0 100644 --- a/synapsepy/tests/error_tests.py +++ b/synapsepy/tests/error_tests.py @@ -1,8 +1,8 @@ import unittest -from ..client import Client -from .. import errors as api_errors +from ..lib.client import Client +from ..helpers import errors as api_errors from .fixtures.error_fixtures import * class ErrorTests(unittest.TestCase): diff --git a/synapsepy/tests/user_tests.py b/synapsepy/tests/user_tests.py index 40209bc..0a2ef14 100644 --- a/synapsepy/tests/user_tests.py +++ b/synapsepy/tests/user_tests.py @@ -7,16 +7,16 @@ from .fixtures.trans_fixtures import * from .fixtures.subnet_fixtures import * -from ..client import Client -from ..user import User -from ..node import Node, Nodes -from ..transaction import Trans, Transactions -from ..subnet import Subnet, Subnets +from ..lib.client import Client +from ..lib.user import User +from ..helpers.node import Node, Nodes +from ..helpers.transaction import Trans, Transactions +from ..helpers.subnet import Subnet, Subnets -from ..http_client import HttpClient +from ..helpers.http_client import HttpClient @mock.patch( - 'synapsepy.user.User._do_request', + 'synapsepy.lib.user.User._do_request', return_value={}, autospec=True ) @@ -58,7 +58,7 @@ def setUp(self): self.node_trans_count = get_all_trans_resp['trans_count'] @mock.patch( - 'synapsepy.http_client.HttpClient.get', + 'synapsepy.helpers.http_client.HttpClient.get', return_value={'refresh_token':'1234'}, autospec=True ) @@ -69,7 +69,7 @@ def test_refresh(self, mock_get, mock_request): ) @mock.patch( - 'synapsepy.http_client.HttpClient.post', + 'synapsepy.helpers.http_client.HttpClient.post', return_value={'oauth_key':'1234'}, autospec=True )