def test_document_upload_s3_error(self): uploader = mock.Mock(bucket_short_name="documents") uploader.upload_fileobj.side_effect = S3ResponseError(403, 'Forbidden') with freeze_time('2015-01-02 04:05:00'): self.assertFalse( upload_document(uploader, 'http://assets', { 'id': "123", 'supplierCode': 5, 'frameworkSlug': 'g-cloud-6' }, "pricingDocumentURL", mock_file('file.pdf', 1)))
def test_document_upload_s3_error(self): uploader = mock.Mock(bucket_short_name="documents") uploader.save.side_effect = S3ResponseError(403, 'Forbidden') with freeze_time('2015-01-02 04:05:00'): self.assertFalse(upload_document( uploader, 'http://assets', {'id': "123", 'supplierId': 5, 'frameworkSlug': 'g-cloud-6'}, "pricingDocumentURL", mock_file('file.pdf', 1) ))
def test_document_upload_s3_error(self): uploader = mock.Mock() # using True as the mock "error_response" for this exception as we want to know if the function under test # wants to access a property of the exception rather than for it to continue in happy ignorance uploader.save.side_effect = ClientError(mock.MagicMock(), 'Forbidden') with freeze_time('2015-01-02 04:05:00'): self.assertFalse( upload_document(uploader, 'documents', 'http://assets', { 'id': "123", 'supplierId': 5, 'frameworkSlug': 'g-cloud-6' }, "pricingDocumentURL", MockFile(b"*", 'file.pdf')))
def test_document_upload_with_invalid_upload_type(self): uploader = mock.Mock() with pytest.raises(ValueError): assert upload_document( uploader, 'invalid', 'http://assets', {'id': "123", 'supplierId': 5, 'frameworkSlug': 'g-cloud-6'}, "pricingDocumentURL", MockFile(b"*", 'file.pdf') ) == 'http://assets/g-cloud-6/submissions/5/123-pricing-document-2015-01-02-0405.pdf' assert not uploader.save.called
def test_document_upload_with_invalid_short_bucket_name(self): uploader = mock.Mock(bucket_short_name="invalid") with pytest.raises(AssertionError): self.assertEquals( upload_document( uploader, 'http://assets', {'id': "123", 'supplierId': 5, 'frameworkSlug': 'g-cloud-6'}, "pricingDocumentURL", mock_file('file.pdf', 1) ), 'http://assets/g-cloud-6/submissions/5/123-pricing-document-2015-01-02-0405.pdf' ) assert not uploader.save.called
def test_document_upload(self): uploader = mock.Mock(bucket_short_name="documents") with freeze_time('2015-01-02 04:05:00'): self.assertEqual( upload_document(uploader, 'http://assets', { 'id': "123", 'supplierCode': 5, 'frameworkSlug': 'g-cloud-6' }, "pricingDocumentURL", mock_file('file.pdf', 1)), 'http://assets/g-cloud-6/documents/5/123-pricing-document-2015-01-02-0405.pdf' ) uploader.upload_fileobj.assert_called_once_with( mock.ANY, 'g-cloud-6/documents/5/123-pricing-document-2015-01-02-0405.pdf', {'ACL': 'public-read'})
def test_document_upload_with_other_upload_type(self): uploader = mock.Mock() with freeze_time('2015-01-02 04:05:00'): self.assertEquals( upload_document(uploader, 'submissions', 'http://assets', { 'id': "123", 'supplierId': 5, 'frameworkSlug': 'g-cloud-6' }, "pricingDocumentURL", MockFile(b"*", 'file.pdf')), 'http://assets/g-cloud-6/submissions/5/123-pricing-document-2015-01-02-0405.pdf' ) uploader.save.assert_called_once_with( 'g-cloud-6/submissions/5/123-pricing-document-2015-01-02-0405.pdf', mock.ANY, acl='public-read')
def test_document_upload_with_null_service_id(self): uploader = mock.Mock() with freeze_time('2015-01-02 04:05:00'): assert upload_document( uploader, 'documents', 'http://assets', {'supplierId': 5, 'frameworkSlug': 'g-cloud-11'}, "modernSlaveryStatement", MockFile(b"*", 'file.pdf') ) == 'http://assets/g-cloud-11/documents/5/modern-slavery-statement-2015-01-02-0405.pdf' uploader.save.assert_called_once_with( 'g-cloud-11/documents/5/modern-slavery-statement-2015-01-02-0405.pdf', mock.ANY, acl='public-read' )
def test_document_private_upload(self): uploader = mock.Mock() with freeze_time('2015-01-02 04:05:00'): assert upload_document( uploader, 'documents', 'http://assets', {'id': "123", 'supplierId': 5, 'frameworkSlug': 'g-cloud-6'}, "pricingDocumentURL", MockFile(b"*", 'file.pdf'), public=False ) == 'http://assets/g-cloud-6/documents/5/123-pricing-document-2015-01-02-0405.pdf' uploader.save.assert_called_once_with( 'g-cloud-6/documents/5/123-pricing-document-2015-01-02-0405.pdf', mock.ANY, acl='bucket-owner-full-control' )
def test_document_upload_with_other_bucket_short_name(self): uploader = mock.Mock(bucket_short_name="submissions") with freeze_time('2015-01-02 04:05:00'): self.assertEquals( upload_document( uploader, 'http://assets', {'id': "123", 'supplierId': 5, 'frameworkSlug': 'g-cloud-6'}, "pricingDocumentURL", mock_file('file.pdf', 1) ), 'http://assets/g-cloud-6/submissions/5/123-pricing-document-2015-01-02-0405.pdf' ) uploader.save.assert_called_once_with( 'g-cloud-6/submissions/5/123-pricing-document-2015-01-02-0405.pdf', mock.ANY, acl='public-read' )