Пример #1
0
def test_keys():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    db.local_aliases.add('local_alias')
    assert set(db.keys()) == set(['foo', 'bar', 'local_alias'])
Пример #2
0
def test_is_local():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
    })
    db.local_aliases.add('local_alias')

    assert not db.is_local('foo')
    assert db.is_local('local_alias')
Пример #3
0
def test_filter_from_mapping_empty_search():
    aliases = {
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
        'baz': Mapping(mapping=(2, 3), backend='test'),
    }
    db = AliasesDatabase(aliases)

    assert db.filter_from_mapping(None) == aliases
Пример #4
0
def test_filter_from_mapping_empty_search():
    aliases = {
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
        'baz': Mapping(mapping=(2, 3), backend='test'),
    }
    db = AliasesDatabase(aliases)

    assert db.filter_from_mapping('') == aliases
Пример #5
0
def test_filter_from_mapping():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
        'baz': Mapping(mapping=(2, 3), backend='test'),
    })
    assert db.filter_from_mapping((1, 3)) == {
        'bar': Mapping(mapping=(1, 3), backend='test')
    }
Пример #6
0
def test_filter_from_mapping():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
        'baz': Mapping(mapping=(2, 3), backend='test'),
    })
    assert db.filter_from_mapping((1, 3)) == {
        'bar': Mapping(mapping=(1, 3), backend='test')
    }
Пример #7
0
def test_get_reversed_aliases():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    reversed_aliases = db.get_reversed_aliases().items()

    assert set(reversed_aliases) == set([
        (Mapping(mapping=(1, 2), backend='test'), 'foo'),
        (Mapping(mapping=(1, 3), backend='test'), 'bar'),
    ])
Пример #8
0
def test_get_reversed_aliases():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    reversed_aliases = db.get_reversed_aliases().items()

    assert set(reversed_aliases) == set([
        (Mapping(mapping=(1, 2), backend='test'), 'foo'),
        (Mapping(mapping=(1, 3), backend='test'), 'bar'),
    ])
Пример #9
0
def test_alias_iteritems():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    alias_set = set(db.iteritems())

    assert alias_set == set([
        ('foo', Mapping(mapping=(1, 2), backend='test')),
        ('bar', Mapping(mapping=(1, 3), backend='test')),
    ])
Пример #10
0
def test_alias_iteritems():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    alias_set = set(db.iteritems())

    assert alias_set == set([
        ('foo', Mapping(mapping=(1, 2), backend='test')),
        ('bar', Mapping(mapping=(1, 3), backend='test')),
    ])
Пример #11
0
def test_filter_from_alias():
    aliases = {
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'foobar': Mapping(mapping=(1, 3), backend='test'),
        'baz': Mapping(mapping=(2, 3), backend='test'),
    }
    db = AliasesDatabase(aliases)

    assert db.filter_from_alias('foo') == {
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'foobar': Mapping(mapping=(1, 3), backend='test'),
    }
Пример #12
0
def test_filter_from_alias():
    aliases = {
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'foobar': Mapping(mapping=(1, 3), backend='test'),
        'baz': Mapping(mapping=(2, 3), backend='test'),
    }
    db = AliasesDatabase(aliases)

    assert db.filter_from_alias('foo') == {
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'foobar': Mapping(mapping=(1, 3), backend='test'),
    }
Пример #13
0
def test_update():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    db.update({
        'foo': Mapping(mapping=(2, 2), backend='test'),
        'baz': Mapping(mapping=(9, 9), backend='test'),
    })

    assert set(db.iteritems()) == set([
        ('foo', Mapping(mapping=(2, 2), backend='test')),
        ('bar', Mapping(mapping=(1, 3), backend='test')),
        ('baz', Mapping(mapping=(9, 9), backend='test')),
    ])
Пример #14
0
def test_update():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    db.update({
        'foo': Mapping(mapping=(2, 2), backend='test'),
        'baz': Mapping(mapping=(9, 9), backend='test'),
    })

    assert set(db.iteritems()) == set([
        ('foo', Mapping(mapping=(2, 2), backend='test')),
        ('bar', Mapping(mapping=(1, 3), backend='test')),
        ('baz', Mapping(mapping=(9, 9), backend='test')),
    ])
Пример #15
0
def test_alias_iter():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    alias_set = set(db)

    assert alias_set == set(['foo', 'bar'])
Пример #16
0
def test_alias_not_in():
    db = AliasesDatabase({'foo': Mapping(mapping=(1, 2), backend='test')})
    assert 'bar' not in db
Пример #17
0
def test_reset():
    db = AliasesDatabase({'foo': Mapping(mapping=(1, 2), backend='test')})
    db.reset()

    assert 'foo' not in db
Пример #18
0
def test_keys():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    assert set(db.keys()) == set(['foo', 'bar'])
Пример #19
0
def test_alias_add_item():
    db = AliasesDatabase({'foo': Mapping(mapping=(1, 2), backend='test')})
    db['bar'] = Mapping(mapping=(2, 2), backend='test')

    assert db['foo'].mapping == (1, 2)
    assert db['bar'].mapping == (2, 2)
Пример #20
0
def test_keys():
    db = AliasesDatabase({
        'foo': Mapping(mapping=(1, 2), backend='test'),
        'bar': Mapping(mapping=(1, 3), backend='test'),
    })
    assert set(db.keys()) == set(['foo', 'bar'])
Пример #21
0
def test_reset():
    db = AliasesDatabase({'foo': Mapping(mapping=(1, 2), backend='test')})
    db.reset()

    assert 'foo' not in db