(self)
| 43 | ) |
| 44 | |
| 45 | def test_basic(self): |
| 46 | table2, table1 = self.tables.table2, self.tables.table1 |
| 47 | |
| 48 | Session = scoped_session(sa.orm.sessionmaker(testing.db)) |
| 49 | |
| 50 | class CustomQuery(query.Query): |
| 51 | pass |
| 52 | |
| 53 | class SomeObject(ComparableEntity): |
| 54 | query = Session.query_property() |
| 55 | |
| 56 | class SomeOtherObject(ComparableEntity): |
| 57 | query = Session.query_property() |
| 58 | custom_query = Session.query_property(query_cls=CustomQuery) |
| 59 | |
| 60 | self.mapper_registry.map_imperatively( |
| 61 | SomeObject, |
| 62 | table1, |
| 63 | properties={class="st">"options": relationship(SomeOtherObject)}, |
| 64 | ) |
| 65 | self.mapper_registry.map_imperatively(SomeOtherObject, table2) |
| 66 | |
| 67 | s = SomeObject(id=1, data=class="st">"hello") |
| 68 | sso = SomeOtherObject() |
| 69 | s.options.append(sso) |
| 70 | Session.add(s) |
| 71 | Session.commit() |
| 72 | Session.refresh(sso) |
| 73 | Session.remove() |
| 74 | |
| 75 | eq_( |
| 76 | SomeObject( |
| 77 | id=1, data=class="st">"hello", options=[SomeOtherObject(someid=1)] |
| 78 | ), |
| 79 | Session.query(SomeObject).one(), |
| 80 | ) |
| 81 | eq_( |
| 82 | SomeObject( |
| 83 | id=1, data=class="st">"hello", options=[SomeOtherObject(someid=1)] |
| 84 | ), |
| 85 | SomeObject.query.one(), |
| 86 | ) |
| 87 | eq_( |
| 88 | SomeOtherObject(someid=1), |
| 89 | SomeOtherObject.query.filter( |
| 90 | SomeOtherObject.someid == sso.someid |
| 91 | ).one(), |
| 92 | ) |
| 93 | assert isinstance(SomeOtherObject.query, query.Query) |
| 94 | assert not isinstance(SomeOtherObject.query, CustomQuery) |
| 95 | assert isinstance(SomeOtherObject.custom_query, query.Query) |
| 96 | |
| 97 | def test_config_errors(self): |
| 98 | Session = scoped_session(sa.orm.sessionmaker()) |
nothing calls this directly
no test coverage detected