8
8
from qtpy .QtWidgets import QApplication
9
9
from shiver .shiver import Shiver
10
10
from shiver .configuration import Configuration , get_data
11
+ from shiver .version import __version__ as current_version
11
12
12
13
13
14
def test_config_path_default ():
@@ -47,29 +48,29 @@ def test_config_path_does_not_exist(monkeypatch, tmp_path):
47
48
48
49
49
50
@pytest .mark .parametrize (
50
- "user_conf_file " ,
51
+ "user_conf_file_with_version " ,
51
52
[
52
53
"""
53
54
[generate_tab.oncat]
54
55
#url to oncat portal
55
56
oncat_url = https://oncat.ornl.gov
56
57
#client id for on cat; it is unique for Shiver
57
- client_id = 99025bb3-ce06-4f4b-bcf2-36ebf925cd1d
58
+ client_id = 46c478f0-a472-4551-9264-a937626d5fc2
58
59
59
60
"""
60
61
],
61
62
indirect = True ,
62
63
)
63
- def test_field_validate_fields_exist (monkeypatch , user_conf_file ):
64
+ def test_field_validate_fields_exist (monkeypatch , user_conf_file_with_version ):
64
65
"""Test configuration validate all fields exist with the same values as templates
65
66
Note: update the parameters if the fields increase"""
66
67
# read the custom configuration file
67
- monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file )
68
+ monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file_with_version )
68
69
user_config = Configuration ()
69
70
70
- assert user_config .config_file_path .endswith (user_conf_file ) is True
71
+ assert user_config .config_file_path .endswith (user_conf_file_with_version ) is True
71
72
# check if the file exists
72
- assert os .path .exists (user_conf_file )
73
+ assert os .path .exists (user_conf_file_with_version )
73
74
74
75
# check all fields are the same as the configuration template file
75
76
project_directory = Path (__file__ ).resolve ().parent .parent .parent
@@ -79,11 +80,14 @@ def test_field_validate_fields_exist(monkeypatch, user_conf_file):
79
80
# comments should be copied too
80
81
for section in user_config .config .sections ():
81
82
for field in user_config .config [section ]:
82
- assert user_config .config [section ][field ] == template_config [section ][field ]
83
+ if field != "version" :
84
+ assert user_config .config [section ][field ] == template_config [section ][field ]
85
+ else :
86
+ assert user_config .config [section ][field ] == current_version
83
87
84
88
85
89
@pytest .mark .parametrize (
86
- "user_conf_file " ,
90
+ "user_conf_file_with_version " ,
87
91
[
88
92
"""
89
93
[generate_tab.oncat]
@@ -94,36 +98,40 @@ def test_field_validate_fields_exist(monkeypatch, user_conf_file):
94
98
],
95
99
indirect = True ,
96
100
)
97
- def test_field_validate_fields_same (monkeypatch , user_conf_file ):
98
- """Test configuration validate all fields exist with their values; different from the template"""
101
+ def test_field_validate_fields_same (monkeypatch , user_conf_file_with_version ):
102
+ """Test configuration validate all fields exist with their values; different from the template,
103
+ provided the version is the same"""
99
104
100
105
# read the custom configuration file
101
- monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file )
106
+ monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file_with_version )
102
107
user_config = Configuration ()
103
108
104
109
# check if the file exists
105
- assert os .path .exists (user_conf_file )
106
- assert user_config .config_file_path == user_conf_file
110
+ assert os .path .exists (user_conf_file_with_version )
111
+ assert user_config .config_file_path == user_conf_file_with_version
107
112
108
113
# check all field values have the same values as the user configuration file
109
114
assert get_data ("generate_tab.oncat" , "oncat_url" ) == "test_url"
110
115
assert get_data ("generate_tab.oncat" , "client_id" ) == "0000-0000"
111
116
# cast to bool
112
117
assert get_data ("generate_tab.oncat" , "use_notes" ) is True
118
+ assert get_data ("software.info" , "version" ) == current_version
113
119
114
120
115
121
@pytest .mark .parametrize (
116
122
"user_conf_file" ,
117
123
[
118
124
"""
119
125
[generate_tab.oncat]
126
+ oncat_url = test_url
120
127
client_id = 0000-0000
128
+ use_notes = True
121
129
"""
122
130
],
123
131
indirect = True ,
124
132
)
125
- def test_field_validate_fields_missing (monkeypatch , user_conf_file ):
126
- """Test configuration validate missing fields added from the template """
133
+ def test_field_validate_fields_update_different_version (monkeypatch , user_conf_file ):
134
+ """Test configuration update all fields, provided the version is not the same """
127
135
128
136
# read the custom configuration file
129
137
monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file )
@@ -133,6 +141,34 @@ def test_field_validate_fields_missing(monkeypatch, user_conf_file):
133
141
assert os .path .exists (user_conf_file )
134
142
assert user_config .config_file_path == user_conf_file
135
143
144
+ # check all field values have the same values as the user configuration file
145
+ assert get_data ("generate_tab.oncat" , "oncat_url" ) != "test_url"
146
+ assert get_data ("generate_tab.oncat" , "client_id" ) != "0000-0000"
147
+ # version is included with the current version
148
+ assert get_data ("software.info" , "version" ) == current_version
149
+
150
+
151
+ @pytest .mark .parametrize (
152
+ "user_conf_file_with_version" ,
153
+ [
154
+ """
155
+ [generate_tab.oncat]
156
+ client_id = 0000-0000
157
+ """
158
+ ],
159
+ indirect = True ,
160
+ )
161
+ def test_field_validate_fields_missing (monkeypatch , user_conf_file_with_version ):
162
+ """Test configuration validate missing fields added from the template"""
163
+
164
+ # read the custom configuration file
165
+ monkeypatch .setattr ("shiver.configuration.CONFIG_PATH_FILE" , user_conf_file_with_version )
166
+ user_config = Configuration ()
167
+
168
+ # check if the file exists
169
+ assert os .path .exists (user_conf_file_with_version )
170
+ assert user_config .config_file_path == user_conf_file_with_version
171
+
136
172
# check all field values have the same values as the user configuration file
137
173
assert get_data ("generate_tab.oncat" , "oncat_url" ) == "https://oncat.ornl.gov"
138
174
assert get_data ("generate_tab.oncat" , "client_id" ) == "0000-0000"
@@ -151,7 +187,7 @@ def test_get_data_valid(monkeypatch, user_conf_file):
151
187
assert len (get_data ("generate_tab.oncat" , "" )) == 3
152
188
# fields
153
189
assert get_data ("generate_tab.oncat" , "oncat_url" ) == "https://oncat.ornl.gov"
154
- assert get_data ("generate_tab.oncat" , "client_id" ) == "99025bb3-ce06-4f4b-bcf2-36ebf925cd1d "
190
+ assert get_data ("generate_tab.oncat" , "client_id" ) == "46c478f0-a472-4551-9264-a937626d5fc2 "
155
191
assert get_data ("generate_tab.oncat" , "use_notes" ) is False
156
192
157
193
assert config .is_valid ()
0 commit comments