Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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': { \
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ 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 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from .classes.cloudrequestengine_testbase import CloudRequestEngineTestsBase
from .classes.constants import *
from .classes.endpoint import expected_endpoint


class TestCloudResponse(CloudRequestEngineTestsBase):
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
Loading