Skip to content
Snippets Groups Projects
Commit 18266783 authored by MJB's avatar MJB
Browse files

started to work on mock router API

parent 96cdd35d
No related branches found
No related tags found
No related merge requests found
import pytest
from pyramid import testing
from pyramid.httpexceptions import HTTPBadRequest
from time import sleep
from clmcservice.utilities import CONFIG_ATTRIBUTES, PROCESS_ATTRIBUTE, RUNNING_FLAG, MALFORMED_FLAG, URL_REGEX
import os
import signal
class TestSRMockAPI(object):
@pytest.fixture(autouse=True)
def app_config(self):
print("app_config")
self.config = testing.setUp()
# endpoint
# sr
# sfc_i
# sf_i
self.config.add_settings({
'my_endpoint_1': {'sfc_i': 'my_sfc_i_1', 'sf_i': 'my_sf_i_1', 'sr': 'my_sr_1'},
'my_endpoint_2': {'sfc_i': 'my_sfc_i_2', 'sf_i': 'my_sf_i_2', 'sr': 'my_sr_2'}})
yield
testing.tearDown()
def test_GET_config(self):
print("Test get")
# nested import so that importing the class view is part of the test itself
from clmcservice.views import SRMockConfig
request = testing.DummyRequest()
response = SRMockConfig(request).get()
print("response={0}".format(response))
@pytest.mark.parametrize("input_body, output_value", [
('{"aggregator_report_period": 10, "aggregator_database_name": "CLMCMetrics", "aggregator_database_url": "http://171.40.231.51:8086"}',
{'aggregator_report_period': 10, 'aggregator_database_name': "CLMCMetrics", 'aggregator_database_url': "http://171.40.231.51:8086"}),
])
def test_PUT_config(self, input_body, output_value):
print("Test put")
\ No newline at end of file
......@@ -306,3 +306,41 @@ class RoundTripTimeQuery(object):
reverse_data_delay = (8/10**6) * (response_size / bandwidth) * (packet_size / (packet_size - packet_header_size))
return forward_latency + forward_data_delay + service_delay + reverse_latency + reverse_data_delay
@view_defaults(route_name='sr_config', renderer='json')
class SRMockConfig(object):
"""
A class-based view for accessing and mutating the configuration of the aggregator.
"""
def __init__(self, request):
"""
Initialises the instance of the view with the request argument.
:param request: client's call request
"""
self.request = request
def get(self):
"""
A GET API call for endpoint configuration.
:return: A JSON response with the configuration of the aggregator.
"""
log.debug("\Getting endpoint configuration\n")
config = {"key": "hello"}
return config
def put(self):
"""
A PUT API call for the status of the aggregator.
:return: A JSON response to the PUT call - essentially with the new configured data and comment of the state of the aggregator
:raises HTTPBadRequest: if request body is not a valid JSON for the configurator
"""
log.debug("\Putting endpoint configuration\n")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment