Skip to content

Commit 8a25f3b

Browse files
committed
Update tests
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 975801d commit 8a25f3b

File tree

3 files changed

+26
-59
lines changed

3 files changed

+26
-59
lines changed

tests/test_gen.py

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ def test_load_inventory_with_errors(self):
103103
base_dir = get_temp_dir()
104104
errors, abouts = gen.load_inventory(location, base_dir=base_dir)
105105
expected_errors = [
106-
Error(CRITICAL, "Field name: 'confirmed copyright' contains illegal name characters: 0 to 9, a to z, A to Z and _."),
107106
Error(INFO, 'Field resource is a custom field.'),
108107
Error(INFO, 'Field test is a custom field.'),
108+
Error(CRITICAL, "Field name: ['confirmed copyright'] contains illegal name characters: 0 to 9, a to z, A to Z and _. (or empty spaces) and is ignored."),
109109
Error(INFO, 'Field about_resource: Path')
110110
]
111-
# assert [] == errors
111+
112112
for exp, err in zip(expected_errors, errors):
113113
assert exp.severity == err.severity
114114
assert err.message.startswith(exp.message)
@@ -179,7 +179,6 @@ def test_generation_with_no_about_resource(self):
179179
location = get_test_loc('test_gen/inv2.csv')
180180
base_dir = get_temp_dir()
181181
errors, abouts = gen.generate(location, base_dir)
182-
183182
expected = dict([('.', None)])
184183
assert abouts[0].about_resource.value == expected
185184
assert len(errors) == 1
@@ -285,79 +284,47 @@ def test_generate_license_key_with_custom_file_450_no_fetch(self):
285284
expected = (
286285
'''about_resource: test.c
287286
name: test.c
288-
license_expression: public-domain AND custom
287+
license_expression: mit AND custom
289288
licenses:
290289
- file: custom.txt
291290
'''
292291
)
293292
assert expected == result
294293

295-
def test_generate_license_key_with_custom_file_450_with_fetch(self):
296-
location = get_test_loc('test_gen/lic_issue_450/custom_and_valid_lic_key_with_file.csv')
297-
base_dir = get_temp_dir()
298-
299-
errors, abouts = gen.generate(location, base_dir)
300-
301-
lic_dict = {u'public-domain': [u'Public Domain',
302-
u'public-domain.LICENSE',
303-
u'This component is released to the public domain by the author.',
304-
u'https://enterprise.dejacode.com/urn/?urn=urn:dje:license:public-domain',
305-
u''
306-
]}
307-
a = abouts[0]
308-
a.license_key.value.append('public-domain')
309-
a.license_key.value.append('custom')
310-
result = a.dumps(lic_dict)
311-
expected = (
312-
'''about_resource: test.c
313-
name: test.c
314-
license_expression: public-domain AND custom
315-
licenses:
316-
- key: public-domain
317-
name: Public Domain
318-
file: public-domain.LICENSE
319-
url: https://enterprise.dejacode.com/urn/?urn=urn:dje:license:public-domain
320-
spdx_license_key:
321-
- key: custom
322-
name: custom
323-
file: custom.txt
324-
'''
325-
)
326-
assert expected == result
327294

328295
def test_generate_license_key_with_custom_file_450_with_fetch_with_order(self):
329296
location = get_test_loc('test_gen/lic_issue_450/custom_and_valid_lic_key_with_file.csv')
330297
base_dir = get_temp_dir()
331298

332299
errors, abouts = gen.generate(location, base_dir)
333300

334-
lic_dict = {u'public-domain': [u'Public Domain',
335-
u'public-domain.LICENSE',
336-
u'This component is released to the public domain by the author.',
337-
u'https://enterprise.dejacode.com/urn/?urn=urn:dje:license:public-domain',
338-
u''
301+
lic_dict = {u'mit': [u'MIT License',
302+
u'mit.LICENSE',
303+
u'This component is released under MIT License.',
304+
u'https://enterprise.dejacode.com/urn/?urn=urn:dje:license:mit',
305+
u'mit'
339306
]}
340307
# The first row from the test file
341308
a = abouts[0]
342-
a.license_key.value.append('public-domain')
309+
a.license_key.value.append('mit')
343310
a.license_key.value.append('custom')
344311
result1 = a.dumps(lic_dict)
345312
# The second row from the test file
346313
b = abouts[1]
347314
b.license_key.value.append('custom')
348-
b.license_key.value.append('public-domain')
315+
b.license_key.value.append('mit')
349316
result2 = b.dumps(lic_dict)
350317

351318
expected1 = (
352319
'''about_resource: test.c
353320
name: test.c
354-
license_expression: public-domain AND custom
321+
license_expression: mit AND custom
355322
licenses:
356-
- key: public-domain
357-
name: Public Domain
358-
file: public-domain.LICENSE
359-
url: https://enterprise.dejacode.com/urn/?urn=urn:dje:license:public-domain
360-
spdx_license_key:
323+
- key: mit
324+
name: MIT License
325+
file: mit.LICENSE
326+
url: https://enterprise.dejacode.com/urn/?urn=urn:dje:license:mit
327+
spdx_license_key: mit
361328
- key: custom
362329
name: custom
363330
file: custom.txt
@@ -367,16 +334,16 @@ def test_generate_license_key_with_custom_file_450_with_fetch_with_order(self):
367334
expected2 = (
368335
'''about_resource: test.h
369336
name: test.h
370-
license_expression: custom AND public-domain
337+
license_expression: custom AND mit
371338
licenses:
372339
- key: custom
373340
name: custom
374341
file: custom.txt
375-
- key: public-domain
376-
name: Public Domain
377-
file: public-domain.LICENSE
378-
url: https://enterprise.dejacode.com/urn/?urn=urn:dje:license:public-domain
379-
spdx_license_key:
342+
- key: mit
343+
name: MIT License
344+
file: mit.LICENSE
345+
url: https://enterprise.dejacode.com/urn/?urn=urn:dje:license:mit
346+
spdx_license_key: mit
380347
'''
381348
)
382349
assert expected1 == result1

tests/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def test_About_rejects_non_ascii_names_and_accepts_unicode_values(self):
581581
test_file = get_test_loc('test_model/parse/non_ascii_field_name_value.about')
582582
a = model.About(test_file)
583583
expected = [
584-
Error(CRITICAL, "Field name: 'mat\xedas' contains illegal name characters: 0 to 9, a to z, A to Z and _. (or empty spaces) and is ignored.")
584+
Error(CRITICAL, "Field name: ['mat\xedas'] contains illegal name characters: 0 to 9, a to z, A to Z and _. (or empty spaces) and is ignored.")
585585
]
586586
assert expected == a.errors
587587

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
about_resource,name,license_expression,license_file
2-
test.c,test.c,public-domain AND custom,custom.txt
3-
test.h,test.h,custom AND public-domain,custom.txt
1+
about_resource,name,license_expression,license_file
2+
test.c,test.c,mit AND custom,custom.txt
3+
test.h,test.h,custom AND mit,custom.txt

0 commit comments

Comments
 (0)