def test_shutdown_before_load_throws_error() -> None: itly = Itly() with pytest.raises(Exception) as ctx: itly.shutdown() assert str( ctx.value ) == 'Itly is not yet initialized. Have you called `itly.load()` on app start?'
def test_track_before_load_throws_error() -> None: itly = Itly() with pytest.raises(Exception) as ctx: itly.track('user-id', Event("event")) assert str( ctx.value ) == 'Itly is not yet initialized. Have you called `itly.load()` on app start?'
def test_page_before_load_throws_error() -> None: itly = Itly() with pytest.raises(Exception) as ctx: itly.page('user-id', 'category', 'name') assert str( ctx.value ) == 'Itly is not yet initialized. Have you called `itly.load()` on app start?'
def test_group_before_load_throws_error() -> None: itly = Itly() with pytest.raises(Exception) as ctx: itly.group('user-id', 'group-id') assert str( ctx.value ) == 'Itly is not yet initialized. Have you called `itly.load()` on app start?'
def test_track_after_shutdown_throws_error() -> None: itly = Itly() itly.load() itly.shutdown() with pytest.raises(Exception) as ctx: itly.track('user-id', Event("event")) assert str(ctx.value) == 'Itly is shutdown. No more requests are possible.'
def test_double_shutdown_throws_exception() -> None: itly = Itly() itly.load() itly.shutdown() with pytest.raises(Exception) as ctx: itly.shutdown() assert str(ctx.value) == 'Itly is shutdown. No more requests are possible.'
def test_double_load_throws_exception() -> None: itly = Itly() itly.load() with pytest.raises(Exception) as ctx: itly.load() assert str( ctx.value ) == 'Itly is already initialized. itly.load() should only be called once.'
def test_group_with_properties_succeeds() -> None: itly = Itly() logger = CustomLogger() itly.load(context=Properties(context_property=1), options=Options(logger=logger, plugins=[CustomPlugin()])) itly.group('user-id', 'group-id', Properties(required_boolean=True, )) log_text = '\n'.join(logger.log_lines) assert log_text == """[itly-core] load()
def test_identify_with_properties_succeeds() -> None: itly = Itly() logger = CustomLogger() itly.load(context=Properties(context_property=1), options=Options(logger=logger, plugins=[CustomPlugin()])) itly.identify('user-id', Properties(required_number=42.0, )) log_text = '\n'.join(logger.log_lines) assert log_text == """[itly-core] load()
def _check_validation_results( environment: Environment, validation_results: List[Tuple[ValidationOptions, Optional[str], str]] ) -> None: for validation_options, error_text, expected_log in validation_results: itly = Itly() logger = CustomLogger() itly.load( None, Options(environment=environment, logger=logger, plugins=[CustomPlugin()], validation=validation_options), ) if error_text is not None: with pytest.raises(Exception) as ctx: itly.track('user-id', Event("event", Properties(invalid=True))) assert str(ctx.value) == error_text else: itly.track('user-id', Event("event", Properties(invalid=True))) log_text = '\n'.join(logger.log_lines) assert expected_log == log_text
def test_load_default_options_succeeds() -> None: itly = Itly() itly.load()
def test_events_disabled() -> None: user_id = 'test-user-id' itly = Itly() logger = CustomLogger() itly.load( context=Properties( requiredString='A required string', optionalEnum=OptionalEnum.Value1, ), options=Options( environment=Environment.PRODUCTION, plugins=[CustomPlugin()], logger=logger, disabled=True, ), ) itly.identify('user-id', Properties(user_prop=1)) itly.alias(user_id, 'user-id') itly.group(user_id, 'a-group-id', Properties(group_prop='test value')) itly.page(user_id, 'page category', 'page name', Properties(page_prop='a page property')) itly.track(user_id, Event('Event No Properties')) itly.track( user_id, Event( 'Event With All Properties', Properties( required_string='A required string', required_number=2.0, required_integer=42, required_enum=RequiredEnum.Enum1, required_boolean=False, required_const='some-const-value', required_array=['required', 'array'], optional_string="I'm optional!", ))) itly.flush() itly.track(user_id, Event('EventMaxIntForTest', Properties(int_max_10=20, ))) itly.flush() itly.shutdown() log_text = '\n'.join(logger.log_lines) assert log_text == '''[itly-core] disabled = True'''