Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/tests/test_converters.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import unittest | import unittest | ||||
from nose.tools import istest | |||||
from swh.loader.svn import converters | from swh.loader.svn import converters | ||||
class TestAuthorGitSvnConverters(unittest.TestCase): | class TestAuthorGitSvnConverters(unittest.TestCase): | ||||
@istest | def test_svn_author_to_gitsvn_person(self): | ||||
def svn_author_to_gitsvn_person(self): | |||||
"""The author should have name, email and fullname filled. | """The author should have name, email and fullname filled. | ||||
""" | """ | ||||
actual_person = converters.svn_author_to_gitsvn_person( | actual_person = converters.svn_author_to_gitsvn_person( | ||||
'tony <ynot@dagobah>', | 'tony <ynot@dagobah>', | ||||
repo_uuid=None) | repo_uuid=None) | ||||
self.assertEquals(actual_person, { | self.assertEquals(actual_person, { | ||||
'fullname': b'tony <ynot@dagobah>', | 'fullname': b'tony <ynot@dagobah>', | ||||
'name': b'tony', | 'name': b'tony', | ||||
'email': b'ynot@dagobah', | 'email': b'ynot@dagobah', | ||||
}) | }) | ||||
@istest | def test_svn_author_to_gitsvn_person_no_email(self): | ||||
def svn_author_to_gitsvn_person_no_email(self): | |||||
"""The author should see his/her email filled with author@<repo-uuid>. | """The author should see his/her email filled with author@<repo-uuid>. | ||||
""" | """ | ||||
actual_person = converters.svn_author_to_gitsvn_person( | actual_person = converters.svn_author_to_gitsvn_person( | ||||
'tony', | 'tony', | ||||
repo_uuid=b'some-uuid') | repo_uuid=b'some-uuid') | ||||
self.assertEquals(actual_person, { | self.assertEquals(actual_person, { | ||||
'fullname': b'tony <tony@some-uuid>', | 'fullname': b'tony <tony@some-uuid>', | ||||
'name': b'tony', | 'name': b'tony', | ||||
'email': b'tony@some-uuid', | 'email': b'tony@some-uuid', | ||||
}) | }) | ||||
@istest | def test_svn_author_to_gitsvn_person_empty_person(self): | ||||
def svn_author_to_gitsvn_person_empty_person(self): | |||||
"""The empty person should see name, fullname and email filled. | """The empty person should see name, fullname and email filled. | ||||
""" | """ | ||||
actual_person = converters.svn_author_to_gitsvn_person( | actual_person = converters.svn_author_to_gitsvn_person( | ||||
'', | '', | ||||
repo_uuid=b'some-uuid') | repo_uuid=b'some-uuid') | ||||
self.assertEqual(actual_person, { | self.assertEqual(actual_person, { | ||||
'fullname': b'(no author) <(no author)@some-uuid>', | 'fullname': b'(no author) <(no author)@some-uuid>', | ||||
'name': b'(no author)', | 'name': b'(no author)', | ||||
'email': b'(no author)@some-uuid' | 'email': b'(no author)@some-uuid' | ||||
}) | }) | ||||
class TestAuthorConverters(unittest.TestCase): | class TestAuthorConverters(unittest.TestCase): | ||||
@istest | def test_svn_author_to_swh_person(self): | ||||
def svn_author_to_swh_person(self): | |||||
"""The author should have name, email and fullname filled. | """The author should have name, email and fullname filled. | ||||
""" | """ | ||||
actual_person = converters.svn_author_to_swh_person( | actual_person = converters.svn_author_to_swh_person( | ||||
'tony <ynot@dagobah>') | 'tony <ynot@dagobah>') | ||||
self.assertEquals(actual_person, { | self.assertEquals(actual_person, { | ||||
'fullname': b'tony <ynot@dagobah>', | 'fullname': b'tony <ynot@dagobah>', | ||||
'name': b'tony', | 'name': b'tony', | ||||
'email': b'ynot@dagobah', | 'email': b'ynot@dagobah', | ||||
}) | }) | ||||
@istest | def test_svn_author_to_swh_person_no_email(self): | ||||
def svn_author_to_swh_person_no_email(self): | |||||
"""The author and fullname should be the same as the input (author). | """The author and fullname should be the same as the input (author). | ||||
""" | """ | ||||
actual_person = converters.svn_author_to_swh_person('tony') | actual_person = converters.svn_author_to_swh_person('tony') | ||||
self.assertEquals(actual_person, { | self.assertEquals(actual_person, { | ||||
'fullname': b'tony', | 'fullname': b'tony', | ||||
'name': b'tony', | 'name': b'tony', | ||||
'email': None, | 'email': None, | ||||
}) | }) | ||||
@istest | def test_svn_author_to_swh_person_empty_person(self): | ||||
def svn_author_to_swh_person_empty_person(self): | |||||
"""Empty person has only its fullname filled with the empty | """Empty person has only its fullname filled with the empty | ||||
byte-string. | byte-string. | ||||
""" | """ | ||||
actual_person = converters.svn_author_to_swh_person('') | actual_person = converters.svn_author_to_swh_person('') | ||||
self.assertEqual(actual_person, { | self.assertEqual(actual_person, { | ||||
'fullname': b'', | 'fullname': b'', | ||||
'name': None, | 'name': None, | ||||
'email': None, | 'email': None, | ||||
}) | }) | ||||
class TestRevisionConverters(unittest.TestCase): | class TestRevisionConverters(unittest.TestCase): | ||||
@istest | def test_build_swh_revision_default(self): | ||||
def build_swh_revision_default(self): | |||||
"""This should build the swh revision with the swh revision's extra | """This should build the swh revision with the swh revision's extra | ||||
headers about the repository. | headers about the repository. | ||||
""" | """ | ||||
actual_swh_revision = converters.build_swh_revision( | actual_swh_revision = converters.build_swh_revision( | ||||
repo_uuid=b'uuid', | repo_uuid=b'uuid', | ||||
dir_id='dir-id', | dir_id='dir-id', | ||||
commit={ | commit={ | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | def test_build_swh_revision_default(self): | ||||
['svn_revision', b'10'], | ['svn_revision', b'10'], | ||||
] | ] | ||||
}, | }, | ||||
'parents': ['123'], | 'parents': ['123'], | ||||
}) | }) | ||||
class TestGitSvnRevisionConverters(unittest.TestCase): | class TestGitSvnRevisionConverters(unittest.TestCase): | ||||
@istest | def test_build_gitsvn_swh_revision_default(self): | ||||
def build_gitsvn_swh_revision_default(self): | |||||
"""This should build the swh revision without the swh revision's extra | """This should build the swh revision without the swh revision's extra | ||||
headers about the repository. | headers about the repository. | ||||
""" | """ | ||||
actual_swh_revision = converters.build_gitsvn_swh_revision( | actual_swh_revision = converters.build_gitsvn_swh_revision( | ||||
dir_id='dir-id', | dir_id='dir-id', | ||||
commit={ | commit={ | ||||
'author_name': { | 'author_name': { | ||||
Show All 39 Lines | def test_build_gitsvn_swh_revision_default(self): | ||||
}, | }, | ||||
'synthetic': True, | 'synthetic': True, | ||||
'metadata': None, | 'metadata': None, | ||||
'parents': ['123'], | 'parents': ['123'], | ||||
}) | }) | ||||
class ConvertDate(unittest.TestCase): | class ConvertDate(unittest.TestCase): | ||||
@istest | def test_svn_date_to_swh_date(self): | ||||
def svn_date_to_swh_date(self): | |||||
"""The timestamp should not be tampered with and include the | """The timestamp should not be tampered with and include the | ||||
decimals. | decimals. | ||||
""" | """ | ||||
self.assertEquals( | self.assertEquals( | ||||
converters.svn_date_to_swh_date('2011-05-31T06:04:39.500900Z'), { | converters.svn_date_to_swh_date('2011-05-31T06:04:39.500900Z'), { | ||||
'timestamp': { | 'timestamp': { | ||||
'seconds': 1306821879, | 'seconds': 1306821879, | ||||
'microseconds': 500900, | 'microseconds': 500900, | ||||
}, | }, | ||||
'offset': 0 | 'offset': 0 | ||||
}) | }) | ||||
self.assertEquals( | self.assertEquals( | ||||
converters.svn_date_to_swh_date('2011-05-31T06:04:39.800722Z'), | converters.svn_date_to_swh_date('2011-05-31T06:04:39.800722Z'), | ||||
{ | { | ||||
'timestamp': { | 'timestamp': { | ||||
'seconds': 1306821879, | 'seconds': 1306821879, | ||||
'microseconds': 800722, | 'microseconds': 800722, | ||||
}, | }, | ||||
'offset': 0 | 'offset': 0 | ||||
}) | }) | ||||
@istest | def test_svn_date_to_swh_date_epoch(self): | ||||
def svn_date_to_swh_date_epoch(self): | |||||
"""Empty date should be EPOCH (timestamp and offset at 0).""" | """Empty date should be EPOCH (timestamp and offset at 0).""" | ||||
# It should return 0, epoch | # It should return 0, epoch | ||||
self.assertEquals({ | self.assertEquals({ | ||||
'timestamp': { | 'timestamp': { | ||||
'seconds': 0, | 'seconds': 0, | ||||
'microseconds': 0, | 'microseconds': 0, | ||||
}, | }, | ||||
'offset': 0, | 'offset': 0, | ||||
}, converters.svn_date_to_swh_date('')) | }, converters.svn_date_to_swh_date('')) | ||||
self.assertEquals({ | self.assertEquals({ | ||||
'timestamp': { | 'timestamp': { | ||||
'seconds': 0, | 'seconds': 0, | ||||
'microseconds': 0, | 'microseconds': 0, | ||||
}, 'offset': 0, | }, 'offset': 0, | ||||
}, converters.svn_date_to_swh_date(None)) | }, converters.svn_date_to_swh_date(None)) | ||||
class ConvertGitSvnDate(unittest.TestCase): | class ConvertGitSvnDate(unittest.TestCase): | ||||
@istest | def test_svn_date_to_gitsvn_date(self): | ||||
def svn_date_to_gitsvn_date(self): | |||||
"""The timestamp should be truncated to be an integer.""" | """The timestamp should be truncated to be an integer.""" | ||||
actual_ts = converters.svn_date_to_gitsvn_date( | actual_ts = converters.svn_date_to_gitsvn_date( | ||||
'2011-05-31T06:04:39.800722Z') | '2011-05-31T06:04:39.800722Z') | ||||
self.assertEquals(actual_ts, { | self.assertEquals(actual_ts, { | ||||
'timestamp': { | 'timestamp': { | ||||
'seconds': 1306821879, | 'seconds': 1306821879, | ||||
'microseconds': 0, | 'microseconds': 0, | ||||
}, | }, | ||||
'offset': 0, | 'offset': 0, | ||||
}) | }) | ||||
@istest | def test_svn_date_to_gitsvn_date_epoch(self): | ||||
def svn_date_to_gitsvn_date_epoch(self): | |||||
"""Empty date should be EPOCH (timestamp and offset at 0).""" | """Empty date should be EPOCH (timestamp and offset at 0).""" | ||||
# It should return 0, epoch | # It should return 0, epoch | ||||
self.assertEquals({ | self.assertEquals({ | ||||
'timestamp': { | 'timestamp': { | ||||
'seconds': 0, | 'seconds': 0, | ||||
'microseconds': 0, | 'microseconds': 0, | ||||
}, | }, | ||||
'offset': 0, | 'offset': 0, | ||||
}, converters.svn_date_to_gitsvn_date('')) | }, converters.svn_date_to_gitsvn_date('')) | ||||
self.assertEquals({ | self.assertEquals({ | ||||
'timestamp': { | 'timestamp': { | ||||
'seconds': 0, | 'seconds': 0, | ||||
'microseconds': 0, | 'microseconds': 0, | ||||
}, | }, | ||||
'offset': 0, | 'offset': 0, | ||||
}, converters.svn_date_to_gitsvn_date(None)) | }, converters.svn_date_to_gitsvn_date(None)) |