@@ -453,6 +453,7 @@ def test_track(self, mocker):
453453 factory_destroyed = mocker .PropertyMock ()
454454 factory_destroyed .return_value = False
455455 type(factory_mock ).destroyed = factory_destroyed
456+ factory_mock ._apikey = 'some-test'
456457
457458 client = Client (factory_mock )
458459 client ._events_storage = mocker .Mock (spec = EventStorage )
@@ -602,6 +603,50 @@ def test_track(self, mocker):
602603 mocker .call ("track: value must be a number." )
603604 ]
604605
606+ # Test traffic type existance
607+ ready_property = mocker .PropertyMock ()
608+ ready_property .return_value = True
609+ type(factory_mock ).ready = ready_property
610+
611+ split_storage_mock = mocker .Mock (spec = SplitStorage )
612+ split_storage_mock .is_valid_traffic_type .return_value = True
613+ factory_mock ._get_storage .return_value = split_storage_mock
614+
615+ # Test that it doesn't warn if tt is cached, not in localhost mode and sdk is ready
616+ client ._logger .reset_mock ()
617+ assert client .track ("some_key" , "traffic_type" , "event_type" , None ) is True
618+ assert client ._logger .error .mock_calls == []
619+ assert client ._logger .warning .mock_calls == []
620+
621+ # Test that it does warn if tt is cached, not in localhost mode and sdk is ready
622+ split_storage_mock .is_valid_traffic_type .return_value = False
623+ client ._logger .reset_mock ()
624+ assert client .track ("some_key" , "traffic_type" , "event_type" , None ) is True
625+ assert client ._logger .error .mock_calls == []
626+ assert client ._logger .warning .mock_calls == [mocker .call (
627+ 'track: Traffic Type %s does not have any corresponding Splits in this environment, '
628+ 'make sure you\' re tracking your events to a valid traffic type defined '
629+ 'in the Split console.' ,
630+ 'traffic_type'
631+ )]
632+
633+ # Test that it does not warn when in localhost mode.
634+ factory_mock ._apikey = 'localhost'
635+ client ._logger .reset_mock ()
636+ assert client .track ("some_key" , "traffic_type" , "event_type" , None ) is True
637+ assert client ._logger .error .mock_calls == []
638+ assert client ._logger .warning .mock_calls == []
639+
640+ # Test that it does not warn when not in localhost mode and not ready
641+ factory_mock ._apikey = 'not-localhost'
642+ ready_property .return_value = False
643+ type(factory_mock ).ready = ready_property
644+ client ._logger .reset_mock ()
645+ assert client .track ("some_key" , "traffic_type" , "event_type" , None ) is True
646+ assert client ._logger .error .mock_calls == []
647+ assert client ._logger .warning .mock_calls == []
648+
649+
605650 def test_get_treatments (self , mocker ):
606651 """Test getTreatments() method."""
607652 split_mock = mocker .Mock (spec = Split )
0 commit comments