Skip to content

Commit 2d041b4

Browse files
committed
Added a test case for generate attribution with default template
1 parent 1d934f2 commit 2d041b4

File tree

3 files changed

+82
-4
lines changed

3 files changed

+82
-4
lines changed

about_code_tool/about.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import csv
3333
from datetime import datetime
3434
from email.parser import HeaderParser
35-
from os.path import dirname, join
35+
from os.path import basename, dirname, join, realpath
3636
import errno
3737
import httplib
3838
import logging
@@ -1241,11 +1241,12 @@ def generate_attribution(self, template_path=None, limit_to=None):
12411241
# For some reasons, if I set the template_path = "templates/default.html"
12421242
# in the parameter, the tempalte_path will become 'None' and cause error
12431243
if not template_path:
1244-
template_path = "templates/default.html"
1244+
template_path = join(dirname(realpath(__file__)),
1245+
"templates/default.html")
12451246

12461247
# FIXME: the template dir should be outside the code tree
1247-
template_dir = os.path.dirname(template_path)
1248-
template_file_name = os.path.basename(template_path)
1248+
template_dir = dirname(template_path)
1249+
template_file_name = basename(template_path)
12491250
loader = j2.FileSystemLoader(template_dir)
12501251
jinja_env = j2.Environment(loader=loader)
12511252

about_code_tool/tests/test_about.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,14 @@ def test_generate_attribution_with_custom_template(self):
616616
result = collector.generate_attribution(template)
617617
self.assertEqual(expected, result)
618618

619+
def test_generate_attribution_with_default_template(self):
620+
f = open(join(TESTDATA_DIR, 'attrib/attrib.html'))
621+
expected = f.read()
622+
test_file = join(TESTDATA_DIR, 'attrib/attrib.ABOUT')
623+
collector = about.Collector(test_file)
624+
result = collector.generate_attribution()
625+
self.assertEqual(expected, result)
626+
619627
def test_license_text_extracted_from_license_text_file(self):
620628
expected = '''Tester holds the copyright for test component. Tester relinquishes copyright of
621629
this software and releases the component to Public Domain.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
<body>
13+
<h1>OPEN SOURCE SOFTWARE INFORMATION</h1>
14+
<div>
15+
16+
<p>For instructions on how to obtain a copy of any source code
17+
being made publicly available by Starship Technology related to
18+
software used in this product you may send your request in
19+
writing to:</p>
20+
21+
Starship Technology LLC.<br/>
22+
OSS Management<br/>
23+
7829 Montague Expressway<br/>
24+
Santa Clara, CA 95031<br/>
25+
USA<br/>
26+
27+
<p>The Starship Technology website www.dejacode.com also
28+
contains information regarding Starship Technology's use of open
29+
source. Starship Technology has created the <a href=
30+
"http://www.dejacode.org">www.dejacode.org</a> to
31+
serve as a portal for interaction with the software
32+
community-at-large.</p>
33+
34+
<p>This document contains additional information regarding
35+
licenses, acknowledgments and required copyright notices for
36+
open source packages used in this Starship Technology product.
37+
This Starship Technology product contains the following open
38+
source software components</p>
39+
40+
</div>
41+
42+
<div class="oss-table-of-contents">
43+
44+
<p><a href="#component_0">Apache HTTP Server
45+
46+
2.4.3
47+
48+
</a></p>
49+
50+
</div>
51+
52+
<hr>
53+
54+
55+
<div class="oss-component" id="component_0">
56+
<h3 class="component-name">Apache HTTP Server
57+
2.4.3
58+
</h3>
59+
60+
61+
62+
63+
</div>
64+
65+
<hr>
66+
67+
<h3><a id="End">End</a></h3>
68+
</body>
69+
</html>

0 commit comments

Comments
 (0)