Esempio n. 1
0
 def test_upload_file_dry_run_doesnt_upload(self):
     file_path = '/92877-framework-agreement.pdf'
     bucket = mock.Mock()
     with mock.patch.object(builtins, 'open',
                            mock.mock_open(read_data='foo')):
         upload_file(bucket, True, file_path, 'g-cloud-11', 'agreements')
         assert bucket.save.call_count == 0
Esempio n. 2
0
def test_upload_file_dry_run_doesnt_upload():
    file_path = 'The_Business_Software_Centre-92877-signed-framework-agreement.pdf'
    bucket = mock.Mock()
    with mock.patch.object(builtins, 'open', mock.mock_open(read_data='foo')):
        upload_file(bucket, True, file_path, 'g-cloud-7', 'agreements',
                    'countersigned_agreement', 'pdf')
        assert bucket.save.call_count == 0
def test_upload_file_dry_run_doesnt_upload():
    file_path = 'The_Business_Software_Centre-92877-signed-framework-agreement.pdf'
    bucket = mock.Mock()
    with mock.patch.object(builtins, 'open', mock.mock_open(read_data='foo')):
        upload_file(bucket, True, file_path, 'g-cloud-7', 'agreements',
                    'countersigned_agreement', 'pdf')
        assert bucket.save.call_count == 0
Esempio n. 4
0
 def test_upload_file_skips_signed_framework_agreement(self):
     file_path = '/12345-signed-framework-agreement.pdf'
     bucket = mock.Mock()
     with mock.patch.object(builtins, 'open',
                            mock.mock_open(read_data='foo')) as mock_open:
         with pytest.raises(ValueError):
             upload_file(bucket, False, file_path, 'g-cloud-11',
                         'agreements')
         assert bucket.save.call_count == 0
         assert mock_open.called is False
Esempio n. 5
0
def test_upload_file_without_document_category():
    file_path = '/92877-framework-agreement.pdf'
    bucket = mock.Mock()
    with mock.patch.object(builtins, 'open', mock.mock_open(read_data='foo')):
        upload_file(bucket, False, file_path, 'g-cloud-7', 'agreements')
        assert bucket.save.call_count == 1
        bucket.save.assert_called_with(
            'g-cloud-7/agreements/92877/92877-framework-agreement.pdf',
            mock.ANY,
            acl='bucket-owner-full-control',
            download_filename=None)
Esempio n. 6
0
 def test_upload_file_with_document_bucket_category(self):
     file_path = '/92877-modern-slavery-statement.pdf'
     bucket = mock.Mock()
     with mock.patch.object(builtins, 'open',
                            mock.mock_open(read_data='foo')):
         upload_file(bucket, False, file_path, 'g-cloud-11', 'documents')
         assert bucket.save.call_count == 1
         bucket.save.assert_called_with(
             'g-cloud-11/documents/92877/92877-modern-slavery-statement.pdf',
             mock.ANY,
             acl='bucket-owner-full-control',
             download_filename=None)
def test_upload_file_without_document_category():
    file_path = '/92877-signed-framework-agreement.pdf'
    bucket = mock.Mock()
    with mock.patch.object(builtins, 'open', mock.mock_open(read_data='foo')):
        upload_file(bucket, False, file_path, 'g-cloud-7', 'agreements')
        assert bucket.save.call_count == 1
        bucket.save.assert_called_with(
            'g-cloud-7/agreements/92877/92877-signed-framework-agreement.pdf',
            mock.ANY,
            acl='private',
            move_prefix=None,
            download_filename=None)
Esempio n. 8
0
def test_upload_file():
    file_path = 'The_Business_Software_Centre-92877-signed-framework-agreement.pdf'
    bucket = mock.Mock()
    with mock.patch.object(builtins, 'open', mock.mock_open(read_data='foo')):
        upload_file(bucket, False, file_path, 'g-cloud-7', 'agreements',
                    'countersigned_agreement', 'pdf')
        assert bucket.save.call_count == 1
        bucket.save.assert_called_with(
            'g-cloud-7/agreements/92877/92877-countersigned_agreement.pdf',
            mock.ANY,
            acl='bucket-owner-full-control',
            download_filename=None)
def test_upload_file():
    file_path = 'The_Business_Software_Centre-92877-signed-framework-agreement.pdf'
    bucket = mock.Mock()
    with mock.patch.object(builtins, 'open', mock.mock_open(read_data='foo')):
        upload_file(bucket, False, file_path, 'g-cloud-7', 'agreements',
                    'countersigned_agreement', 'pdf')
        assert bucket.save.call_count == 1
        bucket.save.assert_called_with(
            'g-cloud-7/agreements/92877/92877-countersigned_agreement.pdf',
            mock.ANY,
            acl='private',
            download_filename=None,
            move_prefix=None)
