Skip to content
Snippets Groups Projects
Verified Commit f140bd02 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

pypi.converters: Fallback to empty author if metadata incomplete

Close T1206
parent ca97baea
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,9 @@
# See top-level LICENSE file for more information
EMPTY_AUTHOR = {'fullname': b'', 'name': None, 'email': None}
def info(data):
"""Given a dict of a PyPI project information, returns a project
subset.
......@@ -48,15 +51,16 @@ def author(data):
swh-model dict representing a person.
"""
name = data['author']
email = data['author_email']
name = data.get('author')
email = data.get('author_email')
if email:
fullname = '%s <%s>' % (name, email)
else:
fullname = name
if not fullname:
return {'fullname': b'', 'name': None, 'email': None}
return EMPTY_AUTHOR
if fullname:
fullname = fullname.encode('utf-8')
......
......@@ -6,7 +6,7 @@
from unittest import TestCase
from nose.tools import istest
from swh.loader.pypi.converters import author, info
from swh.loader.pypi.converters import author, EMPTY_AUTHOR
from .common import WithProjectTest
......@@ -43,6 +43,23 @@ class Test(WithProjectTest):
self.assertEqual(expected_author, actual_author)
@istest
def no_author(self):
actual_author = author({})
self.assertEqual(EMPTY_AUTHOR, actual_author)
@istest
def partial_author(self):
actual_author = author({'author': 'someone'})
expected_author = {
'name': b'someone',
'fullname': b'someone',
'email': None,
}
self.assertEqual(expected_author, actual_author)
class ParseAuthorTest(TestCase):
@istest
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment