From 1dd71ac68e25445e64d51e73185da145f5226eb2 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 23 Nov 2026 08:51:37 +0000 Subject: [PATCH 1/2] TEST: Expect the cloud address the endpoint order gives The cloud request engine takes its address from the cloud_endpoint setting first, then the _51DEGREES_CLOUD_ENDPOINT environment variable, then https://cloud.51degrees.com/api/v4/ when both are blank. Four tests gave no address but expected the default, so they failed whenever the variable pointed the suite at another cloud service, as it does in CI. Add tests/classes/endpoint.py with expected_endpoint(), which works out the address the engine uses when no setting is given, and use it in test_cloudresponse.py and test_credentials.py. The two error messages in tests/classes/constants.py now take the address. Add a test that an empty variable falls back to the default, next to the existing order tests. --- .../tests/classes/constants.py | 20 ++++++-- .../tests/classes/endpoint.py | 47 +++++++++++++++++++ .../tests/test_cloudrequestengine.py | 13 +++++ .../tests/test_cloudresponse.py | 9 +++- .../tests/test_credentials.py | 5 +- 5 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 pipeline/fiftyone_pipeline_cloudrequestengine/tests/classes/endpoint.py diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/classes/constants.py b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/classes/constants.py index 6ac49ddd..2624ed38 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/classes/constants.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/classes/constants.py @@ -36,11 +36,25 @@ class Constants(): invalidKeyMessageComplete = "Error returned from 51Degrees cloud service: '" + invalidKeyMessage + "'" noDataKey = "nodatakey" noDataKeyResponse = {} - noDataKeyMessageComplete = "Error returned from 51Degrees cloud service: 'No data in response " + \ - "from cloud service at https://cloud.51degrees.com/api/v4/accessibleProperties?resource=nodatakey'" + + @staticmethod + def noDataKeyMessageComplete(endpoint): + """The error for the no data key from the service at endpoint.""" + return "Error returned from 51Degrees cloud service: 'No data in " + \ + "response from cloud service at " + endpoint + \ + "accessibleProperties?resource=nodatakey'" + noErrorNoSuccessKey = "noErrorNoSuccessKey" noErrorNoSuccessResponse = {'device': {'value': 'abc'}} - noErrorNoSuccessMessage= "Error returned from 51Degrees cloud service: 'Cloud service at 'https://cloud.51degrees.com/api/v4/' returned status code '400' with content {'device': {'value': 'abc'}}'" + + @staticmethod + def noErrorNoSuccessMessage(endpoint): + """The error for the no error no success key from the service at + endpoint.""" + return "Error returned from 51Degrees cloud service: 'Cloud " + \ + "service at '" + endpoint + "' returned status code '400' " + \ + "with content {'device': {'value': 'abc'}}'" + accessibleSubPropertiesResponse = \ { \ 'Products': { \ diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/classes/endpoint.py b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/classes/endpoint.py new file mode 100644 index 00000000..86d7302d --- /dev/null +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/classes/endpoint.py @@ -0,0 +1,47 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +import os + +from fiftyone_pipeline_cloudrequestengine.constants import Constants + + +def expected_endpoint(): + """! + The address a cloud request engine uses when it is given no + cloud_endpoint setting. That is the _51DEGREES_CLOUD_ENDPOINT + environment variable when it is set and not empty, and the default + address otherwise, ending with a slash. + + Tests that give no address expect this value, so they pass both with + the variable unset and when the variable points the suite at another + cloud service. + + @rtype: string + @return: the address the engine is expected to use + """ + + endpoint = os.environ.get(Constants.CLOUD_ENDPOINT) or \ + Constants.BASE_URL_DEFAULT + if not endpoint.endswith("/"): + endpoint += "/" + return endpoint diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudrequestengine.py b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudrequestengine.py index 6fe7b2a5..c6d9907d 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudrequestengine.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudrequestengine.py @@ -106,6 +106,19 @@ def testConfigEndPoint_DefaultSetting(self): }) self.assertEqual(Constants.BASE_URL_DEFAULT, cloud_request_engine.baseURL) + def testConfigEndPoint_BlankEnvironmentVariable(self): + """! + Check that an empty environment variable is treated as not set, + so the default value is used + """ + + os.environ[Constants.CLOUD_ENDPOINT] = "" + cloud_request_engine = CloudRequestEngine({ + "resource_key": TestCloudRequestEngine.testResourceKey, + "http_client": self.mock_http() + }) + self.assertEqual(Constants.BASE_URL_DEFAULT, cloud_request_engine.baseURL) + def testOneConstantNamesAnEnvironmentVariable(self): """! Check that the only constant holding the name of an environment diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudresponse.py b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudresponse.py index 7281fba9..3435f07c 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudresponse.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudresponse.py @@ -29,6 +29,7 @@ from .classes.cloudrequestengine_testbase import CloudRequestEngineTestsBase from .classes.constants import * +from .classes.endpoint import expected_endpoint class TestCloudResponse(CloudRequestEngineTestsBase): @@ -123,7 +124,9 @@ def test_validate_error_handling_nodata(self): "http_client": self.http_client, }) - self.assertEqual(Constants.noDataKeyMessageComplete, context.exception.message) + self.assertEqual( + Constants.noDataKeyMessageComplete(expected_endpoint()), + context.exception.message) def test_validate_error_handling_noerror_nosuccess(self): """ @@ -137,4 +140,6 @@ def test_validate_error_handling_noerror_nosuccess(self): "http_client": self.http_client, }) - self.assertEqual(Constants.noErrorNoSuccessMessage, context.exception.message) + self.assertEqual( + Constants.noErrorNoSuccessMessage(expected_endpoint()), + context.exception.message) diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_credentials.py b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_credentials.py index 72b5a11c..f318bde2 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_credentials.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_credentials.py @@ -30,6 +30,7 @@ from .classes.accepteverykeyelement import AcceptEveryKeyElement from .classes.cloudrequestengine_testbase import CloudRequestEngineTestsBase +from .classes.endpoint import expected_endpoint RESOURCE_KEY = "resource_key" LICENSE_KEY = "a-licence-key" @@ -135,7 +136,7 @@ def test_licence_key_with_properties_is_accepted(self): request_type, url, content = self.data_request(requests) self.assertEqual("POST", request_type) - self.assertEqual(Constants.BASE_URL_DEFAULT + "json", url) + self.assertEqual(expected_endpoint() + "json", url) self.assertNotIn(Constants.RESOURCE_PARAMETER, content) self.assertEqual(LICENSE_KEY, content[Constants.LICENSE_PARAMETER]) self.assertEqual( @@ -166,7 +167,7 @@ def test_licence_key_discovers_properties_with_the_key_in_the_body(self): request_type, url, content = properties_requests[0] self.assertEqual("POST", request_type) self.assertEqual( - Constants.BASE_URL_DEFAULT + "accessibleProperties", url) + expected_endpoint() + "accessibleProperties", url) self.assertEqual({Constants.LICENSE_PARAMETER: LICENSE_KEY}, content) def test_licence_key_without_properties_is_refused(self): From a869226d8818c11128369f43fbf4def402e0bb99 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 23 Nov 2026 09:03:57 +0000 Subject: [PATCH 2/2] TEST: Check a cloud address without a trailing slash gets one Add a test that sets _51DEGREES_CLOUD_ENDPOINT to an address with no trailing slash and expects the engine to use it with one added, as tests/classes/endpoint.py assumes. --- .../tests/test_cloudrequestengine.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudrequestengine.py b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudrequestengine.py index c6d9907d..aa2c2200 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudrequestengine.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudrequestengine.py @@ -119,6 +119,19 @@ def testConfigEndPoint_BlankEnvironmentVariable(self): }) self.assertEqual(Constants.BASE_URL_DEFAULT, cloud_request_engine.baseURL) + def testConfigEndPoint_EnvironmentVariableWithoutSlash(self): + """! + Check that an environment variable without a trailing slash is + used with one added + """ + + os.environ[Constants.CLOUD_ENDPOINT] = \ + TestCloudRequestEngine.testEnvVarEndPoint.rstrip("/") + cloud_request_engine = self.new_engine() + self.assertEqual( + TestCloudRequestEngine.testEnvVarEndPoint, + cloud_request_engine.baseURL) + def testOneConstantNamesAnEnvironmentVariable(self): """! Check that the only constant holding the name of an environment