def test_split_resource_no_resource_regex_match(): background_resource = { "service": "storage.googleapis.com", # This name will not match the regex associated with the service. "name": "foo/bar/baz", "type": "storage#object", } context = Context(eventType="google.storage.object.finalize", resource=background_resource) with pytest.raises(EventConversionException) as exc_info: event_conversion._split_resource(context) assert "Resource regex did not match" in exc_info.value.args[0]
def test_split_resource_without_service_unknown_event_type(): background_resource = { "name": "projects/_/buckets/some-bucket/objects/folder/Test.cs", "type": "storage#object", } # This event type cannot be mapped to an equivalent CloudEvent type. context = Context(eventType="not_a_known_event_type", resource=background_resource) with pytest.raises(EventConversionException) as exc_info: event_conversion._split_resource(context) assert "Unable to find CloudEvent equivalent service" in exc_info.value.args[ 0]
def test_split_resource(background_resource): context = Context(eventType="google.storage.object.finalize", resource=background_resource) service, resource, subject = event_conversion._split_resource(context) assert service == "storage.googleapis.com" assert resource == "projects/_/buckets/some-bucket" assert subject == "objects/folder/Test.cs"
def test_split_resource_unknown_service_and_event_type(): # With both an unknown service and an unknown event type, we won't attempt any # event type mapping or resource/subject splitting. background_resource = { "service": "not_a_known_service", "name": "projects/_/my/stuff/at/test.txt", "type": "storage#object", } context = Context(eventType="not_a_known_event_type", resource=background_resource) service, resource, subject = event_conversion._split_resource(context) assert service == "not_a_known_service" assert resource == "projects/_/my/stuff/at/test.txt" assert subject == ""