Skip to content

Commit

Permalink
fix(integration-tests): fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gjedlicska committed Apr 6, 2023
1 parent 420c73f commit a4ed7eb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


{
"name": "Python: Current File",
Expand All @@ -17,8 +18,8 @@
"name": "Pytest",
"type": "python",
"request": "launch",
"program": "poetry",
"args": ["run", "pytest"],
"program": "pytest",
"args": [],
"console": "integratedTerminal",
"justMyCode": true
}
Expand Down
23 changes: 17 additions & 6 deletions src/specklepy/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from gql import Client
from gql.transport.requests import RequestsHTTPTransport
from gql.transport.websockets import WebsocketsTransport
from gql.transport.exceptions import TransportServerError

from specklepy.api import resources
from specklepy.api.credentials import Account, get_account_from_token
Expand Down Expand Up @@ -164,13 +165,23 @@ def _set_up_client(self) -> None:

self._init_resources()

if self.user.get() is None:
warn(
SpeckleWarning(
"Possibly invalid token - could not authenticate Speckle Client"
f" for server {self.url}"
try:
user_or_error = self.active_user.get()
if isinstance(user_or_error, SpeckleException):
if isinstance(user_or_error.exception, TransportServerError):
raise user_or_error.exception
else:
raise user_or_error
except TransportServerError as ex:
if ex.code == 403:
warn(
SpeckleWarning(
"Possibly invalid token - could not authenticate Speckle Client"
f" for server {self.url}"
)
)
)
else:
raise ex

def execute_query(self, query: str) -> Dict:
return self.httpclient.execute(query)
Expand Down
17 changes: 9 additions & 8 deletions src/specklepy/transports/server/batch_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,18 @@ def _sending_thread_main(self):
self._exception = self._exception or ex
LOG.error("ServerTransport sending thread error: " + str(ex))

def _bg_send_batch(self, session, batch):
def _bg_send_batch(self, session: requests.Session, batch):
object_ids = [obj[0] for obj in batch]
try:
server_has_object = session.post(
url=f"{self.server_url}/api/diff/{self.stream_id}",
data={"objects": json.dumps(object_ids)},
).json()
except Exception as ex:
response = session.post(
url=f"{self.server_url}/api/diff/{self.stream_id}",
data={"objects": json.dumps(object_ids)},
)
if response.status_code == 403:
raise SpeckleException(
f"Invalid credentials - cannot send objects to server {self.server_url}"
) from ex
)
response.raise_for_status()
server_has_object = response.json()

new_object_ids = [x for x in object_ids if not server_has_object[x]]
new_object_ids = set(new_object_ids)
Expand Down
5 changes: 4 additions & 1 deletion tests/intergration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from specklepy.objects.base import Base
from specklepy.objects.fakemesh import FakeDirection, FakeMesh
from specklepy.objects.geometry import Point
from urllib.parse import urlparse, parse_qs


metrics.disable()

Expand Down Expand Up @@ -38,7 +40,8 @@ def seed_user(host):
)
if not r.ok:
raise Exception(f"Cannot seed user: {r.reason}")
access_code = r.text.split("access_code=")[1]
redirect_url = urlparse(r.headers.get('location'))
access_code = parse_qs(redirect_url.query)['access_code'][0] # type: ignore

r_tokens = requests.post(
url=f"http://{host}/auth/token",
Expand Down

0 comments on commit a4ed7eb

Please sign in to comment.