From 1826678314beccee13f52baa9692f7d03b1dad5d Mon Sep 17 00:00:00 2001
From: MJB <mjb@it-innovation.soton.ac.uk>
Date: Wed, 13 Jun 2018 15:37:22 +0100
Subject: [PATCH] started to work on mock router API

---
 src/service/clmcservice/test_sr_mock_view.py | 49 ++++++++++++++++++++
 src/service/clmcservice/views.py             | 38 +++++++++++++++
 2 files changed, 87 insertions(+)
 create mode 100644 src/service/clmcservice/test_sr_mock_view.py

diff --git a/src/service/clmcservice/test_sr_mock_view.py b/src/service/clmcservice/test_sr_mock_view.py
new file mode 100644
index 0000000..053066c
--- /dev/null
+++ b/src/service/clmcservice/test_sr_mock_view.py
@@ -0,0 +1,49 @@
+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
diff --git a/src/service/clmcservice/views.py b/src/service/clmcservice/views.py
index b033675..ddcdd2e 100644
--- a/src/service/clmcservice/views.py
+++ b/src/service/clmcservice/views.py
@@ -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")
-- 
GitLab