diff options
26 files changed, 628 insertions, 37 deletions
diff --git a/osdf/__init__.py b/osdf/__init__.py index d0993ae..6529b0a 100755 --- a/osdf/__init__.py +++ b/osdf/__init__.py @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------- -# Copyright (c) 2015-2017 AT&T Intellectual Property +# Copyright (c) 2015-2018 AT&T Intellectual Property # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/osdf/adapters/__init__.py b/osdf/adapters/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/adapters/__init__.py +++ b/osdf/adapters/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/adapters/dcae/__init__.py b/osdf/adapters/dcae/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/adapters/dcae/__init__.py +++ b/osdf/adapters/dcae/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/adapters/local_data/__init__.py b/osdf/adapters/local_data/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/adapters/local_data/__init__.py +++ b/osdf/adapters/local_data/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/adapters/policy/__init__.py b/osdf/adapters/policy/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/adapters/policy/__init__.py +++ b/osdf/adapters/policy/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/adapters/sdc/__init__.py b/osdf/adapters/sdc/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/adapters/sdc/__init__.py +++ b/osdf/adapters/sdc/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/config/__init__.py b/osdf/config/__init__.py index 303a8ce..86156a1 100644 --- a/osdf/config/__init__.py +++ b/osdf/config/__init__.py @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------- -# Copyright (c) 2015-2017 AT&T Intellectual Property +# Copyright (c) 2015-2018 AT&T Intellectual Property # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/osdf/logging/__init__.py b/osdf/logging/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/logging/__init__.py +++ b/osdf/logging/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/operation/__init__.py b/osdf/operation/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/operation/__init__.py +++ b/osdf/operation/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/optimizers/__init__.py b/osdf/optimizers/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/optimizers/__init__.py +++ b/osdf/optimizers/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/optimizers/licenseopt/__init__.py b/osdf/optimizers/licenseopt/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/optimizers/licenseopt/__init__.py +++ b/osdf/optimizers/licenseopt/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/optimizers/placementopt/__init__.py b/osdf/optimizers/placementopt/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/optimizers/placementopt/__init__.py +++ b/osdf/optimizers/placementopt/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/optimizers/placementopt/conductor/__init__.py b/osdf/optimizers/placementopt/conductor/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/optimizers/placementopt/conductor/__init__.py +++ b/osdf/optimizers/placementopt/conductor/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/utils/__init__.py b/osdf/utils/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/utils/__init__.py +++ b/osdf/utils/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/osdf/webapp/__init__.py b/osdf/webapp/__init__.py index e69de29..4b25e5b 100644 --- a/osdf/webapp/__init__.py +++ b/osdf/webapp/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# diff --git a/test/adapters/test_message_router.py b/test/adapters/test_message_router.py index 2a02dc8..60580d4 100644 --- a/test/adapters/test_message_router.py +++ b/test/adapters/test_message_router.py @@ -1,3 +1,20 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# import osdf.adapters.dcae.message_router as MR import unittest diff --git a/test/bad_test_Utils.py b/test/bad_test_Utils.py deleted file mode 100644 index 3e5cecd..0000000 --- a/test/bad_test_Utils.py +++ /dev/null @@ -1,21 +0,0 @@ -import unittest -import json - -from osdf.config.base import osdf_config -from osdf.utils.programming_utils import dot_notation - - -class TestUtils(unittest.TestCase): - - def test_metrics(self): - with open('test/placement-tests/request.json', 'r') as f: - data = json.load(f) - placementInfo = data["placementInfo"] - config_local = osdf_config.core - self.assertEqual("USOSTCDALTX0101UJZZ11", dot_notation(placementInfo, config_local['service_info']['vCPE']['vcpeHostName'])) - self.assertEqual("200", dot_notation(placementInfo, config_local['service_info']['vCPE']['e2eVpnKey'])) - self.assertEqual(['vGMuxInfra', 'vG'], dot_notation(placementInfo, 'demandInfo.placementDemand.resourceModuleName')) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/dummy_test_dummy.py b/test/dummy_test_dummy.py deleted file mode 100644 index dc46d50..0000000 --- a/test/dummy_test_dummy.py +++ /dev/null @@ -1,14 +0,0 @@ -import osdf -# import osdfapp -from osdf.config.loader import load_config_file - - -def test_dummy(): - """Generate time constraints from cm-request.json and cm-policy-response.json""" - try: - load_config_file("DUMMY") - except: - pass - return 1 - - diff --git a/test/local_data/test_local_policies.py b/test/local_data/test_local_policies.py new file mode 100644 index 0000000..120b186 --- /dev/null +++ b/test/local_data/test_local_policies.py @@ -0,0 +1,50 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# +import unittest +import json +import yaml + +from osdf.adapters.local_data import local_policies + + +class TestLocalPolicies(unittest.TestCase): + + def __init__(self, *args, **kwargs): + super(self.__class__, self).__init__(*args, **kwargs) + self.folder = './test/policy-local-files' + self.invalid_policies = ['INVALID-one.json', 'INVALID-two.json'] + self.valid_policies = ['CloudAttributePolicy_vG_1.json', 'CloudAttributePolicy_vGMuxInfra_1.json'] + + def test_get_local_policies_no_policies(self): + with self.assertRaises(FileNotFoundError): + res = local_policies.get_local_policies(self.folder, self.invalid_policies) + assert res is None + + def test_get_local_valid_policies(self): + res = local_policies.get_local_policies(self.folder, self.valid_policies) + assert len(res) == len(self.valid_policies) + + def test_get_subset_valid_policies(self): + wanted = [ x[:-5] for x in self.valid_policies[:1] ] + res = local_policies.get_local_policies(self.folder, self.valid_policies, wanted) + assert len(res) == len(wanted) + + +if __name__ == "__main__": + unittest.main() + diff --git a/test/logging/test_osdf_logging.py b/test/logging/test_osdf_logging.py new file mode 100755 index 0000000..982ef0b --- /dev/null +++ b/test/logging/test_osdf_logging.py @@ -0,0 +1,182 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# +import unittest +import json +import yaml + +from osdf.logging import osdf_logging as L1 +from osdf.logging.osdf_logging import OOF_OSDFLogMessageHelper as MH +from osdf.logging.osdf_logging import OOF_OSDFLogMessageFormatter as formatter +from unittest import mock + + +class TestOSDFLogging(unittest.TestCase): + + def __init__(self, *args, **kwargs): + super(self.__class__, self).__init__(*args, **kwargs) + self.MH = MH() + self.err = Exception("Some Exception") + self.req_id = "TEST-Req-ID" + self.url = mock.MagicMock() + self.request = mock.MagicMock() + self.client = mock.MagicMock() + self.service_name = mock.MagicMock() + self.callback_url = mock.MagicMock() + self.service_name = mock.MagicMock() + self.body = mock.MagicMock() + self.desc = mock.MagicMock() + self.response = mock.MagicMock() + self.remote_addr = mock.MagicMock() + self.json_body = mock.MagicMock() + self.F = formatter + + def test_log_handlers_pre_onap(self): + res = L1.log_handlers_pre_onap() + assert type(res) == dict + + def test_format_exception(self): + res = L1.format_exception(Exception("Some error")) + + def test_accepted_valid_request(self): + res = formatter.accepted_valid_request(self.req_id, self.request) + assert res.startswith("Accepted valid request") + + def test_invalid_request(self): + res = formatter.invalid_request(self.req_id, self.err) + assert res.startswith("Invalid request") + + def test_invalid_response(self): + res = formatter.invalid_response(self.req_id, self.err) + assert res.startswith("Invalid response") + + def test_malformed_request(self): + res = formatter.malformed_request(self.request, self.err) + assert res.startswith("Malformed request") + + def test_malformed_response(self): + res = formatter.malformed_response(self.response, self.client, self.err) + assert res.startswith("Malformed response") + + def test_need_policies(self): + res = formatter.need_policies(self.req_id) + assert res.startswith("Policies required but") + + def test_policy_service_error(self): + res = formatter.policy_service_error(self.url, self.req_id, self.err) + assert res.startswith("Unable to call policy") + + def test_requesting_url(self): + res = formatter.requesting_url(self.url, self.req_id) + assert res.startswith("Making a call to URL") + + def test_requesting(self): + res = formatter.requesting(self.service_name, self.req_id) + assert res.startswith("Making a call to service") + + def test_error_requesting(self): + res = formatter.error_requesting(self.service_name, self.req_id, self.err) + assert res.startswith("Error while requesting service") + + def test_error_calling_back(self): + res = formatter.error_calling_back(self.service_name, self.callback_url, self.err) + assert res.startswith("Error while posting result to callback URL") + + def test_calling_back(self): + res = formatter.calling_back(self.req_id, self.callback_url) + assert res.startswith("Posting result to callback URL") + + def test_calling_back_with_body(self): + res = formatter.calling_back_with_body(self.req_id, self.callback_url, self.body) + assert res.startswith("Posting result to callback URL") + + def test_received_request(self): + res = formatter.received_request(self.url, self.remote_addr, self.json_body) + assert res.startswith("Received a call") + + def test_new_worker_thread(self): + res = formatter.new_worker_thread(self.req_id) + assert res.startswith("Initiating new worker thread") + + def test_inside_worker_thread(self): + res = formatter.inside_worker_thread(self.req_id) + assert res.startswith("Inside worker thread for request ID") + + def test_inside_new_thread(self): + res = formatter.inside_new_thread(self.req_id) + assert res.startswith("Spinning up a new thread for request ID") + + def test_processing(self): + res = formatter.processing(self.req_id, self.desc) + assert res.startswith("Processing request ID") + + def test_processed(self): + res = formatter.processed(self.req_id, self.desc) + assert res.startswith("Processed request ID") + + def test_error_while_processing(self): + res = formatter.error_while_processing(self.req_id, self.desc, self.err) + assert res.startswith("Error while processing request ID") + + def test_creating_local_env(self): + res = formatter.creating_local_env(self.req_id) + assert res.startswith("Creating local environment request ID") + + def test_error_local_env(self): + res = formatter.error_local_env(self.req_id, self.desc, self.err) + assert res.startswith("Error while creating local environment for request ID") + + def test_error_response_posting(self): + res = formatter.error_response_posting(self.req_id, self.desc, self.err) + assert res.startswith("Error while posting a response for a request ID") + + def test_received_http_response(self): + res = formatter.received_http_response(self.response) + assert res.startswith("Received response [code: ") + + def test_sending_response(self): + res = formatter.sending_response(self.req_id, self.desc) + assert res.startswith("Response is sent for request ID") + + def test_listening_response(self): + res = formatter.listening_response(self.req_id, self.desc) + assert res.startswith("Response is sent for request ID") + + def test_items_received(self): + res = formatter.items_received(10, "messages") + assert res == "Received 10 messages" + + def test_items_sent(self): + res = formatter.items_sent(10, "messages") + assert res == "Published 10 messages" + + def test_warn_audit_error(self): + """Log the message to error_log.warn and audit_log.warn""" + L1.warn_audit_error("Some warning message") + + def test_log_message_multi(msg): + X = L1.log_handlers_pre_onap() + wanted_methods = [ + X["error"].error, X["error"].warn, X["audit"].info, + X["metrics"].info, X["debug"].debug, X["error"].fatal + ] + L1.log_message_multi("Some log message", *wanted_methods) + + +if __name__ == "__main__": + unittest.main() + diff --git a/test/mainapp/test_osdfapp.py b/test/mainapp/test_osdfapp.py index 2ffe4f3..c162ac0 100644 --- a/test/mainapp/test_osdfapp.py +++ b/test/mainapp/test_osdfapp.py @@ -1,3 +1,20 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# import osdfapp import unittest diff --git a/test/operation/test_responses.py b/test/operation/test_responses.py new file mode 100644 index 0000000..253cb7c --- /dev/null +++ b/test/operation/test_responses.py @@ -0,0 +1,71 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# +import unittest +import json +import yaml + +from osdf.adapters.local_data import local_policies + + +class TestLocalPolicies(unittest.TestCase): + + def __init__(self, *args, **kwargs): + super(self.__class__, self).__init__(*args, **kwargs) + self.folder = './test/policy-local-files' + self.invalid_policies = ['INVALID-one.json', 'INVALID-two.json'] + self.valid_policies = ['CloudAttributePolicy_vG_1.json', 'CloudAttributePolicy_vGMuxInfra_1.json'] + + def test_get_local_policies_no_policies(self): + with self.assertRaises(FileNotFoundError): + res = local_policies.get_local_policies(self.folder, self.invalid_policies) + assert res is None + + def test_get_local_valid_policies(self): + res = local_policies.get_local_policies(self.folder, self.valid_policies) + assert len(res) == len(self.valid_policies) + + def test_get_subset_valid_policies(self): + wanted = [ x[:-5] for x in self.valid_policies[:1] ] + res = local_policies.get_local_policies(self.folder, self.valid_policies, wanted) + assert len(res) == len(wanted) + + +if __name__ == "__main__": + unittest.main() + +from flask import Response + +from osdf import ACCEPTED_MESSAGE_TEMPLATE + + +def osdf_response_for_request_accept(req_id="", text="", response_code=202, as_http=True): + """Helper method to create a response object for request acceptance, so that the object can be sent to a client + :param req_id: request ID provided by the caller + :param text: extra text description about accepting the request (e.g. "Request accepted") + :param response_code: the HTTP status code to send -- default is 202 (accepted) + :param as_http: whether to send response as HTTP response object or as a string + :return: if as_http is True, return a HTTP Response object. Otherwise, return json-encoded-message + """ + response_message = ACCEPTED_MESSAGE_TEMPLATE.render(description=text, request_id=req_id) + if not as_http: + return response_message + + response = Response(response_message, content_type='application/json; charset=utf-8') + response.headers.add('content-length', len(response_message)) + response.status_code = response_code + return response diff --git a/test/test_ConductorApiBuilder.py b/test/test_ConductorApiBuilder.py index b988efa..f809c56 100644 --- a/test/test_ConductorApiBuilder.py +++ b/test/test_ConductorApiBuilder.py @@ -1,3 +1,20 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# import unittest import json import yaml diff --git a/test/test_PolicyCalls.py b/test/test_PolicyCalls.py index b05b6dc..0378dbd 100644 --- a/test/test_PolicyCalls.py +++ b/test/test_PolicyCalls.py @@ -1,3 +1,20 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# import json import unittest diff --git a/test/test_api_validation.py b/test/test_api_validation.py index 5af81e6..9045530 100644 --- a/test/test_api_validation.py +++ b/test/test_api_validation.py @@ -1,3 +1,20 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# import json import unittest diff --git a/test/test_process_placement_opt.py b/test/test_process_placement_opt.py index 5d3014b..3cf9701 100644 --- a/test/test_process_placement_opt.py +++ b/test/test_process_placement_opt.py @@ -1,3 +1,20 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2017-2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# import unittest import json import yaml |