Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/tar/tests/test_loader.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-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 os | import os | ||||
import pytest | import pytest | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.loader.core.tests import BaseLoaderTest | from swh.loader.core.tests import BaseLoaderTest | ||||
from swh.loader.tar.loader import TarLoader | from swh.loader.tar.loader import TarLoader | ||||
TEST_CONFIG = { | TEST_CONFIG = { | ||||
'extraction_dir': '/tmp/tests/loader-tar/', # where to extract the tarball | 'working_dir': '/tmp/tests/loader-tar/', # where to extract the tarball | ||||
'debug': False, | |||||
'storage': { # we instantiate it but we don't use it in test context | 'storage': { # we instantiate it but we don't use it in test context | ||||
'cls': 'memory', | 'cls': 'memory', | ||||
'args': { | 'args': { | ||||
} | } | ||||
}, | }, | ||||
'send_contents': True, | 'send_contents': True, | ||||
'send_directories': True, | 'send_directories': True, | ||||
'send_revisions': True, | 'send_revisions': True, | ||||
Show All 33 Lines | class TestTarLoader1(TestTarLoader): | ||||
@pytest.mark.fs | @pytest.mark.fs | ||||
def test_load(self): | def test_load(self): | ||||
"""Process a new tarball should be ok | """Process a new tarball should be ok | ||||
""" | """ | ||||
# given | # given | ||||
origin = { | origin = { | ||||
'url': 'file:///tmp/sample-folder', | 'url': self.repo_url, | ||||
'type': 'dir' | 'type': 'tar' | ||||
} | } | ||||
visit_date = 'Tue, 3 May 2016 17:16:32 +0200' | visit_date = 'Tue, 3 May 2016 17:16:32 +0200' | ||||
import datetime | last_modified = '2018-12-05T12:35:23+00:00' | ||||
ardumont: Same i use the same date as before but with another format. | |||||
commit_time = int(datetime.datetime( | |||||
2018, 12, 5, 13, 35, 23, 0, | |||||
tzinfo=datetime.timezone(datetime.timedelta(hours=1)) | |||||
).timestamp()) | |||||
swh_person = { | |||||
'name': 'Software Heritage', | |||||
'fullname': 'Software Heritage', | |||||
'email': 'robot@softwareheritage.org' | |||||
} | |||||
revision_message = 'swh-loader-tar: synthetic revision message' | |||||
revision_type = 'tar' | |||||
revision = { | |||||
'date': { | |||||
'timestamp': commit_time, | |||||
'offset': 0, | |||||
}, | |||||
'committer_date': { | |||||
'timestamp': commit_time, | |||||
'offset': 0, | |||||
}, | |||||
'author': swh_person, | |||||
'committer': swh_person, | |||||
'type': revision_type, | |||||
'message': revision_message, | |||||
'synthetic': True, | |||||
} | |||||
branch_name = os.path.basename(self.tarpath) | |||||
# when | # when | ||||
self.loader.load(tar_path=self.tarpath, origin=origin, | self.loader.load( | ||||
visit_date=visit_date, revision=revision, | origin=origin, visit_date=visit_date, last_modified=last_modified) | ||||
branch_name=branch_name) | |||||
# then | # then | ||||
self.assertCountContents(8, "3 files + 5 links") | self.assertCountContents(8, "3 files + 5 links") | ||||
self.assertCountDirectories(6, "4 subdirs + 1 empty + 1 main dir") | self.assertCountDirectories(6, "4 subdirs + 1 empty + 1 main dir") | ||||
self.assertCountRevisions(1, "synthetic revision") | self.assertCountRevisions(1, "synthetic revision") | ||||
rev_id = hashutil.hash_to_bytes( | rev_id = hashutil.hash_to_bytes( | ||||
'67a7d7dda748f9a86b56a13d9218d16f5cc9ab3d') | '67a7d7dda748f9a86b56a13d9218d16f5cc9ab3d') | ||||
Show All 23 Lines |
Same i use the same date as before but with another format.