-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from cehbrecht/work-on-tests
Work on tests
- Loading branch information
Showing
7 changed files
with
124 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ dependencies: | |
- jsonschema-with-format | ||
- dataclasses-json | ||
# tests | ||
- pytest | ||
- pytest | ||
- sqlite |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from .rest import RESTClient | ||
from .dummy import DummyClient | ||
|
||
|
||
def PidMaker(dry_run=True): | ||
if dry_run: | ||
client = DummyClient() | ||
else: | ||
client = RESTClient() | ||
return client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class BaseClient: | ||
def register_handle(self, handle, record): | ||
raise NotImplementedError | ||
|
||
def check_if_handle_exists(self, handle): | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from .base import BaseClient | ||
|
||
import sqlite3 | ||
import json | ||
|
||
import logging | ||
|
||
LOGGER = logging.getLogger("piddiplatsch") | ||
|
||
conn = sqlite3.connect(":memory:") | ||
cursor = conn.cursor() | ||
|
||
|
||
def table_exists(table_name): | ||
cursor.execute( | ||
"SELECT name FROM sqlite_master WHERE type='table' AND name=?", (table_name,) | ||
) | ||
return cursor.fetchone() is not None | ||
|
||
|
||
if not table_exists("data"): | ||
cursor.execute( | ||
"""CREATE TABLE data ( | ||
id TEXT PRIMARY KEY, | ||
json_string TEXT | ||
)""" | ||
) | ||
|
||
|
||
class DummyClient(BaseClient): | ||
|
||
def register_handle(self, handle, record): | ||
LOGGER.info(f"handle: {handle}") | ||
LOGGER.info(f"record: {record}") | ||
|
||
data = json.dumps(record) | ||
|
||
cursor.execute( | ||
"""INSERT INTO data (id, json_string) VALUES (?, ?)""", | ||
(handle, data), | ||
) | ||
conn.commit() | ||
|
||
def check_if_handle_exists(self, handle): | ||
if not handle: | ||
return False | ||
elif "invalid" in handle: | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from .base import BaseClient | ||
|
||
import pyhandle | ||
|
||
|
||
class RESTClient(BaseClient): | ||
def __init__(self): | ||
self.client = pyhandle.handleclient.PyHandleClient("rest") | ||
|
||
def register_handle(self, handle, record): | ||
self.client.register_handle(handle, record) | ||
|
||
def check_if_handle_exists(self, handle): | ||
return self.client.check_if_handle_exists(handle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters