def test_load_many_when_relationship_is_none(self): attr = attributes.Relationship('Attr', related_model=RelatedModel, many=True) self.assertEqual(attr.load(None), [])
class Loaded(ModelBase): id = attributes.Integer('Id') one = attributes.Relationship('One', related_model=LoadedToOne) many = attributes.Relationship('Many', related_model=LoadedToMany, many=True)
def test_load(self): attr = attributes.Relationship('Attr', related_model=RelatedModel) data = {'attributes': {'type': 'RelatedModel'}, 'Id': 1} self.assertEqual(attr.load(data), RelatedModel.load({'Id': 1}))
def test_load_many(self): attr = attributes.Relationship('Attr', related_model=RelatedModel, many=True) data = {'records': [{'attributes': {'type': 'RelatedModel'}, 'Id': 1}]} self.assertEqual(attr.load(data), [RelatedModel.load({'Id': 1})])
import unittest from soql import attributes from soql import Model from soql.path_builder import PathBuilder from tests.helpers import SoqlAssertions # Declare the relationships separately so we can assert some stuff in the tests # more easily... next_ = attributes.Relationship('Next', related_model='LinkedList') list_ = attributes.Relationship('List', related_model='LinkedList') children = attributes.Relationship('Children', related_model='GraphNode', many=True) class LinkedList(Model): id = attributes.Integer('Id') next = next_ class GraphNode(Model): id = attributes.Integer('Id') value = attributes.Integer('Value') list = list_ children = children class PathBuilderTest(unittest.TestCase, SoqlAssertions): def assertColumnNodesEqual(self, node_list, expected): self.assertEqual(sorted([str(node) for node in node_list]),
class AllZeRelationships(Model): parent = attributes.Relationship('Parent', related_model=AParent) children = attributes.Relationship('Children', related_model=AChild, many=True)
class AChild(Model): id = attributes.Integer('Id') name = attributes.String('Name') mom = attributes.Relationship('Mom', related_model=AParent)
class Bar(Model): foos = attributes.Relationship('Foos', related_model=Foo, many=True)
class Foo(Model): bar = attributes.Relationship('Bar', related_model='Bar')