Skip to content

Commit af780cf

Browse files
committed
Fix failing tests and add basic REST API and Restlet tests
1 parent 4f94345 commit af780cf

File tree

7 files changed

+59
-33
lines changed

7 files changed

+59
-33
lines changed

netsuite/rest_api.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from .config import Config
55
from .rest_api_base import RestApiBase
6+
from .util import cached_property
67

78
logger = logging.getLogger(__name__)
89

@@ -18,10 +19,13 @@ def __init__(
1819
concurrent_requests: int = 10,
1920
):
2021
self._config = config
21-
self._hostname = self._make_hostname()
2222
self._default_timeout = default_timeout
2323
self._concurrent_requests = concurrent_requests
2424

25+
@cached_property
26+
def hostname(self) -> str:
27+
return self._make_hostname()
28+
2529
async def get(self, subpath: str, **request_kw):
2630
return await self._request("GET", subpath, **request_kw)
2731

@@ -85,7 +89,7 @@ def _make_hostname(self):
8589
return f"{self._config.account_slugified}.suitetalk.api.netsuite.com"
8690

8791
def _make_url(self, subpath: str):
88-
return f"https://{self._hostname}/services/rest{subpath}"
92+
return f"https://{self.hostname}/services/rest{subpath}"
8993

9094
def _make_default_headers(self):
9195
return {

netsuite/restlet.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from .config import Config
44
from .rest_api_base import RestApiBase
5+
from .util import cached_property
56

67
logger = logging.getLogger(__name__)
78

@@ -17,10 +18,13 @@ def __init__(
1718
concurrent_requests: int = 10,
1819
):
1920
self._config = config
20-
self._hostname = self._make_hostname()
2121
self._default_timeout = default_timeout
2222
self._concurrent_requests = concurrent_requests
2323

24+
@cached_property
25+
def hostname(self) -> str:
26+
return self._make_hostname()
27+
2428
async def get(self, script_id: int, *, deploy: int = 1, **request_kw):
2529
subpath = self._make_restlet_params(script_id, deploy)
2630
return await self._request("GET", subpath, **request_kw)
@@ -44,4 +48,4 @@ def _make_hostname(self):
4448
return f"{self._config.account_slugified}.restlets.api.netsuite.com"
4549

4650
def _make_url(self, subpath: str) -> str:
47-
return f"https://{self._hostname}/app/site/hosting/restlet.nl{subpath}"
51+
return f"https://{self.hostname}/app/site/hosting/restlet.nl{subpath}"

tests/conftest.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from netsuite import Config
4+
5+
6+
@pytest.fixture
7+
def dummy_config():
8+
return Config(
9+
account="123456_SB1",
10+
auth={
11+
"consumer_key": "abcdefghijklmnopqrstuvwxyz0123456789",
12+
"consumer_secret": "abcdefghijklmnopqrstuvwxyz0123456789",
13+
"token_id": "abcdefghijklmnopqrstuvwxyz0123456789",
14+
"token_secret": "abcdefghijklmnopqrstuvwxyz0123456789",
15+
},
16+
)

tests/test_base.py

-29
This file was deleted.

tests/test_rest_api.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from netsuite import NetSuiteRestApi
2+
3+
4+
def test_expected_hostname(dummy_config):
5+
rest_api = NetSuiteRestApi(dummy_config)
6+
assert rest_api.hostname == "123456-sb1.suitetalk.api.netsuite.com"

tests/test_restlet.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from netsuite import NetSuiteRestlet
2+
3+
4+
def test_expected_hostname(dummy_config):
5+
restlet = NetSuiteRestlet(dummy_config)
6+
assert restlet.hostname == "123456-sb1.restlets.api.netsuite.com"

tests/test_soap_api.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from netsuite import NetSuiteSoapApi
4+
from netsuite.soap_api.zeep import ZEEP_INSTALLED
5+
6+
pytestmark = pytest.mark.skipif(not ZEEP_INSTALLED, reason="Requires zeep")
7+
8+
9+
def test_netsuite_hostname(dummy_config):
10+
soap_api = NetSuiteSoapApi(dummy_config)
11+
assert soap_api.hostname == "123456-sb1.suitetalk.api.netsuite.com"
12+
13+
14+
def test_netsuite_wsdl_url(dummy_config):
15+
soap_api = NetSuiteSoapApi(dummy_config)
16+
assert (
17+
soap_api.wsdl_url
18+
== "https://123456-sb1.suitetalk.api.netsuite.com/wsdl/v2021_1_0/netsuite.wsdl"
19+
)

0 commit comments

Comments
 (0)