def test_empty_list(self,): class RelatedResource2(ResourceBase): pass list_name = 'mylist' lr = ListRelationship(list_name, relation='RelatedResource') res_list = lr.construct_resource(dict(some='thing', another='thing')) self.assertIsInstance(res_list, list) self.assertEqual(len(res_list), 0)
def test_init(self): """ Tests the initialization of the ListRelationship """ list_name = 'mylist' lr = ListRelationship(list_name, relation='MyResource', embedded=True) self.assertEqual(list_name, lr.name) self.assertTrue(lr.embedded) self.assertEqual(lr._relation, 'MyResource')
def relationships(cls): """ Appends the ListRelationship relationship that corresponds to the items returned. :return: The relationships on the class plus the cls.__name__ :rtype: tuple """ relationships = cls._relationships or tuple() return relationships + (ListRelationship(cls.resource_name, relation=cls.__name__),)
def test_remove_child_properties(self): """ Test remove child properties """ list_name = 'listname' properties = {list_name: 'Something', 'another': 'thing'} lr = ListRelationship(list_name) post_props = lr.remove_child_resource_properties(properties) self.assertNotEqual(properties, post_props) self.assertEqual({'another': 'thing'}, post_props) # Just make sure that it still works when the properties aren't there part2 = lr.remove_child_resource_properties(post_props) self.assertEqual(part2, post_props) self.assertNotEqual(id(part2), id(post_props))
def test_construct_resource(self): class RelatedResource(ResourceBase): _pks = ['pk'] list_name = 'mylist' lr = ListRelationship(list_name, relation='RelatedResource') props = {list_name: []} for i in range(10): props[list_name].append(dict(pk=i)) res_list = lr.construct_resource(props) self.assertIsInstance(res_list, list) for x in res_list: # TODO actually check this pass self.assertEqual(len(res_list), 10)