Skip to content

Commit a976008

Browse files
committed
#241 Improved Nuget model with correct owners and authors
1 parent ab44604 commit a976008

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

src/packagedcode/nuget.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,24 @@ def parse(location):
7777
if not nuspec:
7878
return
7979
asserted_license = models.AssertedLicense(url=nuspec.get('licenseUrl'))
80+
81+
authors = [models.Party(name=nuspec.get('authors'))] if nuspec.get('authors') else []
82+
owners = [models.Party(name=nuspec.get('owners'))] if nuspec.get('owners') else []
83+
8084
package = models.NugetPackage(
81-
id=nuspec.get('id'),
82-
asserted_licenses=[asserted_license],
83-
copyrights=[nuspec.get('copyright')],
84-
version=nuspec.get('version'),
85-
homepage_url=nuspec.get('projectUrl'),
85+
location=location,
86+
8687
name=nuspec.get('id'),
87-
description=nuspec.get('description'),
88-
# FIXME: this mapping is not correct: owners and authors should be Party objects
89-
authors=nuspec.get('authors'),
90-
owners=nuspec.get('owners'),
88+
version=nuspec.get('version'),
89+
9190
summary=nuspec.get('title'),
92-
location=location,
91+
description=nuspec.get('description'),
92+
homepage_url=nuspec.get('projectUrl'),
93+
94+
authors=authors,
95+
owners=owners,
96+
97+
asserted_licenses=[asserted_license],
98+
copyrights=[nuspec.get('copyright')],
9399
)
94100
return package

tests/packagedcode/test_nuget.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@
2929
from commoncode.testcase import FileBasedTesting
3030

3131
from packagedcode import nuget
32+
from collections import OrderedDict
3233

3334

3435
class TestNuget(FileBasedTesting):
3536
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')
3637

3738
def test_parse_nuspec_bootstrap(self):
3839
test_file = self.get_test_loc('nuget/bootstrap.nuspec')
39-
output_obtained = nuget.parse_nuspec(test_file)
40-
expected_output = {
40+
result = nuget.parse_nuspec(test_file)
41+
expected = {
4142
'authors': u'Twitter, Inc.',
4243
'copyright': u'Copyright 2015',
4344
'description': u'The most popular front-end framework for developing responsive, mobile first projects on the web.',
@@ -51,7 +52,7 @@ def test_parse_nuspec_bootstrap(self):
5152
'title': u'Bootstrap CSS',
5253
'version': u'4.0.0-alpha'
5354
}
54-
assert expected_output == output_obtained
55+
assert expected == result
5556

5657
def test_parse_nuspec_entity_framework(self):
5758
test_file = self.get_test_loc('nuget/EntityFramework.nuspec')
@@ -106,11 +107,34 @@ def test_parse_nuspec_microsoft_asp_mvc(self):
106107
def test_parse_creates_package_from_nuspec(self):
107108
test_file = self.get_test_loc('nuget/Microsoft.Net.Http.nuspec')
108109
package = nuget.parse(test_file)
109-
assert 'Microsoft.Net.Http' == package.name
110-
assert 'Microsoft.Net.Http' == package.id
111-
assert [u'Copyright \xa9 Microsoft Corporation'] == package.copyrights
112-
assert '2.2.29' == package.version
113-
assert 'http://go.microsoft.com/fwlink/?LinkID=280055' == package.homepage_url
114-
assert 'Microsoft HTTP Client Libraries' == package.summary
115-
assert 'Microsoft' == package.authors
116-
assert 'Microsoft' == package.owners
110+
expected = OrderedDict([
111+
('type', u'Nuget'),
112+
('name', u'Microsoft.Net.Http'),
113+
('version', u'2.2.29'),
114+
('primary_language', None),
115+
('packaging', u'archive'),
116+
('summary', u'Microsoft HTTP Client Libraries'),
117+
('description', u'This package includes HttpClient for sending requests over HTTP, as well as HttpRequestMessage and HttpResponseMessage for '
118+
u'processing HTTP messages.\n\nThis package is not supported in Visual Studio 2010, and is only required for projects targeting'
119+
u' .NET Framework 4.5, Windows 8, or Windows Phone 8.1 when consuming a library that uses this package.\n\nSupported Platforms:'
120+
u'\n- .NET Framework 4\n- Windows 8\n- Windows Phone 8.1\n- Windows Phone Silverlight 7.5\n- Silverlight 4\n- Portable Class Libraries'),
121+
('payload_type', None),
122+
('authors', [OrderedDict([('type', None), ('name', u'Microsoft'), ('email', None), ('url', None)])]),
123+
('maintainers', []), ('contributors', []),
124+
('owners', [OrderedDict([('type', None), ('name', u'Microsoft'), ('email', None), ('url', None)])]),
125+
('packagers', []), ('distributors', []), ('vendors', []),
126+
('keywords', []), ('keywords_doc_url', None),
127+
('metafile_locations', []),
128+
('metafile_urls', []),
129+
('homepage_url', u'http://go.microsoft.com/fwlink/?LinkID=280055'),
130+
('notes', None), ('download_urls', []),
131+
('download_sha1', None), ('download_sha256', None), ('download_md5', None),
132+
('bug_tracking_url', None), ('support_contacts', []), ('code_view_url', None),
133+
('vcs_tool', None), ('vcs_repository', None), ('vcs_revision', None),
134+
('copyright_top_level', None), ('copyrights', [u'Copyright \xa9 Microsoft Corporation']),
135+
('asserted_licenses', [OrderedDict([('license', None), ('url', u'http://go.microsoft.com/fwlink/?LinkId=329770'), ('text', None), ('notice', None)])]),
136+
('legal_file_locations', []), ('license_expression', None), ('license_texts', []), ('notice_texts', []),
137+
('dependencies', {}), ('related_packages', [])])
138+
139+
140+
assert expected == package.as_dict()

0 commit comments

Comments
 (0)