def initdb(session): from elixr.sax.address import Country, State ca = Country(code='CA', name='Canada') ng = Country(code='NG', name='Nigeria') session.add_all([ ca, ng, State(code='BC', name='British Columbia', country=ca), State(code='BC', name='Bauchi', country=ng), # wrong code ;-D ]) session.commit()
def initdb(session): from elixr.sax.address import Country, State ca = Country(code='CA', name='Canada') ng = Country(code='NG', name='Nigeria') session.add_all([ ca, ng, State(code='KN', name='Kano', country=ng), # wrong code ;-D ]) from elixr.sax.party import OrganizationType ot1 = OrganizationType(name='hq', title='Headquarters', is_root=True) ot2 = OrganizationType(name='branch', title='Branch') session.add_all([ot1, ot2]) session.commit()
def test_state_delete_cascades_down_to_setr_null(self, db): country = Country(code='NG', name='Nigeria') state = State(code='KD', name='Kaduna', country=country) Address(raw='Street, Town', street='Street', town='Town', state=state) Address(raw='Street2, Town2', street='Street2', town='Town2', state=state) db.add(country) db.commit() assert db.query(Country).count() == 1 assert db.query(State).count() == 1 assert db.query(Address).count() == 2 assert db.query(Address).filter( Address.state_id.is_(None)).count() == 0 db.delete(state) db.commit() assert db.query(Country).count() == 1 assert db.query(State).count() == 0 assert db.query(Address).count() == 2 assert db.query(Address).filter( Address.state_id.is_(None)).count() == 2
def test_country_delete_cascades_down(self, db): country = Country(code='NG', name='Nigeria') country2 = Country(code='GH', name='Ghana') State(code='KD', name='Kaduna', country=country) State(code='KN', name='Kano', country=country) db.add_all([country, country2]) db.commit() assert db.query(Country).count() == 2 assert db.query(State).count() == 2 db.delete(country) db.commit() assert db.query(Country).count() == 1 assert db.query(State).count() == 0
def initdb(session): cn = Country(code='CN', name='Country') org = Organisation(identifier="Org0", name="Org.Main", short_name="Org0") session.add_all([ ## voltages Voltage(value=415), Voltage(value=11000), Voltage(value=33000), ## states State(code='S1', name='State 1', country=cn), State(code='S2', name='State 2', country=cn), ## organisations Organisation(identifier="Org1", name="Child1", short_name="Org1", parent=org), Organisation(identifier="Org2", name="Child2", short_name="Org2", parent=org), ]) session.commit()
def initdb(db): from elixr.sax.address import Country db.add(Country(name='Nigeria', code='NG')) db.add(Country(name='Algeria', code='AL')) db.commit()
def test_commit_fails_for_blank_code(self, addr_db): with pytest.raises(Exception): addr_db.add(Country(name='Kenya')) addr_db.commit() addr_db.rollback()
def test_commit_fails_for_blank_name(self, addr_db): with pytest.raises(Exception): addr_db.add(Country(code='NG')) addr_db.commit() addr_db.rollback() # why? see hint at module top
def test_commit_fails_for_duplicate_name(self, addr_db): with pytest.raises(Exception): addr_db.add(Country(name='Nigeria', code='??')) addr_db.commit()
def test_string_repr(self): country = Country(name='Nigeria', code='NG') assert 'Nigeria' == str(country)