20
20
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
# SOFTWARE.
23
+ #
24
+
23
25
from datetime import datetime , timezone
24
26
25
27
import pytest
28
30
29
31
@pytest .fixture
30
32
def conversation_export ():
31
- return ConversationExport (
32
- start_date = datetime (year = 2021 , month = 7 , day = 1 , hour = 12 , tzinfo = timezone .utc ), batch_size = 1 , logger = None
33
- )
33
+ return ConversationExport (start_date = datetime (year = 2021 , month = 7 , day = 1 , hour = 12 , tzinfo = timezone .utc ), batch_size = 1 , logger = None )
34
34
35
35
36
36
def test_validate_ms_timestamp_with_valid_input ():
@@ -49,28 +49,14 @@ def test_validate_ms_timestamp_with_invalid_input_length():
49
49
50
50
def test_ms_timestamp_to_datetime ():
51
51
assert ConversationExport .ms_timestamp_to_datetime (1625312980123 ) == datetime (
52
- year = 2021 ,
53
- month = 7 ,
54
- day = 3 ,
55
- hour = 11 ,
56
- minute = 49 ,
57
- second = 40 ,
58
- microsecond = 123000 ,
59
- tzinfo = timezone .utc
52
+ year = 2021 , month = 7 , day = 3 , hour = 11 , minute = 49 , second = 40 , microsecond = 123000 , tzinfo = timezone .utc
60
53
)
61
54
62
55
63
56
def test_datetime_to_ms_timestamp ():
64
57
assert (
65
- ConversationExport .datetime_to_ms_timestamp (datetime (
66
- year = 2021 ,
67
- month = 7 ,
68
- day = 3 ,
69
- hour = 11 ,
70
- minute = 49 ,
71
- second = 40 ,
72
- microsecond = 123000 ,
73
- tzinfo = timezone .utc )
58
+ ConversationExport .datetime_to_ms_timestamp (
59
+ datetime (year = 2021 , month = 7 , day = 3 , hour = 11 , minute = 49 , second = 40 , microsecond = 123000 , tzinfo = timezone .utc )
74
60
)
75
61
== 1625312980123
76
62
)
@@ -83,14 +69,8 @@ def test_add_days_to_ms_timestamp():
83
69
def test_stream_slices_without_state (conversation_export ):
84
70
conversation_export .end_timestamp = 1625270400001 # 2021-07-03 00:00:00 + 1 ms
85
71
expected_slices = [
86
- {
87
- 'updated_after' : 1625140800000 , # 2021-07-01 12:00:00
88
- 'updated_before' : 1625227200000 # 2021-07-02 12:00:00
89
- },
90
- {
91
- 'updated_after' : 1625227200000 ,
92
- 'updated_before' : 1625270400001
93
- }
72
+ {"updated_after" : 1625140800000 , "updated_before" : 1625227200000 }, # 2021-07-01 12:00:00 # 2021-07-02 12:00:00
73
+ {"updated_after" : 1625227200000 , "updated_before" : 1625270400001 },
94
74
]
95
75
actual_slices = conversation_export .stream_slices ()
96
76
assert actual_slices == expected_slices
@@ -101,12 +81,7 @@ def test_stream_slices_without_state_large_batch():
101
81
start_date = datetime (year = 2021 , month = 7 , day = 1 , hour = 12 , tzinfo = timezone .utc ), batch_size = 31 , logger = None
102
82
)
103
83
conversation_export .end_timestamp = 1625270400001 # 2021-07-03 00:00:00 + 1 ms
104
- expected_slices = [
105
- {
106
- 'updated_after' : 1625140800000 , # 2021-07-01 12:00:00
107
- 'updated_before' : 1625270400001
108
- }
109
- ]
84
+ expected_slices = [{"updated_after" : 1625140800000 , "updated_before" : 1625270400001 }] # 2021-07-01 12:00:00
110
85
actual_slices = conversation_export .stream_slices ()
111
86
assert actual_slices == expected_slices
112
87
@@ -123,26 +98,18 @@ def test_stream_slices_with_start_timestamp_larger_than_state():
123
98
Test that if start_timestamp is larger than state, then start at start_timestamp.
124
99
"""
125
100
conversation_export = ConversationExport (
126
- start_date = datetime (year = 2021 , month = 12 , day = 1 , tzinfo = timezone .utc ), batch_size = 31 ,
127
- logger = None
101
+ start_date = datetime (year = 2021 , month = 12 , day = 1 , tzinfo = timezone .utc ), batch_size = 31 , logger = None
128
102
)
129
103
conversation_export .end_timestamp = 1638360000001 # 2021-12-01 12:00:00 + 1 ms
130
- expected_slices = [
131
- {
132
- 'updated_after' : 1638316800000 , # 2021-07-01 12:00:00
133
- 'updated_before' : 1638360000001
134
- }
135
- ]
136
- actual_slices = conversation_export .stream_slices (
137
- stream_state = {'updated_at' : 1625220000000 } # # 2021-07-02 12:00:00
138
- )
104
+ expected_slices = [{"updated_after" : 1638316800000 , "updated_before" : 1638360000001 }] # 2021-07-01 12:00:00
105
+ actual_slices = conversation_export .stream_slices (stream_state = {"updated_at" : 1625220000000 }) # # 2021-07-02 12:00:00
139
106
assert actual_slices == expected_slices
140
107
141
108
142
109
def test_get_updated_state_without_state (conversation_export ):
143
- assert conversation_export .get_updated_state (
144
- current_stream_state = None , latest_record = { ' updated_at' : 1625263200000 }
145
- ) == { 'updated_at' : 1625140800000 }
110
+ assert conversation_export .get_updated_state (current_stream_state = None , latest_record = { "updated_at" : 1625263200000 }) == {
111
+ " updated_at" : 1625140800000
112
+ }
146
113
147
114
148
115
def test_get_updated_state_with_bigger_state (conversation_export ):
0 commit comments