Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
pymemri
Commits
14322b2e
Commit
14322b2e
authored
2 years ago
by
Eelco van der Wel
Browse files
Options
Download
Email Patches
Plain Diff
create account fix + tests
parent
5565989d
Pipeline
#11594
passed with stage
in 2 minutes and 38 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pymemri/pod/api.py
+1
-2
pymemri/pod/api.py
pymemri/pod/client.py
+8
-4
pymemri/pod/client.py
tests/pod/test_client.py
+21
-10
tests/pod/test_client.py
with
30 additions
and
16 deletions
+30
-16
pymemri/pod/api.py
+
1
-
2
View file @
14322b2e
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
pymemri/pod/client.py
+
8
-
4
View file @
14322b2e
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
tests/pod/test_client.py
+
21
-
10
View file @
14322b2e
...
...
@@ -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
())
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets