def test_put_dimension_adds_to_dimensions(mock_time): # arrange context = MetricsContext() dimension_key = fake.word() dimension_value = fake.word() # act context.put_dimensions({dimension_key: dimension_value}) # assert assert context.dimensions == [{dimension_key: dimension_value}]
def test_create_copy_with_context_does_not_copy_dimensions(): # arrange context = MetricsContext() dimension_key = fake.word() dimension_value = fake.word() context.put_dimensions({dimension_key: dimension_value}) # act new_context = context.create_copy_with_context() # assert assert len(new_context.dimensions) == 0
def test_set_dimensions_overwrites_all_dimensions(): # arrange context = MetricsContext() context.set_default_dimensions({fake.word(): fake.word}) context.put_dimensions({fake.word(): fake.word}) expected_dimensions = {fake.word(): fake.word} # act context.set_dimensions(expected_dimensions) # assert assert context.dimensions == expected_dimensions
def test_create_copy_with_context_copies_dimensions(): # arrange context = MetricsContext() dimension_key = fake.word() dimension_value = fake.word() context.put_dimensions({dimension_key: dimension_value}) # act new_context = context.create_copy_with_context() # assert assert context.dimensions == new_context.dimensions assert context.dimensions is not new_context.dimensions
def test_create_copy_with_context_does_not_repeat_dimensions(): # arrange context = MetricsContext() expected_dimensions = {fake.word(): fake.word()} custom = {fake.word(): fake.word()} context.set_default_dimensions(expected_dimensions) context.put_dimensions(custom) new_context = context.create_copy_with_context() new_context.set_default_dimensions(expected_dimensions) new_context.put_dimensions(custom) # assert assert len(new_context.get_dimensions()) == 1
def test_get_dimensions_returns_only_custom_dimensions_if_default_dimensions_are_empty( ): # arrange context = MetricsContext() dimension_key = fake.word() dimension_value = fake.word() expected_dimensions = {dimension_key: dimension_value} context.set_default_dimensions({}) context.put_dimensions(expected_dimensions) # act actual_dimensions = context.get_dimensions() # assert assert [expected_dimensions] == actual_dimensions
def test_get_dimensions_returns_merged_custom_and_default_dimensions(): # arrange context = MetricsContext() custom_dimension_key = fake.word() custom_dimension_value = fake.word() default_dimension_key = fake.word() default_dimension_value = fake.word() expected_dimensions = { default_dimension_key: default_dimension_value, custom_dimension_key: custom_dimension_value, } context.set_default_dimensions( {default_dimension_key: default_dimension_value}) context.put_dimensions({custom_dimension_key: custom_dimension_value}) # act actual_dimensions = context.get_dimensions() # assert assert [expected_dimensions] == actual_dimensions