| |
@@ -1,6 +1,7 @@
|
| |
# -*- coding: utf-8 -*-
|
| |
|
| |
import errno
|
| |
+ import filecmp
|
| |
import glob
|
| |
import hashlib
|
| |
import logging
|
| |
@@ -12,15 +13,16 @@
|
| |
import tempfile
|
| |
|
| |
import git
|
| |
+ import koji_cli.lib
|
| |
import six
|
| |
+ import utils
|
| |
from mock import ANY, Mock, PropertyMock, call, mock_open, patch
|
| |
from six.moves import StringIO, configparser, http_client
|
| |
+ from utils import CommandTestCase, FakeThreadPool
|
| |
|
| |
- import koji_cli.lib
|
| |
import pyrpkg.cli
|
| |
- import utils
|
| |
from pyrpkg import Commands, Modulemd, layout, rpkgError
|
| |
- from utils import CommandTestCase, FakeThreadPool
|
| |
+ from pyrpkg.errors import AlreadyUploadedError
|
| |
|
| |
try:
|
| |
import unittest2 as unittest
|
| |
@@ -1229,10 +1231,17 @@
|
| |
def lookasidecache_upload(self, repo_name, filepath, hash, offline):
|
| |
filename = os.path.basename(filepath)
|
| |
storage_filename = os.path.join(self.lookasidecache_storage, filename)
|
| |
+ if self._remote_file_exists(filepath, storage_filename):
|
| |
+ raise AlreadyUploadedError("File already uploaded.")
|
| |
with open(storage_filename, 'wb') as fout:
|
| |
with open(filepath, 'rb') as fin:
|
| |
fout.write(fin.read())
|
| |
|
| |
+ def _remote_file_exists(self, local_file, remote_file):
|
| |
+ if os.path.isfile(remote_file):
|
| |
+ return filecmp.cmp(local_file, remote_file)
|
| |
+ return False
|
| |
+
|
| |
def lookasidecache_download(self, name, filename, hash, outfile, hashtype=None, **kwargs):
|
| |
with open(outfile, 'w') as f:
|
| |
f.write('binary data')
|
| |
@@ -1330,6 +1339,22 @@
|
| |
r'.+README.rst which has different checksum.+',
|
| |
cli.upload)
|
| |
|
| |
+ @patch('pyrpkg.log.info')
|
| |
+ def test_upload_file_twice(self, log_info):
|
| |
+ cli_cmd = [
|
| |
+ 'rpkg', '--path', self.cloned_repo_path, 'upload', self.readme_patch
|
| |
+ ]
|
| |
+
|
| |
+ with patch('sys.argv', new=cli_cmd):
|
| |
+ cli = self.new_cli()
|
| |
+ with patch('pyrpkg.lookaside.CGILookasideCache.upload',
|
| |
+ new=self.lookasidecache_upload):
|
| |
+ cli.upload()
|
| |
+ cli.upload()
|
| |
+
|
| |
+ log_info.assert_has_calls(
|
| |
+ call("All sources were already uploaded."))
|
| |
+
|
| |
|
| |
class TestSources(LookasideCacheMock, CliTestCase):
|
| |
|
| |
@@ -1503,7 +1528,11 @@
|
| |
|
| |
def test_import(self):
|
| |
self.assert_import_srpm(self.chaos_repo)
|
| |
- self.assert_import_srpm(self.cloned_repo_path)
|
| |
+ # Exception is not a functionality issue. There is no problem with
|
| |
+ # uploading same file twice in a test however, the upload method checks
|
| |
+ # if file has been already uploaded.
|
| |
+ self.assertRaisesRegex(AlreadyUploadedError, r'File already uploaded',
|
| |
+ self.assert_import_srpm, self.cloned_repo_path)
|
| |
|
| |
def test_import_gating_and_rpmlintrc_exception(self):
|
| |
# Add three additional files to the repo. Former gating.yaml and package.rpmlintrc are
|
| |
Fixes the bug when new-sources prints our the message "Source upload succeeded. Don't forget to commit the sources file" when file is already uploaded (so there is no upload).
Fixes: #533
JIRA: RHELCMP-5529
Signed-off-by: Dominik Rumian drumian@redhat.com