Beispiel #1
0
def test_dynamic_segment_with_non_static_rules_have_a_count():
    segment = SegmentFactory.build(type=Segment.TYPE_DYNAMIC, count=0)
    rule = TimeRule(
        start_time=datetime.time(0, 0, 0),
        end_time=datetime.time(23, 59, 59),
    )
    form = form_with_data(segment, rule)
    assert form.is_valid(), form.errors
Beispiel #2
0
def test_non_static_rules_have_a_count():
    segment = SegmentFactory.build(type=Segment.TYPE_STATIC, count=0)
    rule = TimeRule(
        start_time=datetime.time(0, 0, 0),
        end_time=datetime.time(23, 59, 59),
        segment=segment,
    )
    form = form_with_data(segment, rule)
    assert not form.is_valid()
def test_create_segment_factory():
    factoried_segment = SegmentFactory()
    segment = Segment(name='TestSegment', status='enabled')
    TimeRule(start_time=datetime.time(8, 0, 0),
             end_time=datetime.time(23, 0, 0),
             segment=segment)

    assert factoried_segment.name == segment.name
    assert factoried_segment.status == segment.status
Beispiel #4
0
def test_sessions_not_added_to_static_segment_if_rule_not_static(mocker):
    segment = SegmentFactory.build(type=Segment.TYPE_STATIC, count=1)
    rule = TimeRule(
        start_time=datetime.time(0, 0, 0),
        end_time=datetime.time(23, 59, 59),
        segment=segment,
    )
    form = form_with_data(segment, rule)
    mock_test_rule = mocker.patch(
        'wagtail_personalisation.adapters.SessionSegmentsAdapter._test_rules')
    instance = form.save()

    assert not instance.static_users.all()
    assert mock_test_rule.call_count == 0
Beispiel #5
0
def test_mixed_static_dynamic_session_doesnt_generate_at_creation(
        site, mocker):
    segment = SegmentFactory.build(type=Segment.TYPE_STATIC, count=1)
    static_rule = VisitCountRule(counted_page=site.root_page)
    non_static_rule = TimeRule(
        start_time=datetime.time(0, 0, 0),
        end_time=datetime.time(23, 59, 59),
    )
    form = form_with_data(segment, static_rule, non_static_rule)

    mock_test_rule = mocker.patch(
        'wagtail_personalisation.adapters.SessionSegmentsAdapter._test_rules')
    instance = form.save()

    assert not instance.static_users.all()
    assert mock_test_rule.call_count == 0
Beispiel #6
0
def test_count_matching_users_only_counts_static_rules(site, client, mocker,
                                                       django_user_model):
    django_user_model.objects.create(username='******')
    django_user_model.objects.create(username='******')

    segment = SegmentFactory.build(type=Segment.TYPE_STATIC)
    rule = TimeRule(
        start_time=datetime.time(0, 0, 0),
        end_time=datetime.time(23, 59, 59),
        segment=segment,
    )
    form = form_with_data(segment, rule)
    mock_test_user = mocker.patch(
        'wagtail_personalisation.rules.TimeRule.test_user')

    assert form.count_matching_users([rule], True) is 0
    assert mock_test_user.call_count == 0
def test_mixed_static_dynamic_session_doesnt_generate_at_creation(
        site, client, user):
    session = client.session
    session.save()
    client.force_login(user)
    client.get(site.root_page.url)

    segment = SegmentFactory.build(type=Segment.TYPE_STATIC, count=1)
    static_rule = VisitCountRule(counted_page=site.root_page)
    non_static_rule = TimeRule(
        start_time=datetime.time(0, 0, 0),
        end_time=datetime.time(23, 59, 59),
    )
    form = form_with_data(segment, static_rule, non_static_rule)
    instance = form.save()

    assert not instance.static_users.all()
def test_sessions_not_added_to_static_segment_if_rule_not_static(
        client, site, user):
    session = client.session
    session.save()
    client.force_login(user)
    client.get(site.root_page.url)

    segment = SegmentFactory.build(type=Segment.TYPE_STATIC, count=1)
    rule = TimeRule(
        start_time=datetime.time(0, 0, 0),
        end_time=datetime.time(23, 59, 59),
        segment=segment,
    )
    form = form_with_data(segment, rule)
    instance = form.save()

    assert not instance.static_users.all()
Beispiel #9
0
def test_segment_create():
    segment = SegmentFactory()
    TimeRule(start_time=datetime.time(8, 0, 0),
             end_time=datetime.time(23, 0, 0),
             segment=segment)