def test_event_local_publish_data_handles_nested_dict_updates_gracefully(self): with mock_response(): cased.publish_key = "cs_test_001" cased.Context.update( { "country": "Austria", "mappings": {"user-one": "123", "user-two": "456"}, } ) Event.publish({"mappings": {"user-three": "789"}}) cased.http.HTTPClient.make_request.assert_called_with( "post", ANY, "cs_test_001", { "mappings": { "user-one": "123", "user-three": "789", "user-two": "456", }, "country": "Austria", "cased_id": ANY, "timestamp": ANY, }, )
def test_event_is_updated_with_context_and_context_cleared_if_set(self): with mock_response(): cased.publish_key = "cs_test_001" cased.clear_context_after_publishing = True cased.Context.update({"country": "Austria"}) Event.publish({"user": "******"}) cased.http.HTTPClient.make_request.assert_called_with( "post", ANY, "cs_test_001", { "user": "******", "country": "Austria", "cased_id": ANY, "timestamp": ANY, }, ) Event.publish({"user": "******"}) cased.http.HTTPClient.make_request.assert_called_with( "post", ANY, "cs_test_001", {"user": "******", "cased_id": ANY, "timestamp": ANY}, )
def test_event_publish_raised_if_publisher_does_not_implement_publish(self): with mock_response(): cased.publish_key = "cs_test_001" empty = EmptyClass() cased.add_publisher(empty) with pytest.raises(PublisherException): Event.publish({"user": "******"})
def test_event_publish_does_not_publish_to_additional_unless_given(self): with mock_response(): cased.publish_key = "cs_test_001" pub = MockPublisher() with patch.object(pub, "publish", wraps=pub.publish) as wrapped_publish: Event.publish({"user": "******"}) # Confirm publish is not called on the added publisher assert not wrapped_publish.called
def test_event_is_extended_with_cased_id_and_timestamp(self): with mock_response(): cased.publish_key = "cs_test_001" Event.publish({"user": "******"}) # Confirm that "cased_id" and "timestamp" have been added to the request cased.http.HTTPClient.make_request.assert_called_with( "post", ANY, "cs_test_001", {"user": "******", "cased_id": ANY, "timestamp": ANY}, )
def test_event_publish_publishes_to_additional(self): with mock_response(): cased.publish_key = "cs_test_001" pub = MockPublisher() cased.add_publisher(pub) with patch.object(pub, "publish", wraps=pub.publish) as wrapped_publish: Event.publish({"user": "******"}) # Confirm publish is called on the added publisher wrapped_publish.assert_called_with( {"user": "******", "cased_id": ANY, "timestamp": ANY} )
def test_event_local_publish_data_handles_deeply_nested_updates(self): with mock_response(): cased.publish_key = "cs_test_001" cased.Context.update( { "mappings": {"user-one": "123", "user-two": "456"}, "location": { "country": "test-country-1", "divisions": [ "test-division-1", "test-division-2", "test-division-3", ], }, } ) Event.publish( { "mappings": {"user-three": "789"}, "location": {"city": "test-city-1"}, } ) cased.http.HTTPClient.make_request.assert_called_with( "post", ANY, "cs_test_001", { "mappings": { "user-one": "123", "user-three": "789", "user-two": "456", }, "location": { "city": "test-city-1", "country": "test-country-1", "divisions": [ "test-division-1", "test-division-2", "test-division-3", ], }, "cased_id": ANY, "timestamp": ANY, }, )
def test_event_can_still_publish_with_reliability_engine_misconfigured_per_request( self, ): with mock_response(): cased.publish_key = "cs_test_001" cased.reliability_backend = None assert Event.publish({"user": "******"}, backend="nothere").status_code == 200
def test_event_local_publish_data_takes_precedence_over_context(self): with mock_response(): cased.publish_key = "cs_test_001" cased.Context.update({"country": "Austria", "user": "******"}) Event.publish({"user": "******"}) cased.http.HTTPClient.make_request.assert_called_with( "post", ANY, "cs_test_001", { "user": "******", "country": "Austria", "cased_id": ANY, "timestamp": ANY, }, )
def test_event_can_publish_with_reliability_engine_configured_per_request(self): with mock_response(): cased.publish_key = "cs_test_001" cased.reliability_backend = None assert ( Event.publish( {"user": "******"}, backend=SimpleReliabilityBackend ).status_code == 200 )
def test_event_can_be_configured_to_not_publish(self): with mock_response(): cased.publish_key = "cs_test_001" cased.disable_publishing = True assert Event.publish({"user": "******"}) is None
def test_event_can_publish(self): with mock_response(): cased.publish_key = "cs_test_001" assert Event.publish({"user": "******"}).status_code == 200