Skip to content

Commit d17f8ab

Browse files
ThomasThomas
authored andcommitted
Fixed #406 - License key and name are not in sync
* The problem was the about.license_key was changed after parsed the license expression. * Add test to make sure the license key and license name are in sync
1 parent 289dc8c commit d17f8ab

File tree

7 files changed

+82
-4
lines changed

7 files changed

+82
-4
lines changed

src/attributecode/attrib.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ def generate_and_save(abouts, output_location, template_loc=None, variables=None
185185
msg = (u"The following character(s) cannot be in the license_expression: " +
186186
str(special_char_in_expression))
187187
errors.append(Error(ERROR, msg))
188-
else:
189-
about.license_key.value = lic_list
190188

191189
rendering_error, rendered = generate_from_file(
192190
abouts,

tests/test_attrib.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf8 -*-
33

44
# ============================================================================
5-
# Copyright (c) 2014-2017 nexB Inc. http://www.nexb.com/ - All rights reserved.
5+
# Copyright (c) 2014-2019 nexB Inc. http://www.nexb.com/ - All rights reserved.
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
@@ -23,11 +23,11 @@
2323
import unittest
2424

2525
from testing_utils import get_test_loc
26+
from testing_utils import get_temp_file
2627

2728
from attributecode import attrib
2829
from attributecode import model
2930

30-
3131
class TemplateTest(unittest.TestCase):
3232

3333
def test_check_template_simple_valid_returns_None(self):
@@ -109,6 +109,18 @@ def test_generate_with_default_template(self):
109109
expected = remove_timestamp(expected)
110110
assert expected == result
111111

112+
def test_lic_key_name_sync(self):
113+
test_file = get_test_loc('test_attrib/gen_license_key_name_check/test.ABOUT')
114+
expected = get_test_loc('test_attrib/gen_license_key_name_check/expected/expected.html')
115+
template_loc = get_test_loc('test_attrib/gen_license_key_name_check/custom.template')
116+
output_file = get_temp_file()
117+
118+
errors, abouts = model.collect_inventory(test_file)
119+
attrib.generate_and_save(abouts, output_file, template_loc)
120+
121+
f1 = open(output_file, "r").read()
122+
f2 = open(expected,"r").read()
123+
assert f1 == f2
112124

113125
def remove_timestamp(html_text):
114126
"""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is Apache
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is LGPL
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<style type="text/css">
5+
div.additional-license-text-list {display:block}
6+
body {font-family: Helvetica, Arial, sans-serif;}
7+
pre {white-space: pre-wrap;}
8+
</style>
9+
<title>Open Source Software Information</title>
10+
</head>
11+
12+
13+
{% for about_object in abouts %}
14+
<div class="oss-component" id="component_{{ loop.index0 }}">
15+
{% for i in range(about_object.license_file.value|length) %}
16+
<h2>{{ about_object.license_key.value[i] | e}}</h2>
17+
<pre>{{ about_object.license_file.value.values()[i] | e}}</pre>
18+
{% endfor %}
19+
20+
</div>
21+
{% endfor %}
22+
23+
<hr/>
24+
25+
</body>
26+
</html>
27+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<style type="text/css">
5+
div.additional-license-text-list {display:block}
6+
body {font-family: Helvetica, Arial, sans-serif;}
7+
pre {white-space: pre-wrap;}
8+
</style>
9+
<title>Open Source Software Information</title>
10+
</head>
11+
12+
13+
14+
<div class="oss-component" id="component_0">
15+
16+
<h2>Apache-2.0</h2>
17+
<pre>This is Apache</pre>
18+
19+
<h2>LGPL-3.0-or-later</h2>
20+
<pre>This is LGPL</pre>
21+
22+
23+
</div>
24+
25+
26+
<hr/>
27+
28+
</body>
29+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
about_resource: .
2+
name: test
3+
license_expression: LGPL-3.0-or-later OR Apache-2.0
4+
licenses:
5+
- key: Apache-2.0
6+
name: Apache License 2.0
7+
file: LICENSES/Apache-2.0.txt
8+
- key: LGPL-3.0-or-later
9+
name: LGPL
10+
file: LICENSES/LGPL-3.0.txt

0 commit comments

Comments
 (0)