Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_db.py
# Copyright (C) 2015-2017 The Software Heritage developers | # Copyright (C) 2015-2017 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 unittest | import unittest | ||||
from nose.tools import istest | |||||
from nose.plugins.attrib import attr | from nose.plugins.attrib import attr | ||||
from swh.core.tests.db_testing import SingleDbTestFixture | from swh.core.tests.db_testing import SingleDbTestFixture | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.storage.db import Db | from swh.storage.db import Db | ||||
TEST_DIR = os.path.dirname(os.path.abspath(__file__)) | TEST_DIR = os.path.dirname(os.path.abspath(__file__)) | ||||
TEST_DATA_DIR = os.path.join(TEST_DIR, '../../../../swh-storage-testdata') | TEST_DATA_DIR = os.path.join(TEST_DIR, '../../../../swh-storage-testdata') | ||||
@attr('db') | @attr('db') | ||||
class TestDb(SingleDbTestFixture, unittest.TestCase): | class TestDb(SingleDbTestFixture, unittest.TestCase): | ||||
TEST_DB_DUMP = os.path.join(TEST_DATA_DIR, 'dumps/swh.dump') | TEST_DB_DUMP = os.path.join(TEST_DATA_DIR, 'dumps/swh.dump') | ||||
def setUp(self): | def setUp(self): | ||||
super().setUp() | super().setUp() | ||||
self.db = Db(self.conn) | self.db = Db(self.conn) | ||||
def tearDown(self): | def tearDown(self): | ||||
self.db.conn.close() | self.db.conn.close() | ||||
super().tearDown() | super().tearDown() | ||||
@istest | def test_add_content(self): | ||||
def add_content(self): | |||||
cur = self.cursor | cur = self.cursor | ||||
sha1 = hash_to_bytes('34973274ccef6ab4dfaaf86599792fa9c3fe4689') | sha1 = hash_to_bytes('34973274ccef6ab4dfaaf86599792fa9c3fe4689') | ||||
self.db.mktemp('content', cur) | self.db.mktemp('content', cur) | ||||
self.db.copy_to([{ | self.db.copy_to([{ | ||||
'sha1': sha1, | 'sha1': sha1, | ||||
'sha1_git': hash_to_bytes( | 'sha1_git': hash_to_bytes( | ||||
'd81cc0710eb6cf9efd5b920a8453e1e07157b6cd'), | 'd81cc0710eb6cf9efd5b920a8453e1e07157b6cd'), | ||||
'sha256': hash_to_bytes( | 'sha256': hash_to_bytes( | ||||
Show All 12 Lines |