Commit 14322b2e authored by Eelco van der Wel's avatar Eelco van der Wel :speech_balloon:
Browse files

create account fix + tests

parent 5565989d
Pipeline #11594 passed with stage
in 2 minutes and 38 seconds
Showing with 30 additions and 16 deletions
+30 -16
......@@ -53,9 +53,8 @@ class PodAPI:
f"{self._url}/{self.version}/account",
json={"ownerKey": self.owner_key, "databaseKey": self.database_key},
)
if response.status_code != 200:
logger.error(f"Failed to register the account {response.text}")
raise PodError(response.status_code, response.text)
def test_connection(self) -> bool:
try:
......
......@@ -53,10 +53,8 @@ class PodClient:
self.default_priority = Priority(default_priority)
if owner_key is None or create_account:
# owner_key not provided by the caller, create account for newly generated one
# or enforced to do so by the flag
self.api.create_account()
if create_account:
self.create_account()
self.api.test_connection()
self.local_db = DB()
......@@ -75,6 +73,12 @@ class PodClient:
def generate_random_key():
return "".join([str(random.randint(0, 9)) for i in range(64)])
def create_account(self):
try:
self.api.create_account()
except PodError as e:
logger.warning(e)
def register_base_schemas(self):
result = self.add_to_schema(PluginRun, Account)
if not result:
......
......@@ -2,17 +2,9 @@ from typing import List
import pytest
from pymemri.data.schema import (
Account,
Edge,
EmailMessage,
Item,
OauthFlow,
Person,
PluginRun,
)
from pymemri.data.schema import Account, Edge, EmailMessage, Item, Person, PluginRun
from pymemri.examples.example_schema import Dog
from pymemri.pod.client import PodClient
from pymemri.pod.client import PodClient, PodError
from pymemri.pod.graphql_utils import GQLQuery
......@@ -299,3 +291,22 @@ def test_plugin_status(client: PodClient):
run = PluginRun(containerImage="")
client.create(run)
assert client.plugin_status([run.id])[run.id] == "unreachable"
def test_create_account():
# Create client with new account
client = PodClient()
owner_key = client.owner_key
database_key = client.database_key
# Create another client with same keys
client = PodClient(owner_key=owner_key, database_key=database_key, create_account=False)
assert len(client.search({"type": "ItemPropertySchema"}))
# Create new client + account with same keys only raises warning
client = PodClient(owner_key=owner_key, database_key=database_key, create_account=True)
assert len(client.search({"type": "ItemPropertySchema"}))
# New pod without create_account throws error
with pytest.raises(PodError):
_ = PodClient(create_account=False, owner_key=PodClient.generate_random_key())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment