示例#1
0
def test_kcl_drops_events_with_no_matching_records(match_buckets_a_resource):
    client = mock.Mock()
    listener = KintoChangesListener(client, 'broadcaster', [], [], match_buckets_a_resource)
    single_record = [
        {'new': changes_record('b', 'c')},
    ]
    request = DummyRequest()
    event = events.ResourceChanged(PAYLOAD, single_record, request)

    listener(event)
    assert not client.send_version.called
示例#2
0
def test_kcl_ignores_missing_new(match_buckets_a_resource):
    client = mock.Mock()
    listener = KintoChangesListener(client, 'broadcaster', [], [], match_buckets_a_resource)
    single_record = [
        {'old': changes_record('a', 'c')},
    ]
    request = DummyRequest()
    event = events.ResourceChanged(PAYLOAD, single_record, request)

    listener(event)
    assert not client.send_version.called
示例#3
0
def test_kcl_can_fail_to_match_in_collections(match_collection_z1_resource):
    client = mock.Mock()
    listener = KintoChangesListener(client, 'broadcaster', [], [],
                                    match_collection_z1_resource)
    one_record = [
        {'new': changes_record('z', 'z2')},
    ]
    request = DummyRequest()
    event = events.ResourceChanged(PAYLOAD, one_record, request)

    listener(event)
    assert not client.send_version.called
示例#4
0
def test_kcl_posts_on_matching_records(match_buckets_a_resource):
    client = mock.Mock()
    listener = KintoChangesListener(client, 'broadcaster', [], [],
                                    match_buckets_a_resource)
    single_record = [
        {'new': changes_record('a', 'c')},
    ]
    request = DummyRequest()
    event = events.ResourceChanged(PAYLOAD, single_record, request)

    listener(event)
    client.send_version.assert_called_with('broadcaster', 'monitor_changes', '"123"')
示例#5
0
def test_kcl_can_match_in_collections(match_collection_z1_resource):
    client = mock.Mock()
    listener = KintoChangesListener(client, 'broadcaster', [], [],
                                    match_collection_z1_resource)
    one_record = [
        {'new': changes_record('z', 'z1')},
    ]
    request = DummyRequest()
    request.route_path.return_value = "/buckets/z/collections/z1"
    event = events.ResourceChanged(PAYLOAD, one_record, request)

    listener(event)
    client.send_version.assert_called_with('broadcaster', 'monitor_changes', '"123"')
示例#6
0
def test_kcl_ignores_writes_not_on_records(match_buckets_a_resource):
    client = mock.Mock()
    listener = KintoChangesListener(client, 'broadcaster', [], [], match_buckets_a_resource)
    payload = {
        **PAYLOAD,
        'resource_name': 'collection',
    }
    single_record = [
        {'new': changes_record('a', 'c')}
    ]
    request = DummyRequest()
    event = events.ResourceChanged(payload, single_record, request)

    listener(event)
    assert not client.send_version.called
示例#7
0
def test_kinto_changes_ignores_not_monitor_changes(match_buckets_a_resource):
    client = mock.Mock()
    listener = KintoChangesListener(client, 'broadcaster', [], [], match_buckets_a_resource)
    payload = {
        **PAYLOAD,
        'bucket_id': 'food',
        'collection_id': 'french',
    }
    single_record = [
        {'new': {'id': 'abcd'}}
    ]
    request = DummyRequest()
    event = events.ResourceChanged(payload, single_record, request)

    listener(event)
    assert not client.send_version.called
示例#8
0
def test_excluding_resources(kinto_changes_settings):
    client = mock.Mock()
    listener = KintoChangesListener(client, 'broadcaster', [], [])
    listener.included_resources = [
        ('bucket', {'id': 'a'}),
        ('collection', {'bucket_id': 'b', 'id': 'd'}),
        ('collection', {'bucket_id': 'z', 'id': 'z1'}),
    ]
    listener.excluded_resources = [
        ('bucket', {'id': 'b'}),
        ('collection', {'bucket_id': 'a', 'id': 'c'}),
        ('collection', {'bucket_id': 'z', 'id': 'z2'}),
    ]
    request = DummyRequest()

    client.reset_mock()
    event = events.ResourceChanged(PAYLOAD, [{'new': changes_record('a', 'c')}], request)
    listener(event)
    assert not client.send_version.called

    client.reset_mock()
    event = events.ResourceChanged(PAYLOAD, [{'new': changes_record('b', 'x')}], request)
    listener(event)
    assert not client.send_version.called

    client.reset_mock()
    event = events.ResourceChanged(PAYLOAD, [{'new': changes_record('a', 'd')}], request)
    listener(event)
    assert client.send_version.called

    client.reset_mock()
    event = events.ResourceChanged(PAYLOAD, [{'new': changes_record('z', 'z1')}], request)
    listener(event)
    assert client.send_version.called

    client.reset_mock()
    event = events.ResourceChanged(PAYLOAD, [{'new': changes_record('a', 'z2')}], request)
    listener(event)
    assert client.send_version.called

    client.reset_mock()
    event = events.ResourceChanged(PAYLOAD, [{'new': changes_record('x', 'z1')}], request)
    listener(event)
    assert not client.send_version.called