1+ import json
12import textwrap
23from unittest .mock import call
34
@@ -18,14 +19,14 @@ def tg_upgrade_action(action_cls, args_mock, tmp_data_folder, start_cmd_mock, re
1819def tg_upgrade_stdout_side_effect (stdout_mock ):
1920 side_effect = [
2021 # Pre-execute calls
21- [b"This version: 1.0.0 \n " , b"Latest version: 1.1 .0\n " ], # Version check
22+ [b"TestGen 1.0.0\n " ], # Version check
2223 # Execute calls
2324 [], # Down
2425 [], # Pull
2526 [], # Up
2627 [], # Upgrade DB
2728 # Post-execute calls
28- [b"This version: 1.1.0 \n " , b"Latest version: 1.1.0\n " ], # Confirmation version check
29+ [b"TestGen 1.1.0\n " ], # Confirmation version check
2930 [b"[]" ], # Image data collection
3031 ]
3132
@@ -57,9 +58,15 @@ def get_compose_content(*extra_vars):
5758 return template .format (textwrap .indent ("\n " .join (extra_vars ), " " ))
5859
5960
61+ def set_version_check_mock (version_check_mock , latest_version ):
62+ version_check_mock .return_value .code = 200
63+ version_values = { "docker" : {"datakitchen/dataops-testgen" : latest_version } }
64+ version_check_mock .return_value .read .return_value = json .dumps (version_values ).encode ("utf-8" )
65+
66+
6067@pytest .mark .integration
6168def test_tg_upgrade_compose_missing (tg_upgrade_action , args_mock , start_cmd_mock , console_msg_mock ):
62- start_cmd_mock .__exit__ .side_effect = [None , None , None , CommandFailed ]
69+ start_cmd_mock .__exit__ .side_effect = [None , None , CommandFailed ]
6370
6471 with pytest .raises (AbortAction , match = "" ):
6572 tg_upgrade_action ._check_requirements (args_mock )
@@ -68,7 +75,22 @@ def test_tg_upgrade_compose_missing(tg_upgrade_action, args_mock, start_cmd_mock
6875
6976
7077@pytest .mark .integration
71- def test_tg_upgrade (tg_upgrade_action , compose_path , start_cmd_mock , tg_upgrade_stdout_side_effect , args_mock ):
78+ @pytest .mark .parametrize (
79+ "skip_verify, latest_version" ,
80+ ((True , "1.0.0" ), (False , "1.1.0" )),
81+ )
82+ def test_tg_upgrade (
83+ skip_verify ,
84+ latest_version ,
85+ tg_upgrade_action ,
86+ compose_path ,
87+ start_cmd_mock ,
88+ tg_upgrade_stdout_side_effect ,
89+ args_mock ,
90+ version_check_mock ,
91+ ):
92+ args_mock .skip_verify = skip_verify
93+ set_version_check_mock (version_check_mock , latest_version )
7294 compose_path .write_text (get_compose_content ())
7395
7496 tg_upgrade_action .execute (args_mock )
@@ -93,21 +115,16 @@ def test_tg_upgrade(tg_upgrade_action, compose_path, start_cmd_mock, tg_upgrade_
93115
94116
95117@pytest .mark .integration
96- @pytest .mark .parametrize (
97- "skip_verify, latest_version" ,
98- ((True , b"1.0.0" ), (True , b"1.1.0" ), (False , b"1.0.0" )),
99- )
100118def test_tg_upgrade_abort (
101- skip_verify ,
102- latest_version ,
103119 tg_upgrade_action ,
104120 compose_path ,
105121 start_cmd_mock ,
106122 tg_upgrade_stdout_side_effect ,
107123 args_mock ,
124+ version_check_mock ,
108125):
109- args_mock .skip_verify = skip_verify
110- tg_upgrade_stdout_side_effect [ 0 ][ 1 ] = b"Latest version: %b \n " % latest_version
126+ args_mock .skip_verify = False
127+ set_version_check_mock ( version_check_mock , "1.0.0" )
111128 initial_compose_content = get_compose_content ("TG_INSTANCE_ID: test-instance-id" )
112129 compose_path .write_text (initial_compose_content )
113130
@@ -116,7 +133,7 @@ def test_tg_upgrade_abort(
116133
117134 compose_content = compose_path .read_text ()
118135 assert compose_content == initial_compose_content
119- assert start_cmd_mock .call_count == 0 if skip_verify else 1
136+ assert start_cmd_mock .call_count == 1
120137
121138
122139@pytest .mark .integration
@@ -130,8 +147,9 @@ def test_tg_upgrade_enable_analytics(
130147 args_mock ,
131148 console_msg_mock ,
132149 analytics_mock ,
150+ version_check_mock ,
133151):
134- tg_upgrade_stdout_side_effect [ 0 ][ 1 ] = b"Latest version: 1.0.0\n "
152+ set_version_check_mock ( version_check_mock , " 1.0.0" )
135153 compose_path .write_text (get_compose_content ("TG_ANALYTICS: no" if re_enable else "" ))
136154 analytics_mock .get_instance_id .return_value = "test-instance-id"
137155
@@ -153,9 +171,10 @@ def test_tg_upgrade_disable_analytics(
153171 tg_upgrade_stdout_side_effect ,
154172 args_mock ,
155173 console_msg_mock ,
174+ version_check_mock ,
156175):
157176 args_mock .send_analytics_data = False
158- tg_upgrade_stdout_side_effect [ 0 ][ 1 ] = b"Latest version: 1.0.0\n "
177+ set_version_check_mock ( version_check_mock , " 1.0.0" )
159178 compose_path .write_text (
160179 get_compose_content ("TG_INSTANCE_ID: test-instance-id" , "TG_ANALYTICS: yes" if explicitly_enabled else "" )
161180 )
0 commit comments