Ejemplo n.º 1
0
class SwiftStorageUtils(trove_testtools.TestCase):

    def setUp(self):
        super(SwiftStorageUtils, self).setUp()
        self.context = trove_testtools.TroveTestContext(self)
        self.swift_client = FakeSwiftConnection()
        self.create_swift_client_patch = patch.object(
            swift, 'create_swift_client',
            MagicMock(return_value=self.swift_client))
        self.create_swift_client_mock = self.create_swift_client_patch.start()
        self.addCleanup(self.create_swift_client_patch.stop)
        self.swift = SwiftStorage(self.context)

    def tearDown(self):
        super(SwiftStorageUtils, self).tearDown()

    def test_explode_location(self):
        location = 'http://mockswift.com/v1/545433/backups/mybackup.tar'
        url, container, filename = self.swift._explodeLocation(location)
        self.assertEqual('http://mockswift.com/v1/545433', url)
        self.assertEqual('backups', container)
        self.assertEqual('mybackup.tar', filename)

    def test_validate_checksum_good(self):
        match = self.swift._verify_checksum('"my-good-etag"', 'my-good-etag')
        self.assertTrue(match)

    @patch('trove.common.strategies.storage.swift.LOG')
    def test_verify_checksum_bad(self, mock_logging):
        self.assertRaises(SwiftDownloadIntegrityError,
                          self.swift._verify_checksum,
                          '"THE-GOOD-THE-BAD"',
                          'AND-THE-UGLY')
Ejemplo n.º 2
0
class SwiftStorageUtils(trove_testtools.TestCase):
    def setUp(self):
        super(SwiftStorageUtils, self).setUp()
        self.context = trove_testtools.TroveTestContext(self)
        self.swift_client = FakeSwiftConnection()
        self.create_swift_client_patch = patch.object(
            remote, 'create_swift_client',
            MagicMock(return_value=self.swift_client))
        self.create_swift_client_mock = self.create_swift_client_patch.start()
        self.addCleanup(self.create_swift_client_patch.stop)
        self.swift = SwiftStorage(self.context)

    def tearDown(self):
        super(SwiftStorageUtils, self).tearDown()

    def test_explode_location(self):
        location = 'http://mockswift.com/v1/545433/backups/mybackup.tar'
        url, container, filename = self.swift._explodeLocation(location)
        self.assertEqual('http://mockswift.com/v1/545433', url)
        self.assertEqual('backups', container)
        self.assertEqual('mybackup.tar', filename)

    def test_validate_checksum_good(self):
        match = self.swift._verify_checksum('"my-good-etag"', 'my-good-etag')
        self.assertTrue(match)

    @patch('trove.common.strategies.storage.swift.LOG')
    def test_verify_checksum_bad(self, mock_logging):
        self.assertRaises(SwiftDownloadIntegrityError,
                          self.swift._verify_checksum, '"THE-GOOD-THE-BAD"',
                          'AND-THE-UGLY')