tests: sign in before the multisig setup tests (section 31 point 1)
This commit is contained in:
1 parent
a325021fd1
commit
89bfc3abf1
1 file changed
+9
-18
@@ -12,10 +12,10 @@ import tempfile
|
|||||||
import threading
|
import threading
|
||||||
import unittest
|
import unittest
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
from urllib.request import Request, urlopen
|
|
||||||
|
|
||||||
from app import AppHandler
|
from app import AppHandler
|
||||||
from database import initialize_database
|
from database import initialize_database
|
||||||
|
from server_session import SessionMixin
|
||||||
|
|
||||||
|
|
||||||
ADDRESS_PATHS = {
|
ADDRESS_PATHS = {
|
||||||
@@ -37,7 +37,7 @@ FIVE_KEY_SETUP = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class MultisigSetupApiTests(unittest.TestCase):
|
class MultisigSetupApiTests(SessionMixin, unittest.TestCase):
|
||||||
"""The setup endpoint on a new database, before anything is stored."""
|
"""The setup endpoint on a new database, before anything is stored."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -51,6 +51,9 @@ class MultisigSetupApiTests(unittest.TestCase):
|
|||||||
self.thread = threading.Thread(target=self.server.serve_forever, daemon=True)
|
self.thread = threading.Thread(target=self.server.serve_forever, daemon=True)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
self.base_url = f"http://127.0.0.1:{self.server.server_port}"
|
self.base_url = f"http://127.0.0.1:{self.server.server_port}"
|
||||||
|
# The database has no key setup yet, but every route except /health
|
||||||
|
# still needs a session (section 31 point 1).
|
||||||
|
self.authenticate()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.server.shutdown()
|
self.server.shutdown()
|
||||||
@@ -63,28 +66,16 @@ class MultisigSetupApiTests(unittest.TestCase):
|
|||||||
self.temp_dir.cleanup()
|
self.temp_dir.cleanup()
|
||||||
|
|
||||||
def get_setup(self):
|
def get_setup(self):
|
||||||
with urlopen(f"{self.base_url}/api/setup") as response:
|
return self.get_json("/api/setup")
|
||||||
self.assertEqual(response.status, 200)
|
|
||||||
return json.load(response)
|
|
||||||
|
|
||||||
def get_keys(self):
|
def get_keys(self):
|
||||||
with urlopen(f"{self.base_url}/api/keys") as response:
|
return self.get_json("/api/keys")
|
||||||
self.assertEqual(response.status, 200)
|
|
||||||
return json.load(response)
|
|
||||||
|
|
||||||
def get_key_status(self):
|
def get_key_status(self):
|
||||||
with urlopen(f"{self.base_url}/api/key-status") as response:
|
return self.get_json("/api/key-status")
|
||||||
self.assertEqual(response.status, 200)
|
|
||||||
return json.load(response)
|
|
||||||
|
|
||||||
def post_setup(self, payload):
|
def post_setup(self, payload):
|
||||||
request = Request(
|
return self.post_json("/api/setup", payload)
|
||||||
f"{self.base_url}/api/setup",
|
|
||||||
data=json.dumps(payload).encode("utf-8"),
|
|
||||||
headers={"Content-Type": "application/json"},
|
|
||||||
method="POST",
|
|
||||||
)
|
|
||||||
return urlopen(request)
|
|
||||||
|
|
||||||
def assert_setup_rejected(self, payload, status=400):
|
def assert_setup_rejected(self, payload, status=400):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in new issue
Block a user