Skip to content

Commit

Permalink
Fix failing tests and add basic REST API and Restlet tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsvante committed Apr 27, 2021
1 parent 4f94345 commit af780cf
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 33 deletions.
8 changes: 6 additions & 2 deletions netsuite/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .config import Config
from .rest_api_base import RestApiBase
from .util import cached_property

logger = logging.getLogger(__name__)

Expand All @@ -18,10 +19,13 @@ def __init__(
concurrent_requests: int = 10,
):
self._config = config
self._hostname = self._make_hostname()
self._default_timeout = default_timeout
self._concurrent_requests = concurrent_requests

@cached_property
def hostname(self) -> str:
return self._make_hostname()

async def get(self, subpath: str, **request_kw):
return await self._request("GET", subpath, **request_kw)

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

def _make_url(self, subpath: str):
return f"https://{self._hostname}/services/rest{subpath}"
return f"https://{self.hostname}/services/rest{subpath}"

def _make_default_headers(self):
return {
Expand Down
8 changes: 6 additions & 2 deletions netsuite/restlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .config import Config
from .rest_api_base import RestApiBase
from .util import cached_property

logger = logging.getLogger(__name__)

Expand All @@ -17,10 +18,13 @@ def __init__(
concurrent_requests: int = 10,
):
self._config = config
self._hostname = self._make_hostname()
self._default_timeout = default_timeout
self._concurrent_requests = concurrent_requests

@cached_property
def hostname(self) -> str:
return self._make_hostname()

async def get(self, script_id: int, *, deploy: int = 1, **request_kw):
subpath = self._make_restlet_params(script_id, deploy)
return await self._request("GET", subpath, **request_kw)
Expand All @@ -44,4 +48,4 @@ def _make_hostname(self):
return f"{self._config.account_slugified}.restlets.api.netsuite.com"

def _make_url(self, subpath: str) -> str:
return f"https://{self._hostname}/app/site/hosting/restlet.nl{subpath}"
return f"https://{self.hostname}/app/site/hosting/restlet.nl{subpath}"
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

from netsuite import Config


@pytest.fixture
def dummy_config():
return Config(
account="123456_SB1",
auth={
"consumer_key": "abcdefghijklmnopqrstuvwxyz0123456789",
"consumer_secret": "abcdefghijklmnopqrstuvwxyz0123456789",
"token_id": "abcdefghijklmnopqrstuvwxyz0123456789",
"token_secret": "abcdefghijklmnopqrstuvwxyz0123456789",
},
)
29 changes: 0 additions & 29 deletions tests/test_base.py

This file was deleted.

6 changes: 6 additions & 0 deletions tests/test_rest_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from netsuite import NetSuiteRestApi


def test_expected_hostname(dummy_config):
rest_api = NetSuiteRestApi(dummy_config)
assert rest_api.hostname == "123456-sb1.suitetalk.api.netsuite.com"
6 changes: 6 additions & 0 deletions tests/test_restlet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from netsuite import NetSuiteRestlet


def test_expected_hostname(dummy_config):
restlet = NetSuiteRestlet(dummy_config)
assert restlet.hostname == "123456-sb1.restlets.api.netsuite.com"
19 changes: 19 additions & 0 deletions tests/test_soap_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest

from netsuite import NetSuiteSoapApi
from netsuite.soap_api.zeep import ZEEP_INSTALLED

pytestmark = pytest.mark.skipif(not ZEEP_INSTALLED, reason="Requires zeep")


def test_netsuite_hostname(dummy_config):
soap_api = NetSuiteSoapApi(dummy_config)
assert soap_api.hostname == "123456-sb1.suitetalk.api.netsuite.com"


def test_netsuite_wsdl_url(dummy_config):
soap_api = NetSuiteSoapApi(dummy_config)
assert (
soap_api.wsdl_url
== "https://123456-sb1.suitetalk.api.netsuite.com/wsdl/v2021_1_0/netsuite.wsdl"
)

0 comments on commit af780cf

Please sign in to comment.