finalsa-common-models 0.0.1__tar.gz → 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {finalsa-common-models-0.0.1/finalsa_common_models.egg-info → finalsa-common-models-0.0.3}/PKG-INFO +1 -1
- finalsa-common-models-0.0.3/finalsa/common/models/__init__.py +15 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa/common/models/models/__init__.py +1 -1
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa/common/models/models/functions.py +15 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa/common/models/models/sqs_response.py +2 -2
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3/finalsa_common_models.egg-info}/PKG-INFO +1 -1
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/tests/test_client.py +33 -3
- finalsa-common-models-0.0.1/finalsa/common/models/__init__.py +0 -13
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/LICENSE.md +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/README.md +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa/common/models/models/sqs_message.py +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa/common/models/py.typed +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa_common_models.egg-info/SOURCES.txt +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa_common_models.egg-info/dependency_links.txt +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa_common_models.egg-info/requires.txt +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa_common_models.egg-info/top_level.txt +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa_common_models.egg-info/zip-safe +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/setup.cfg +0 -0
- {finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/setup.py +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from finalsa.common.models.models import (
|
|
2
|
+
SqsMessage,
|
|
3
|
+
SqsReponse,
|
|
4
|
+
parse_message_attributes,
|
|
5
|
+
to_message_attributes
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
__version__ = "0.0.3"
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"SqsMessage",
|
|
12
|
+
"SqsReponse",
|
|
13
|
+
"parse_message_attributes",
|
|
14
|
+
"to_message_attributes",
|
|
15
|
+
]
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
from typing import Dict
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from decimal import Decimal
|
|
4
|
+
from uuid import UUID
|
|
2
5
|
|
|
3
6
|
|
|
4
7
|
def parse_message_attributes(attributes: Dict) -> Dict:
|
|
@@ -21,6 +24,18 @@ def to_message_attributes(attributes: Dict) -> Dict:
|
|
|
21
24
|
if isinstance(value, str):
|
|
22
25
|
att_dict[key] = {
|
|
23
26
|
'DataType': 'String', 'StringValue': value}
|
|
27
|
+
elif isinstance(value, Decimal):
|
|
28
|
+
att_dict[key] = {
|
|
29
|
+
'DataType': 'Number', 'StringValue': str(value)}
|
|
30
|
+
elif isinstance(value, UUID):
|
|
31
|
+
att_dict[key] = {
|
|
32
|
+
'DataType': 'String', 'StringValue': str(value)}
|
|
33
|
+
elif isinstance(value, datetime):
|
|
34
|
+
att_dict[key] = {
|
|
35
|
+
'DataType': 'String', 'StringValue': value.isoformat()}
|
|
36
|
+
elif isinstance(value, int):
|
|
37
|
+
att_dict[key] = {
|
|
38
|
+
'DataType': 'Number', 'StringValue': str(value)}
|
|
24
39
|
elif isinstance(value, bytes):
|
|
25
40
|
att_dict[key] = {
|
|
26
41
|
'DataType': 'Binary', 'BinaryValue': value}
|
|
@@ -71,7 +71,7 @@ class SqsReponse(BaseModel):
|
|
|
71
71
|
topic=sns_payload['topic'],
|
|
72
72
|
payload=sns_payload['payload'],
|
|
73
73
|
correlation_id=sns_payload['correlation_id'],
|
|
74
|
-
timestamp=
|
|
74
|
+
timestamp=sns_payload['timestamp']
|
|
75
75
|
)
|
|
76
76
|
payload = self.get_payload()
|
|
77
77
|
if 'correlation_id' not in payload:
|
|
@@ -81,7 +81,7 @@ class SqsReponse(BaseModel):
|
|
|
81
81
|
topic=payload['topic'],
|
|
82
82
|
payload=payload['payload'],
|
|
83
83
|
correlation_id=payload['correlation_id'],
|
|
84
|
-
timestamp=
|
|
84
|
+
timestamp=payload['timestamp']
|
|
85
85
|
)
|
|
86
86
|
|
|
87
87
|
@classmethod
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
from finalsa.common.models import (
|
|
2
|
-
SqsMessage, SqsReponse, parse_message_attributes,
|
|
2
|
+
SqsMessage, SqsReponse, parse_message_attributes,
|
|
3
|
+
to_message_attributes, __version__)
|
|
3
4
|
import os
|
|
4
5
|
import sys
|
|
6
|
+
import uuid
|
|
7
|
+
import datetime
|
|
8
|
+
import decimal
|
|
5
9
|
|
|
6
10
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))
|
|
7
11
|
|
|
@@ -77,8 +81,10 @@ def test_sqs_response_from_boto_response():
|
|
|
77
81
|
assert response.body == 'test'
|
|
78
82
|
assert str(response.get_correlation_id()) == '123e4567-e89b-12d3-a456-426614174000'
|
|
79
83
|
assert response.topic == ''
|
|
80
|
-
assert response.message_attributes == {
|
|
81
|
-
|
|
84
|
+
assert response.message_attributes == {
|
|
85
|
+
'correlation_id': "123e4567-e89b-12d3-a456-426614174000"}
|
|
86
|
+
assert response.attributes == {
|
|
87
|
+
'test': 'test', 'correlation_id': '123e4567-e89b-12d3-a456-426614174000'}
|
|
82
88
|
|
|
83
89
|
|
|
84
90
|
def test_sqs_response_no_correlation_id():
|
|
@@ -109,3 +115,27 @@ def test_sqs_message_from_dict():
|
|
|
109
115
|
assert message.topic == message_dict['topic']
|
|
110
116
|
assert message.get_payload() == {'test': 'test'}
|
|
111
117
|
assert message.correlation_id == message_dict['correlation_id']
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_to_message_attributes():
|
|
121
|
+
attributes = {
|
|
122
|
+
'string': 'test',
|
|
123
|
+
'number': 1,
|
|
124
|
+
'binary': b'test',
|
|
125
|
+
'uuid': uuid.uuid4(),
|
|
126
|
+
'datetime': datetime.datetime.now(),
|
|
127
|
+
'decimal': decimal.Decimal('1.0')
|
|
128
|
+
}
|
|
129
|
+
result = to_message_attributes(attributes)
|
|
130
|
+
assert result['string']['DataType'] == 'String'
|
|
131
|
+
assert result['string']['StringValue'] == 'test'
|
|
132
|
+
assert result['number']['DataType'] == 'Number'
|
|
133
|
+
assert result['number']['StringValue'] == '1'
|
|
134
|
+
assert result['binary']['DataType'] == 'Binary'
|
|
135
|
+
assert result['binary']['BinaryValue'] == b'test'
|
|
136
|
+
assert result['uuid']['DataType'] == 'String'
|
|
137
|
+
assert result['uuid']['StringValue'] == str(attributes['uuid'])
|
|
138
|
+
assert result['datetime']['DataType'] == 'String'
|
|
139
|
+
assert result['datetime']['StringValue'] == attributes['datetime'].isoformat()
|
|
140
|
+
assert result['decimal']['DataType'] == 'Number'
|
|
141
|
+
assert result['decimal']['StringValue'] == '1.0'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{finalsa-common-models-0.0.1 → finalsa-common-models-0.0.3}/finalsa_common_models.egg-info/zip-safe
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|