def test_upload_file_with_supplier_name_dictionary():
    file_path = '/35435-signed-framework-agreement.pdf'
    supplier_name_dictionary = {'35435': 'Something', '584425': 'ICNT_Consulting_Ltd'}
    bucket = mock.Mock()
    with mock.patch.object(builtins, 'open', mock.mock_open(read_data='foo')):
        upload_file(bucket, False, file_path, 'g-cloud-7', 'agreements', supplier_name_dict=supplier_name_dictionary)  # noqa
        assert bucket.save.call_count == 1
        bucket.save.assert_called_with(
            'g-cloud-7/agreements/35435/35435-signed-framework-agreement.pdf',
            mock.ANY,
            acl='private',
            download_filename='Something-35435-signed-framework-agreement.pdf',
            move_prefix=None)
Esempio n. 11
0
def test_upload_file_with_supplier_name_dictionary():
    file_path = '/35435-framework-agreement.pdf'
    supplier_name_dictionary = {
        '35435': 'Something',
        '584425': 'ICNT_Consulting_Ltd'
    }
    bucket = mock.Mock()
    with mock.patch.object(builtins, 'open', mock.mock_open(read_data='foo')):
        upload_file(bucket,
                    False,
                    file_path,
                    'g-cloud-7',
                    'agreements',
                    supplier_name_dict=supplier_name_dictionary)  # noqa
        assert bucket.save.call_count == 1
        bucket.save.assert_called_with(
            'g-cloud-7/agreements/35435/35435-framework-agreement.pdf',
            mock.ANY,
            acl='bucket-owner-full-control',
            download_filename='Something-35435-framework-agreement.pdf')
)

from docopt import docopt

from dmutils.s3 import S3


if __name__ == "__main__":
    arguments = docopt(__doc__)

    stage = arguments["<stage>"]
    framework_slug = arguments["<framework_slug>"]
    local_directory = arguments["<local_documents_directory>"]
    bucket_category = arguments["--bucket_category"]
    file_type = arguments["--file_type"]
    tsv_path = arguments["<tsv_path>"]
    dry_run = arguments["--dry-run"]

    if dry_run:
        bucket = None
    else:
        bucket = S3(get_bucket_name(stage, bucket_category))

    supplier_name_dict = get_supplier_name_dict_from_tsv(tsv_path)
    for path in get_all_files_of_type(local_directory, file_type):
        try:
            upload_file(bucket, dry_run, path, framework_slug, bucket_category, supplier_name_dict=supplier_name_dict)
        except ValueError as e:
            print("SKIPPING: {}".format(e))
            continue
    stage = arguments['<stage>']
    framework_slug = arguments['<framework_slug>']
    local_directory = arguments['<local_documents_directory>']
    bucket_category = arguments['--bucket_category']
    file_type = arguments['--file_type']
    tsv_path = arguments['--tsv-path']
    dry_run = arguments['--dry-run']

    if dry_run:
        bucket = None
    else:
        bucket = S3(get_bucket_name(stage, bucket_category))

    supplier_name_dict = get_supplier_name_dict_from_tsv(tsv_path)

    if not os.path.exists(local_directory):
        print(f"Local directory {local_directory} not found. Aborting upload.")
        exit(1)

    for path in get_all_files_of_type(local_directory, file_type):
        try:
            upload_file(bucket,
                        dry_run,
                        path,
                        framework_slug,
                        bucket_category,
                        supplier_name_dict=supplier_name_dict)
        except ValueError as e:
            print("SKIPPING: {}".format(e))
            continue
    stage = arguments['<stage>']
    framework_slug = arguments['<framework_slug>']
    local_directory = arguments['<local_documents_directory>']
    bucket_category = arguments['--bucket_category']
    document_category = arguments['<document_category>']
    document_type = arguments['--document_type']
    dry_run = arguments['--dry-run']

    document_categories = ['result-letter',
                           'framework-agreement',
                           'signed-framework-agreement',
                           'countersigned-framework-agreement']

    if document_category not in document_categories:
        print('Document needs to be one of {}'.format(document_categories))
        sys.exit(1)

    if dry_run:
        bucket = None
    else:
        bucket = S3(get_bucket_name(stage, bucket_category))

    for path in get_all_files_of_type(local_directory, document_type):
        try:
            upload_file(bucket, dry_run, path, framework_slug, bucket_category,
                        document_category, document_type)
        except ValueError as e:
            print("SKIPPING: {}".format(e))
            continue
Esempio n. 15
0
    framework_slug = arguments['<framework_slug>']
    local_directory = arguments['<local_documents_directory>']
    bucket_category = arguments['--bucket_category']
    document_category = arguments['<document_category>']
    document_type = arguments['--document_type']
    dry_run = arguments['--dry-run']

    document_categories = ['result-letter', 'framework-agreement']

    if document_category not in document_categories:
        print('Document needs to be one of {}'.format(document_categories))
        if document_category in ('signed-framework-agreement',
                                 'countersigned-framework-agreement'):
            print(
                'Signed and countersigned agreement paths now need to be stored in database so cannot be uploaded '
                'using this script.')
        sys.exit(1)

    if dry_run:
        bucket = None
    else:
        bucket = S3(get_bucket_name(stage, bucket_category))

    for path in get_all_files_of_type(local_directory, document_type):
        try:
            upload_file(bucket, dry_run, path, framework_slug, bucket_category,
                        document_category, document_type)
        except ValueError as e:
            print("SKIPPING: {}".format(e))
            continue