-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Test Coverage -> Fixed Test report coverage. The Python Server process's coverage was not being reported. 2. Unitest -> Use pytest fixtures for unittesting. Organized test cases. 3. SQLiteClient -> Fix in retry logic. Retry was not sending the request(again), it was simply polling the REQ Socket. 4. SQLiteServer -> Removed server.stop method. Keyboard interupt handling is handled in server.start() method 5. Serialization -> Changed msgpack-python to faster and efficient msgpack 6. Exceptions - The SQLiteClient will not raise an SQLiteRxConnectionError exception if the server is offline. 7. Exceptions - Renamed the error classes. SQLiteRxCompressionError, SQLiteRxConnectionError, SQLiteRxTransportError SQLiteRxSerializationError
- Loading branch information
Abhishek Singh
committed
Jun 6, 2020
1 parent
229da55
commit a0cbc97
Showing
29 changed files
with
457 additions
and
526 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
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 |
---|---|---|
|
@@ -8,3 +8,6 @@ dist | |
sqlite_rx.egg-info | ||
.coveragerc | ||
docker_examples | ||
.coverage | ||
.pytest_cache | ||
.coverage |
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 |
---|---|---|
|
@@ -5,4 +5,6 @@ sqlite_rx.egg-info/ | |
cover/ | ||
build/ | ||
dist/ | ||
.coverage | ||
.pytest_cache | ||
.coverage |
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
click | ||
msgpack-python | ||
msgpack | ||
pyzmq | ||
tornado |
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
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
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
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
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
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,29 @@ | ||
import os | ||
|
||
import socket | ||
|
||
import tempfile | ||
from contextlib import contextmanager | ||
import logging.config | ||
|
||
from sqlite_rx import get_default_logger_settings | ||
from sqlite_rx.auth import KeyGenerator | ||
|
||
logging.config.dictConfig(get_default_logger_settings(level="DEBUG")) | ||
|
||
LOG = logging.getLogger(__file__) | ||
|
||
|
||
@contextmanager | ||
def get_server_auth_files(): | ||
"""Generate Temporary Private and Public keys for ZAP and CurveZMQ SQLiteServer | ||
""" | ||
with tempfile.TemporaryDirectory() as curve_dir: | ||
LOG.info("Curve dir is %s", curve_dir) | ||
server_key_id = "id_server_{}_curve".format(socket.gethostname()) | ||
key_generator = KeyGenerator(destination_dir=curve_dir, key_id=server_key_id) | ||
key_generator.generate() | ||
server_public_key = os.path.join(curve_dir, "{}.key".format(server_key_id)) | ||
server_private_key = os.path.join(curve_dir, "{}.key_secret".format(server_key_id)) | ||
yield curve_dir, server_key_id, server_public_key, server_private_key |
Empty file.
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,55 @@ | ||
import pytest | ||
|
||
import os | ||
import socket | ||
import shutil | ||
import signal | ||
import sqlite3 | ||
import logging.config | ||
|
||
from sqlite_rx import get_default_logger_settings | ||
from sqlite_rx.auth import KeyGenerator | ||
from sqlite_rx.client import SQLiteClient | ||
from sqlite_rx.server import SQLiteServer | ||
from sqlite_rx.tests import get_server_auth_files | ||
|
||
logging.config.dictConfig(get_default_logger_settings(level="DEBUG")) | ||
|
||
LOG = logging.getLogger(__file__) | ||
|
||
@pytest.fixture(scope="module") | ||
def curvezmq_client(): | ||
with get_server_auth_files() as auth_files: | ||
curve_dir, server_key_id, server_public_key, server_private_key = auth_files | ||
client_key_id = "id_client_{}_curve".format(socket.gethostname()) | ||
key_generator = KeyGenerator(destination_dir=curve_dir, key_id=client_key_id) | ||
key_generator.generate() | ||
client_public_key = os.path.join(curve_dir, "{}.key".format(client_key_id)) | ||
client_private_key = os.path.join(curve_dir, "{}.key_secret".format(client_key_id)) | ||
shutil.copyfile(client_public_key, os.path.join(curve_dir, | ||
'authorized_clients', | ||
"{}.key".format(client_key_id))) | ||
auth_config = { | ||
sqlite3.SQLITE_OK: { | ||
sqlite3.SQLITE_DROP_TABLE | ||
} | ||
} | ||
server = SQLiteServer(bind_address="tcp://127.0.0.1:5002", | ||
use_encryption=True, | ||
curve_dir=curve_dir, | ||
server_curve_id=server_key_id, | ||
auth_config=auth_config, | ||
database=":memory:") | ||
|
||
client = SQLiteClient(connect_address="tcp://127.0.0.1:5002", | ||
server_curve_id=server_key_id, | ||
client_curve_id=client_key_id, | ||
curve_dir=curve_dir, | ||
use_encryption=True) | ||
server.start() | ||
LOG.info("Started Test SQLiteServer") | ||
yield client | ||
os.kill(server.pid, signal.SIGINT) | ||
server.join() | ||
client.shutdown() | ||
|
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,59 @@ | ||
import platform | ||
|
||
sqlite_error_prefix = "sqlite3.OperationalError" | ||
|
||
if platform.python_implementation() == "PyPy": | ||
sqlite_error_prefix = "_sqlite3.OperationalError" | ||
|
||
|
||
def test_not_present(curvezmq_client): | ||
result = curvezmq_client.execute('SELECT * FROM IDOLS') | ||
expected_result = { | ||
'items': [], | ||
'error': { | ||
'message': '{0}: no such table: IDOLS'.format(sqlite_error_prefix), | ||
'type': '{0}'.format(sqlite_error_prefix)}} | ||
assert type(result) == dict | ||
assert result == expected_result | ||
|
||
|
||
def test_table_creation(curvezmq_client): | ||
result = curvezmq_client.execute('CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)') | ||
expected_result = {"error": None, 'items': []} | ||
assert result == expected_result | ||
|
||
|
||
def test_table_rows_insertion(curvezmq_client): | ||
purchases = [('2006-03-28', 'BUY', 'IBM', 1000, 45.00), | ||
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), | ||
('2006-04-06', 'SELL', 'XOM', 500, 53.00), | ||
('2006-03-28', 'BUY', 'IBM', 1000, 45.00), | ||
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), | ||
('2006-04-06', 'SELL', 'XOM', 500, 53.00), | ||
('2006-03-28', 'BUY', 'IBM', 1000, 45.00), | ||
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), | ||
('2006-04-06', 'SELL', 'XOM', 500, 53.00), | ||
('2006-03-28', 'BUY', 'IBM', 1000, 45.00), | ||
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), | ||
('2006-04-06', 'SELL', 'XOM', 500, 53.00), | ||
('2006-03-28', 'BUY', 'IBM', 1000, 45.00), | ||
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), | ||
('2006-04-06', 'SELL', 'XOM', 500, 53.00), | ||
('2006-03-28', 'BUY', 'IBM', 1000, 45.00), | ||
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), | ||
('2006-04-06', 'SELL', 'XOM', 500, 53.00), | ||
('2006-03-28', 'BUY', 'IBM', 1000, 45.00), | ||
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), | ||
('2006-04-06', 'SELL', 'XOM', 500, 53.00), | ||
('2006-03-28', 'BUY', 'IBM', 1000, 45.00), | ||
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), | ||
('2006-04-06', 'SELL', 'XOM', 500, 53.00), | ||
('2006-03-28', 'BUY', 'IBM', 1000, 45.00), | ||
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), | ||
('2006-04-06', 'SELL', 'XOM', 500, 53.00), | ||
] | ||
|
||
result = curvezmq_client.execute('INSERT INTO stocks VALUES (?,?,?,?,?)', *purchases, execute_many=True) | ||
expected_result = {'error': None, 'items': [], 'row_count': 27} | ||
assert result == expected_result | ||
|
Empty file.
Oops, something went wrong.