def test_upload_with_validation_errors(self):
        request_files = {'modernSlaveryStatement': MockFile(b"*" * 100, 'q1.bad')}

        files, errors = upload_declaration_documents(
            self.uploader, 'documents', self.documents_url,
            request_files, self.section,
            'g-cloud-11', 12345
        )

        assert files is None
        assert 'modernSlaveryStatement' in errors
    def test_empty_files_are_filtered(self):
        request_files = {'modernSlaveryStatement': MockFile(b"", 'q1.pdf')}

        files, errors = upload_declaration_documents(
            self.uploader, 'documents', self.documents_url,
            request_files, self.section,
            'g-cloud-11', 12345
        )

        assert len(files) == 0
        assert len(errors) == 0
    def test_only_files_in_section_are_uploaded(self):
        request_files = {'serviceDefinitionDocumentURL': MockFile(b"*" * 100, 'q1.pdf')}

        files, errors = upload_declaration_documents(
            self.uploader, 'documents', self.documents_url,
            request_files, self.section,
            'g-cloud-11', 12345
        )

        assert len(files) == 0
        assert len(errors) == 0
    def test_upload_declaration_documents(self):
        request_files = {'modernSlaveryStatement': self.test_pdf}

        with freeze_time('2015-10-04 14:36:05'):
            files, errors = upload_declaration_documents(
                self.uploader, 'documents', self.documents_url,
                request_files, self.section,
                'g-cloud-11', 12345
            )

        self.uploader.save.assert_called_with(
            'g-cloud-11/documents/12345/modern-slavery-statement-2015-10-04-1436.pdf', mock.ANY, acl='public-read')

        assert 'modernSlaveryStatement' in files
        assert len(errors) == 0