示例#1
0
def test_LinkList__init_iterator(linklist):
    ll_iterated, objs = linklist
    ctor_arg = [(v, v._kwargs) for k, v in objs.iteritems()]
    ll_ctor = RNU.LinkList(ctor_arg)
    assert ll_iterated == ll_ctor
    # Non black-box test warning!
    assert ll_iterated._meta == ll_ctor._meta
示例#2
0
 def make_nav(link):
     '''Crafts the Navigators for each link'''
     if isinstance(link, list):
         return utils.LinkList((make_nav(lnk), lnk) for lnk in link)
     templated = link.get('templated', False)
     if not templated:
         uri = urlparse.urljoin(self.uri, link['href'])
         template_uri = None
     else:
         uri = None
         template_uri = urlparse.urljoin(self.uri, link['href'])
     cp = self._copy(
         uri=uri,
         template_uri=template_uri,
         templated=templated,
         title=link.get('title'),
         type=link.get('type'),
         profile=link.get('profile'),
     )
     if templated:
         cp.uri = None
         cp.parameters = uritemplate.variables(cp.template_uri)
     else:
         cp.template_uri = None
     return cp
示例#3
0
def linklist(blank):
    linklist = RNU.LinkList()
    objs = collections.OrderedDict([
        ('A.a', blank(name='A.a', klass='A', id='a')),
        ('A.b', blank(name='A.b', klass='A', id='b')),
        ('A.c', blank(name='A.c')),
        ('B.a', blank(name='B.a', klass='B', id='a')),
        ('B.b', blank(id='b')),
        ('C.a', blank(name='C.a', klass='C', id='a')),
        ('C.b', blank(klass='C', id='b')),
    ])
    for i, obj in enumerate(objs.values()):
        linklist.append_with(obj, **obj._kwargs)
    return linklist, objs
示例#4
0
def test_LinkList__append_with_get_by_one(blank):
    linklist = RNU.LinkList()
    obj = blank()
    linklist.append_with(obj, name='myobject', title='My Object')
    assert linklist.get_by('name', 'myobject') == obj
    assert linklist.get_by('title', 'My Object') == obj
示例#5
0
def test_LinkList__get_by_unicode_valu():
    unicode_value = u'クリーガーさんは、私の桜がしおれている!'
    prop_list = [('VALUE', {'title': unicode_value})]
    test_list = RNU.LinkList(prop_list)
    assert test_list.get_by('title', unicode_value) == 'VALUE'
示例#6
0
def test_LinkList__named_unhashable():
    bad_value = {'totally': ['bad', 'key']}  # This normally should be hashable
    prop_list = [('STILL_GOT_IT', {'name': bad_value})]
    test_list = RNU.LinkList(prop_list)
    assert test_list.named(bad_value) == 'STILL_GOT_IT'
示例#7
0
def test_LinkList__getall_by_unhashable(unhashable_prop):
    prop_list, bad_value = unhashable_prop
    test_list = RNU.LinkList(prop_list)
    assert test_list.getall_by('bad', bad_value) == ['B']
示例#8
0
def test_LinkList__get_by_unhashable_is_string(unhashable_prop):
    prop_list, bad_value = unhashable_prop
    test_list = RNU.LinkList(prop_list)
    assert test_list.get_by('bad', str(bad_value)) == 'B'
示例#9
0
def test_LinkList__getby_failure():
    ll = RNU.LinkList()
    assert ll.get_by('name', 'XXX') is None