issue #23 - fixing issues from integration test
Unit test coverage / pytest (push) Failing after 1m9s
Unit test coverage / pytest (push) Failing after 1m9s
This commit is contained in:
@@ -86,13 +86,13 @@ class TestScaleRequestV1:
|
||||
|
||||
def test_scale_request_v1_to_json_different_alert_type(self):
|
||||
"""
|
||||
Test the to_json method with a different ScalingRequestAlert type.
|
||||
Test the to_json method with a different ScalingRequestAlert type_string.
|
||||
"""
|
||||
service_id = "test-service"
|
||||
task_id = "test-task"
|
||||
max_availability = 10
|
||||
current_availability = 5
|
||||
request_type = ScalingRequestAlert.OVERLOAD # Change the alert type
|
||||
request_type = ScalingRequestAlert.OVERLOAD # Change the alert type_string
|
||||
|
||||
scale_request = ScaleRequestV1(
|
||||
service_id,
|
||||
|
||||
@@ -98,7 +98,7 @@ class TestCleverThisServiceAdapter(unittest.IsolatedAsyncioTestCase):
|
||||
def test_get_content_type(self):
|
||||
test_cases = [
|
||||
({"Content-Type": ["application/json"]}, "application/json"),
|
||||
({"content-type": ["text/xml"]}, "text/xml"),
|
||||
({"content-type_string": ["text/xml"]}, "text/xml"),
|
||||
({"CONTENT-TYPE": ["text/plain; charset=utf-8"]}, "text/plain"),
|
||||
({}, "application/json"),
|
||||
({"Other-Header": ["value"]}, "application/json"),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from amqp.adapter.service_message_factory import (
|
||||
ServiceMessageFactory,
|
||||
RS,
|
||||
INVALID_MESSAGE,
|
||||
RS,
|
||||
ServiceMessageFactory,
|
||||
)
|
||||
from amqp.model.model import ServiceMessage
|
||||
from amqp.model.service_message_type import ServiceMessageType
|
||||
@@ -13,17 +13,13 @@ class ServiceMessageTest(TestCase):
|
||||
|
||||
def test_to_string(self):
|
||||
_f: ServiceMessageFactory = ServiceMessageFactory("bumble-bee")
|
||||
message: ServiceMessage = _f.of(
|
||||
ServiceMessageType.ROUTING_DATA, "Duck", "Donald"
|
||||
)
|
||||
message: ServiceMessage = _f.of(ServiceMessageType.ROUTING_DATA, "Duck", "Donald")
|
||||
message_str = _f.to_string(message)
|
||||
self.assertTrue("|type=01|" in message_str)
|
||||
self.assertTrue("|type_string=01|" in message_str)
|
||||
self.assertTrue("|body=Duck" in message_str)
|
||||
message: ServiceMessage = _f.of(
|
||||
ServiceMessageType.ROUTING_DATA_REPLACE, "Duck", "Donald"
|
||||
)
|
||||
message: ServiceMessage = _f.of(ServiceMessageType.ROUTING_DATA_REPLACE, "Duck", "Donald")
|
||||
message_str = _f.to_string(message)
|
||||
self.assertTrue("|type=03|" in message_str)
|
||||
self.assertTrue("|type_string=03|" in message_str)
|
||||
self.assertTrue("|body=Duck" in message_str)
|
||||
self.assertTrue("|replyTo=bumble-bee" in message_str)
|
||||
nullMsg = _f.to_string(None)
|
||||
@@ -57,3 +53,4 @@ class ServiceMessageTest(TestCase):
|
||||
message = _f.of(ServiceMessageType.ROUTING_DATA, "Duck", "Donald")
|
||||
serialized = _f.serialize(message)
|
||||
assert RS + "0" + str(ServiceMessageType.ROUTING_DATA.value)
|
||||
assert len(serialized) > 16
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import unittest
|
||||
|
||||
from amqp.adapter.type_descriptor import TypeDescriptor
|
||||
|
||||
|
||||
class TestTypeDescriptor(unittest.TestCase):
|
||||
def test_annotated_with_json(self):
|
||||
type_str = (
|
||||
"typing.Optional[typing.Annotated[core.base.providers.ingestion.IngestionConfig, Json]]"
|
||||
)
|
||||
td = TypeDescriptor(type_str)
|
||||
|
||||
self.assertEqual(td.type, "core.base.providers.ingestion.IngestionConfig")
|
||||
self.assertTrue(td.is_json)
|
||||
|
||||
def test_annotated_without_json(self):
|
||||
type_str = "typing.Optional[typing.Annotated[str, SomethingElse]]"
|
||||
td = TypeDescriptor(type_str)
|
||||
|
||||
self.assertEqual(td.type, "str")
|
||||
self.assertFalse(td.is_json)
|
||||
|
||||
def test_annotated_multiple_args(self):
|
||||
type_str = "typing.Optional[typing.Annotated[list[int], Json, more_args]]"
|
||||
td = TypeDescriptor(type_str)
|
||||
|
||||
self.assertEqual(td.type, "list[int]")
|
||||
self.assertTrue(td.is_json)
|
||||
|
||||
def test_simple_optional(self):
|
||||
type_str = "typing.Optional[uuid.UUID]"
|
||||
td = TypeDescriptor(type_str)
|
||||
|
||||
self.assertEqual(td.type, "uuid.UUID")
|
||||
self.assertFalse(td.is_json)
|
||||
|
||||
def test_whitespace_variations(self):
|
||||
test_cases = [
|
||||
("typing.Optional[typing.Annotated[ str , Json ]]", "str", True),
|
||||
("typing.Optional[ typing.Annotated[dict,Json]]", "dict", True),
|
||||
("typing.Optional[ int ]", "int", False),
|
||||
]
|
||||
|
||||
for type_str, expected_type, expected_json in test_cases:
|
||||
with self.subTest(type_str=type_str):
|
||||
td = TypeDescriptor(type_str)
|
||||
self.assertEqual(td.type, expected_type)
|
||||
self.assertEqual(td.is_json, expected_json)
|
||||
|
||||
def test_invalid_input(self):
|
||||
test_cases = [
|
||||
"not.a.valid.type_string.string",
|
||||
"typing.Optional[missing_bracket",
|
||||
"typing.Optional[]",
|
||||
"typing.Annotated[without.optional]",
|
||||
]
|
||||
|
||||
for type_str in test_cases:
|
||||
with self.subTest(type_str=type_str):
|
||||
td = TypeDescriptor(type_str)
|
||||
self.assertEqual(td.type, "")
|
||||
self.assertFalse(td.is_json)
|
||||
|
||||
def test_repr(self):
|
||||
type_str = "typing.Optional[typing.Annotated[str, Json]]"
|
||||
td = TypeDescriptor(type_str)
|
||||
|
||||
self.assertEqual(repr(td), "TypeDescriptor(type_string='str', is_json=True)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user