Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_cli.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018-2019 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 tarfile | |||||
import tempfile | import tempfile | ||||
import unittest | import unittest | ||||
from click.testing import CliRunner | from click.testing import CliRunner | ||||
import pytest | import pytest | ||||
from swh.model import cli | from swh.model import cli | ||||
from swh.model.hashutil import hash_to_hex | from swh.model.hashutil import hash_to_hex | ||||
Show All 25 Lines | def test_directory_id(self): | ||||
"""identify an entire directory""" | """identify an entire directory""" | ||||
self.make_from_tarball(self.tmpdir_name) | self.make_from_tarball(self.tmpdir_name) | ||||
path = os.path.join(self.tmpdir_name, b'sample-folder') | path = os.path.join(self.tmpdir_name, b'sample-folder') | ||||
result = self.runner.invoke(cli.identify, | result = self.runner.invoke(cli.identify, | ||||
['--type', 'directory', path]) | ['--type', 'directory', path]) | ||||
self.assertPidOK(result, | self.assertPidOK(result, | ||||
'swh:1:dir:e8b0f1466af8608c8a3fb9879db172b887e80759') | 'swh:1:dir:e8b0f1466af8608c8a3fb9879db172b887e80759') | ||||
def test_snapshot_id(self): | |||||
"""identify a snapshot""" | |||||
tarball = os.path.join(os.path.dirname(__file__), 'data', 'repos', | |||||
'sample-repo.tgz') | |||||
with tempfile.TemporaryDirectory(prefix='swh.model.cli') as d: | |||||
with tarfile.open(tarball, 'r:gz') as t: | |||||
t.extractall(d) | |||||
repo_dir = os.path.join(d, 'sample-repo') | |||||
result = self.runner.invoke(cli.identify, | |||||
['--type', 'snapshot', repo_dir]) | |||||
self.assertPidOK(result, | |||||
'swh:1:snp:9dc0fc035aabe293f5faf6c362a59513454a170d') # NoQA | |||||
def test_origin_id(self): | def test_origin_id(self): | ||||
"""identify an origin URL""" | """identify an origin URL""" | ||||
url = 'https://github.com/torvalds/linux' | url = 'https://github.com/torvalds/linux' | ||||
result = self.runner.invoke(cli.identify, ['--type', 'origin', url]) | result = self.runner.invoke(cli.identify, ['--type', 'origin', url]) | ||||
self.assertPidOK(result, | self.assertPidOK(result, | ||||
'swh:1:ori:b63a575fe3faab7692c9f38fb09d4bb45651bb0f') | 'swh:1:ori:b63a575fe3faab7692c9f38fb09d4bb45651bb0f') | ||||
def test_symlink(self): | def test_symlink(self): | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |