Commit e84e36cf authored by Bogdan's avatar Bogdan

Merge remote-tracking branch 'origin/develop' into bugfix/traceIdDeduplication

parents 4e2e062c 52f64f8d
...@@ -10,7 +10,7 @@ It additionally installs all dependencies from a '../requirements.txt' via pip. ...@@ -10,7 +10,7 @@ It additionally installs all dependencies from a '../requirements.txt' via pip.
Use command line argument '-w' to run on windows. Use command line argument '-w' to run on windows.
''' '''
PY = 'py' if (len(sys.argv) > 1 and sys.argv[1] == '-w') else 'python3.7' # use -w to run on windows PY = sys.argv[2] if (len(sys.argv) > 1 and sys.argv[1] == '-py') else 'python3.7' # use -py to use your own python command
ROOT = pathlib.Path(__file__).parent.parent.absolute() ROOT = pathlib.Path(__file__).parent.parent.absolute()
TESTS_FOLDER_NAME = os.path.normpath("/tests") TESTS_FOLDER_NAME = os.path.normpath("/tests")
......
...@@ -21,7 +21,8 @@ from messaging.ReconnectingMessageManager import ReconnectingMessageManager ...@@ -21,7 +21,8 @@ from messaging.ReconnectingMessageManager import ReconnectingMessageManager
from messaging.MessageHandler import MessageHandler from messaging.MessageHandler import MessageHandler
# init message handler # init message handler
message_handler = MessageHandler() from db.repository import Repository
message_handler = MessageHandler(Repository())
def message_received_callback(channel, method, properties, body): def message_received_callback(channel, method, properties, body):
message_handler.handle_generic(body) message_handler.handle_generic(body)
......
import network_constants as netconst import network_constants as netconst
from security.token_manager import TokenManager from security.token_manager import TokenManager
from db.entities import Layer from db.entities import Layer
from db.repository import Repository
import json import json
import requests import requests
...@@ -12,8 +11,8 @@ import logging ...@@ -12,8 +11,8 @@ import logging
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
class MessageHandler: class MessageHandler:
def __init__(self): def __init__(self, repository):
self._repository = Repository() self._repository = repository
def handle_generic(self, body): def handle_generic(self, body):
LOGGER.info(f"Received message: {body}") LOGGER.info(f"Received message: {body}")
......
...@@ -2,8 +2,11 @@ import unittest ...@@ -2,8 +2,11 @@ import unittest
import manage_sys_paths import manage_sys_paths
import json import json
from db.repository import Repository
from db.entities.layer import Layer
from messaging.MessageHandler import MessageHandler from messaging.MessageHandler import MessageHandler
from messaging.DummyMessageManager import DummyMessageManager as DummyMessageSender from messaging.DummyMessageManager import DummyMessageManager as DummyMessageSender
from typing import List
class DummyMongoRepo: class DummyMongoRepo:
'''Dummy class to be used for testing the MessageHandler''' '''Dummy class to be used for testing the MessageHandler'''
...@@ -12,6 +15,28 @@ class DummyMongoRepo: ...@@ -12,6 +15,28 @@ class DummyMongoRepo:
def insert_trace(self, trace): def insert_trace(self, trace):
self.last_trace = trace self.last_trace = trace
def delete_layer(self, layer):
pass
def add_layer(self, layer):
pass
def get_layers_for_use_case_and_table(self, use_case, table):
return [
Layer(
layer_info={
"layer_name": "pizza_layer_test",
"properties": ["UniqueID"],
"total_properties": ["UniqueID"],
"use_case": "debug",
"table": "pizza"
}
)
]
def add_layer_nodes(self, nodes: List):
pass
def get_layers_for_use_case_and_table(use_case, table): def get_layers_for_use_case_and_table(use_case, table):
testLayers = [ testLayers = [
...@@ -86,7 +111,7 @@ class Test_Pipeline(unittest.TestCase): ...@@ -86,7 +111,7 @@ class Test_Pipeline(unittest.TestCase):
def setUp(self): def setUp(self):
self.repo = DummyMongoRepo() self.repo = DummyMongoRepo()
self.msg_sender = DummyMessageSender.get_instance() self.msg_sender = DummyMessageSender.get_instance()
self.handler = MessageHandler() self.handler = MessageHandler(self.repo)
def _buildTraceMessage(self): def _buildTraceMessage(self):
return { return {
......
import unittest import unittest
# import manage_sys_paths import manage_sys_paths
from db.entities.layer_adapter import LayerAdapter from db.entities.layer_adapter import LayerAdapter
......
[
{
"type": "blockchain-transaction",
"ApplicationType": "debug",
"docType": "order",
"orderId": 1,
"pizza": 1,
"price": 12.0,
"restaurant": 1
},
{
"type": "blockchain-transaction",
"ApplicationType": "debug",
"docType": "pizza",
"id": 1,
"name": "Diavolo",
"dough": {
"type": "wheat",
"spinach": false
},
"toppings": [
{
"name": "Tomato Sauce",
"price": 1.00
},
{
"name": "Cheese",
"price": 0.50
},
{
"name": "Chilli Oil",
"price": 0.50
},
{
"name": "Peppers",
"price": 1.50
}
]
}
]
import unittest
import manage_sys_paths
from messaging.DummyMessageManager import DummyMessageManager
# init dummy message manager so no connection to rabbitmq is established
_ = DummyMessageManager.get_instance()
import routes.blockchain_trace as blockchain_trace
from env_info import get_resources_path
from security.token_manager import TokenManager
import network_constants
import json
import requests
class Test_BlockchainTrace(unittest.TestCase):
def test_isBlockchainTraceValid_validInputAndTypes(self):
with open(f"{get_resources_path()}/pizza_transactions.json") as f:
transactions = json.loads(f.read())
jwt = TokenManager.getInstance().getToken()
for transaction in transactions:
url = f'https://{network_constants.REST_GATEWAY_HOSTNAME}:{network_constants.REST_GATEWAY_REST_PORT}/api/trace'
response = requests.post(
url,
verify = False,
proxies = { "http":None, "https":None },
headers = {"Authorization": f"Bearer {jwt}"},
json = transaction
)
print(f"{url} {response.status_code}")
if response.status_code != 201:
print(f"server responded with {response.status_code}: {response.text}")
self.assertTrue(response.status_code==201, "Should accept the new trace.")
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
...@@ -77,10 +77,5 @@ class Test_MessageHandler(unittest.TestCase): ...@@ -77,10 +77,5 @@ class Test_MessageHandler(unittest.TestCase):
} }
return json.dumps(message_values) return json.dumps(message_values)
def test_HandlePizzaMessage(self):
msg = self._get_pizza_message()
_ = self.handler.handle_blockchain_transaction(json.loads(msg)["content"])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
Markdown is supported
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