From 50c6e2c840bd5aaa8ae4642c8a1eae81eaefeb62 Mon Sep 17 00:00:00 2001 From: izzy lyseggen Date: Mon, 18 Jan 2021 11:45:01 +0000 Subject: [PATCH] test(config): set up tests with local server --- tests/__init__.py | 0 tests/conftest.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..729e7c8 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,47 @@ +import uuid +import pytest +import requests +from speckle.api.client import SpeckleClient + + +@pytest.fixture(scope="session") +def host(): + return "127.0.0.1:3000" + + +@pytest.fixture(scope="session") +def seed_user(host): + seed = uuid.uuid4().hex + user_dict = { + "email": f"{seed[0:7]}@spockle.com", + "password": "$uper$3cr3tP@ss", + "name": f"{seed[0:7]} Name", + "company": "test spockle", + } + + r = requests.post( + url=f"http://{host}/auth/local/register?challenge=pyspeckletests", + data=user_dict, + ) + access_code = r.url.split("access_code=")[1] + + r_tokens = requests.post( + url=f"http://{host}/auth/token", + json={ + "appSecret": "spklwebapp", + "appId": "spklwebapp", + "accessCode": access_code, + "challenge": "pyspeckletests", + }, + ) + + user_dict["token"] = r_tokens.json()["token"] + + return user_dict + + +@pytest.fixture(scope="session") +def client(host, seed_user): + client = SpeckleClient(host=host, use_ssl=False) + client.authenticate(seed_user["token"]) + return client