def test_is_s3_url(config_mock_fixture): s3 = S3(None, None) file_public_url = "https://inspire/file_prefix/hash123456" wrong_url = "https://inspire/api/hash123456" s3_url = "https://s3.cern.ch/test-prefix-h/hash1234546" assert s3.is_s3_url(file_public_url) is False assert s3.is_s3_url(wrong_url) is False assert s3.is_s3_url(s3_url) is True
def s3(inspire_app, enable_files): mock = mock_s3() mock.start() client = boto3.client("s3") resource = boto3.resource("s3") s3 = S3(client, resource) class MockedInspireS3: s3_instance = s3 real_inspirehep_s3 = inspire_app.extensions["inspirehep-s3"] inspire_app.extensions["inspirehep-s3"] = MockedInspireS3 yield s3 mock.stop() inspire_app.extensions["inspirehep-s3"] = real_inspirehep_s3
def test_convert_public_url_to_s3_url(config_mock_fixture): s3 = S3(None, None) public_url = "https://inspire/file_prefix/hash123456" expected_url = "https://s3.cern.ch/test-prefix-h/hash123456" assert s3.convert_to_s3_url(public_url) == expected_url
def test_generate_s3_file_url_with_bucket_provided(config_mock_fixture): s3 = S3(None, None) expected_url = "https://s3.cern.ch/another-prefix/hash123456" s3_url = s3.get_s3_url("hash123456", "another-prefix") assert s3_url == expected_url assert s3.is_s3_url(s3_url) is True
def test_generate_s3_file_url(config_mock_fixture): s3 = S3(None, None) expected_url = "https://s3.cern.ch/test-prefix-h/hash123456" s3_url = s3.get_s3_url("hash123456") assert s3_url == expected_url assert s3.is_s3_url(s3_url) is True
def test_generate_public_file_url(config_mock_fixture): s3 = S3(None, None) expected_url = "https://inspire/file_prefix/hash123456" public_url = s3.get_public_url("hash123456") assert public_url == expected_url assert s3.is_public_url(public_url) is True
def test_generate_public_file_path(config_mock_fixture): s3 = S3(None, None) assert s3.public_file_path == "https://inspire/file_prefix/"
def s3_instance(self): s3_instance = S3(self.s3_client, self.s3_resource) return s3_instance
def test_is_s3_url_with_bucket_prefix(url, expected, config_mock_fixture): s3 = S3(None, None) assert expected == s3.is_s3_url_with_bucket_prefix(url)
def test_is_s3_url(url, expected, config_mock_fixture): s3 = S3(None, None) assert expected == s3.is_s3_url(url)