Commit c1aee961 authored by Manuel's avatar Manuel

traceRetrieval: added pizza testcase

parent 25546930
import network_constants as nc
from security.token_manager import TokenManager
from typing import Dict, List
import requests
def add_table(use_case: str, table_name: str):
def add_layers(use_case:str, table_name: str, layers: List):
jwt = TokenManager.getInstance().getToken()
columns = {
"name": "name",
"dough": "dough//type",
"cheese": "dough//cheese",
"sauce": "sauces[0]//name",
"sugar": "sauces[0]//sugarcontent",
"UniqueID": "name+dough//type"
}
for layer in layers:
url = f"https://articonf1.itec.aau.at:30420/api/layers"
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = layer
)
print(url+": "+str(response.status_code)+" "+response.text)
def add_table(use_case: str, table_name: str, columns: Dict):
jwt = TokenManager.getInstance().getToken()
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
......@@ -34,4 +45,59 @@ def add_table(use_case: str, table_name: str):
def main(use_case: str):
print("PIZZA")
add_table(use_case, "pizza")
\ No newline at end of file
# table 1
add_table(
use_case,
"order",
{
"UniqueID": "orderId",
"pizzaId": "pizza",
"totalPrice": "price"
}
)
# table 2
add_table(
use_case,
"pizza",
{
"UniqueID": "id",
"name": "name",
"doughType": "dough//type",
"hasSpinach": "dough//spinach",
"firstTopping": "toppings[0]//name",
"firstToppingPrice": "toppings[0]//price",
"toppingInfo": "toppings[0]//name+toppings[0]//price"
}
)
# layers table 1
add_layers(use_case, "pizza",
[
{
"use_case": use_case,
"table": "pizza",
"name": "Price_Layer",
"properties": [
"UniqueID",
"firstToppingPrice"
],
"cluster_properties": [
"firstToppingPrice"
]
},
{
"use_case": use_case,
"table": "pizza",
"name": "Dough_Layer",
"properties": [
"UniqueID",
"doughType"
],
"cluster_properties": [
"doughType"
]
},
]
)
\ No newline at end of file
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
......@@ -91,8 +91,8 @@ class MessageHandler:
mappings - Required: contains string->path mappings, describing how the flattened object is built
'''
print("TRANSACTION: "+str(transaction))
print("MAPPINGS: "+str(mappings))
# print("TRANSACTION: "+str(transaction))
# print("MAPPINGS: "+str(mappings))
flattened = {}
......
......@@ -67,8 +67,8 @@ class Test_MessageHandler(unittest.TestCase):
def _get_pizza_message(self) -> str:
message_values = \
{
'type': 'blockchain-transaction',
'content':
"type": "blockchain-transaction",
"content":
{
"ApplicationType": "debug",
"docType": "pizza",
......@@ -92,7 +92,6 @@ class Test_MessageHandler(unittest.TestCase):
"price": 0.1,
}
],
}
}
return json.dumps(message_values)
......
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