示例#1
0
def test_to_json(experiments_yaml_obj):
    event = YamlEvent.from_yaml(experiments_yaml_obj)
    event_properties = {}
    for p in experiments_yaml_obj['properties']:
        event_properties[p['name']] = YamlProperty.from_yaml(p).to_json()

    expected = {
        'version': 1,
        'name': 'Experiment Enrolled',
        'description': 'Track whom has been added to an A/B Test Experiment',
        'rules': {
            'labels': {
                'area': 'experiments'
            },
            'properties': {
                'context': {},
                'traits': {},
                'properties': {
                    'type': 'object',
                    'properties': event_properties,
                    'required': ['experiment']
                }
            },
            'required': ['properties'],
            '$schema': 'http://json-schema.org/draft-07/schema#',
            'type': 'object'
        }
    }

    actual = event.to_json()
    assert expected == actual
示例#2
0
def test_parsing_properties(experiments_yaml_obj):
    event = YamlEvent.from_yaml(experiments_yaml_obj)

    assert len(event.properties) == 2
    experiment_property = event.properties[0]

    assert type(experiment_property) == YamlProperty
    assert experiment_property.name == 'experiment'
示例#3
0
def test_to_json_events(tracking_plan_yaml, tracking_plan_event_yaml):
    plan = YamlTrackingPlan(tracking_plan_yaml)
    plan.add_event(tracking_plan_event_yaml)

    json_plan = plan.to_json()

    assert len(json_plan['rules']['events']) == 1

    expected = YamlEvent.from_yaml(tracking_plan_event_yaml).to_json()
    actual = json_plan['rules']['events'][0]
    assert actual == expected
示例#4
0
def test_loader_events(tmpdir):
    _create_plan_file(tmpdir)
    _create_events(tmpdir)

    loader = PlanLoader(tmpdir)
    yaml_event_obj = yaml.safe_load(EVENT_FILE)
    expected = YamlEvent.from_yaml(yaml_event_obj)
    events = loader.plan.events

    assert len(events) == 1
    actual = events[0]
    assert expected.name == actual.name
示例#5
0
 def add_event(self, event_yaml):
     event = YamlEvent(event_yaml)
     self._events.append(event)
     self.validate()
示例#6
0
def test_parsing_tags(tag_created_yaml_obj):
    event = YamlEvent.from_yaml(tag_created_yaml_obj)
    actual = event.to_json()['rules']['labels']

    assert actual['area'] == 'product'
    assert actual['product'] == 'reply'
示例#7
0
def test_parsing_top_level_attrs(experiments_yaml_obj):
    event = YamlEvent.from_yaml(experiments_yaml_obj)

    assert event.area == 'experiments'
    assert event.description == 'Track whom has been added to an A/B Test Experiment'
    assert event.name == 'Experiment Enrolled'
示例#8
0
def test_valid_name(tag_created_yaml_obj):
    tag_created_yaml_obj['name'] = 'Foo bar'

    with assert_raises_validation_error('Foo bar is not a valid event name'):
        YamlEvent(tag_created_yaml_obj)
示例#9
0
def test_duplicate_properties(dup_properties_yaml_obj):
    with assert_raises_validation_error(
            f'Duplicate properties found on event Foo Created. Properties: foo'
    ):
        YamlEvent.from_yaml(dup_properties_yaml_obj)