1
1
from django .test import TestCase
2
2
from django .contrib .auth .models import User
3
+ from django .db .utils import IntegrityError
3
4
4
5
from apps .ifc_validation_models .models import ValidationRequest , ValidationTask # TODO: for now needs to be absolute!
5
6
from apps .ifc_validation_models .models import Company , AuthoringTool , Model
@@ -130,14 +131,15 @@ def test_newly_created_tool_and_model_can_be_navigated(self):
130
131
self .assertEqual (all_tools .count (), 1 )
131
132
self .assertEqual (all_tools [0 ].id , tool .id )
132
133
self .assertEqual (tool .company .name , company .name )
133
- self .assertEqual (all_tools . first () .company .name , company .name )
134
+ self .assertEqual (all_tools [ 0 ] .company .name , company .name )
134
135
self .assertEqual (model .produced_by .company .name , company .name )
135
136
self .assertEqual (model .uploaded_by .username , user .username )
136
137
self .assertEqual (user .models .count (), 2 )
137
138
self .assertEqual (user .models .all ()[1 ].file_name , model2 .file_name )
138
139
139
140
def test_find_tool_by_full_name_should_succeed (self ):
140
141
142
+ # arrange
141
143
ValidationModelsTestCase .set_user_context ()
142
144
company1 = Company .objects .create (name = 'Acme Inc.' )
143
145
tool1 = AuthoringTool .objects .create (name = 'Tool ABC' , version = '1.0' , company = company1 )
@@ -147,17 +149,20 @@ def test_find_tool_by_full_name_should_succeed(self):
147
149
tool3 = AuthoringTool .objects .create (name = 'App' , version = None , company = company2 )
148
150
tool4 = AuthoringTool .objects .create (name = 'App' , version = '2024' , company = company2 )
149
151
152
+ # act/assert
150
153
name_to_find = 'Acme Inc. - Tool ABC - 1.0'
151
154
found_tool = AuthoringTool .find_by_full_name (name_to_find )
152
155
self .assertIsNotNone (found_tool )
153
156
self .assertIsInstance (found_tool , AuthoringTool )
154
157
self .assertEqual (found_tool .name , tool1 .name )
158
+ self .assertEqual (found_tool .company .name , tool1 .company .name )
155
159
156
160
name_to_find = 'Acme Inc. - Tool ABC 1.0'
157
161
found_tool = AuthoringTool .find_by_full_name (name_to_find )
158
162
self .assertIsNotNone (found_tool )
159
163
self .assertIsInstance (found_tool , AuthoringTool )
160
164
self .assertEqual (found_tool .name , tool1 .name )
165
+ self .assertEqual (found_tool .company .name , tool1 .company .name )
161
166
162
167
name_to_find = 'PyCAD Limited'
163
168
found_tool = AuthoringTool .find_by_full_name (name_to_find )
@@ -168,49 +173,80 @@ def test_find_tool_by_full_name_should_succeed(self):
168
173
self .assertIsNotNone (found_tool )
169
174
self .assertIsInstance (found_tool , AuthoringTool )
170
175
self .assertEqual (found_tool .name , tool3 .name )
176
+ self .assertEqual (found_tool .company .name , tool3 .company .name )
171
177
172
178
name_to_find = 'PyCAD Limited - App 2024'
173
179
found_tool = AuthoringTool .find_by_full_name (name_to_find )
174
180
self .assertIsNotNone (found_tool )
175
181
self .assertIsInstance (found_tool , AuthoringTool )
176
182
self .assertEqual (found_tool .name , tool4 .name )
183
+ self .assertEqual (found_tool .company .name , tool4 .company .name )
177
184
178
185
name_to_find = 'PyCAD Limited App 2020'
179
186
found_tool = AuthoringTool .find_by_full_name (name_to_find )
180
187
self .assertIsNone (found_tool )
181
188
182
189
def test_find_tool_by_full_name_should_succeed2 (self ):
183
190
191
+ # arrange
184
192
ValidationModelsTestCase .set_user_context ()
185
193
tool1 = AuthoringTool .objects .create (name = 'Test Application' , version = '0.10' )
194
+ tool2 = AuthoringTool .objects .create (name = 'Test Application' , version = '2023-01' )
186
195
187
- name_to_find = 'Test Application 0.10'
188
-
196
+ # act/assert
197
+ name_to_find = 'Test Application - 0.10'
189
198
found_tool = AuthoringTool .find_by_full_name (name_to_find )
190
199
self .assertIsNotNone (found_tool )
191
200
self .assertIsInstance (found_tool , AuthoringTool )
192
201
self .assertEqual (found_tool .name , tool1 .name )
193
-
194
- tool2 = AuthoringTool .objects .create (name = 'Test Application' , version = '2023-01' )
195
-
202
+ self .assertIsNone (found_tool .company )
203
+
196
204
name_to_find = 'Test Application - 2023-01'
197
-
198
205
found_tool = AuthoringTool .find_by_full_name (name_to_find )
199
206
self .assertIsNotNone (found_tool )
200
207
self .assertIsInstance (found_tool , AuthoringTool )
201
208
self .assertEqual (found_tool .name , tool2 .name )
209
+ self .assertIsNone (found_tool .company )
202
210
203
211
def test_find_tool_by_full_name_should_succeed3 (self ):
204
212
213
+ # arrange
205
214
ValidationModelsTestCase .set_user_context ()
206
215
tool1 = AuthoringTool .objects .create (name = 'IfcOpenShell-v0.7.0-6c9e130ca' , version = 'v0.7.0-6c9e130ca' )
207
216
217
+ # act
208
218
name_to_find = 'IfcOpenShell-v0.7.0-6c9e130ca v0.7.0-6c9e130ca'
209
-
210
219
found_tool = AuthoringTool .find_by_full_name (name_to_find )
220
+
221
+ # assert
211
222
self .assertIsNotNone (found_tool )
212
223
self .assertIsInstance (found_tool , AuthoringTool )
213
224
self .assertEqual (found_tool .name , tool1 .name )
225
+ self .assertIsNone (found_tool .company )
226
+
227
+ def test_find_tool_by_full_name_should_return_none (self ):
228
+
229
+ # arrange
230
+ ValidationModelsTestCase .set_user_context ()
231
+ AuthoringTool .objects .create (name = 'Test Application' , version = '0.10' )
232
+
233
+ # act
234
+ name_to_find = 'Test Application 0.12'
235
+ found_tool = AuthoringTool .find_by_full_name (name_to_find )
236
+
237
+ # assert
238
+ self .assertIsNone (found_tool )
239
+
240
+ def test_add_tool_twice_should_fail (self ):
241
+
242
+ # arrange
243
+ ValidationModelsTestCase .set_user_context ()
244
+
245
+ # act/assert
246
+ AuthoringTool .objects .create (name = 'Test Application' , version = '0.10' ) # should succeed
247
+ AuthoringTool .objects .create (name = 'Test Application' , version = '0.11' ) # should succeed
248
+ with self .assertRaises (IntegrityError ):
249
+ AuthoringTool .objects .create (name = 'Test Application' , version = '0.11' ) # should fail
214
250
215
251
def test_model_can_navigate_back_to_request (self ):
216
252
0 commit comments