예제 #1
0
 def test_commit_fails_for_non_unique_name(self, db):
     db.add(OrganizationType(name='root', title='Root'))
     db.commit()
     with pytest.raises(exc.IntegrityError):
         db.add(OrganizationType(name='root', title='Root'))
         db.commit()
     db.rollback()
예제 #2
0
    def test_organization_cannot_belong_to_multiple_organization_types(self, db):
        org = Organization(name='Org', code='org')
        org_type1 = OrganizationType(name='orgtype1', title='Org Type 1')
        org_type2 = OrganizationType(name='orgtype2', title='Org Type 2')
        org_type1.organizations.append(org)
        org_type2.organizations.append(org)

        db.add_all([org_type1, org_type2])
        db.commit()

        assert org.type_id == org_type2.uuid
        assert len(org_type1.organizations) == 0 \
           and len(org_type2.organizations) == 1
예제 #3
0
    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()
예제 #4
0
 def _get_organization_type(self, db, name='org-type', title='Org Type',
                            is_root=False, commit=True):
     org_type = OrganizationType(name=name, title=title, is_root=is_root)
     if commit:
         db.add(org_type)
         db.commit()
     return org_type
예제 #5
0
    def test_access_organization_type_on_organization(self, db):
        org = Organization(name='Org', code='org-1')
        org_type = OrganizationType(name='orgtype', title='Org Type')
        org_type.organizations.append(org)
        db.add(org_type)
        db.commit()

        assert org.id is not None and org.type is not None
        assert org.type.name == org_type.name
예제 #6
0
    def test_organization_type_cascaded_deletion(self, db):
        org = Organization(code='01', name='Org')
        org_type1 = OrganizationType(name='org-type', title='Org Type')
        org_type1.organizations.append(org)

        child1 = Organization(code='011', name='Child Org1', parent=org)
        child2 = Organization(code='012', name='Child Org2', parent=org)
        org_type2 = OrganizationType(name='org-type-1', title='Org Type-1')
        org_type2.organizations.extend([child1, child2])
        db.add_all([org_type1, org_type2])
        db.commit()

        assert db.query(Organization).count() == 3
        assert db.query(OrganizationType).count() == 2
        db.delete(org_type2)
        db.commit()

        assert db.query(OrganizationType).count() == 1
        assert db.query(Organization).count() == 1
예제 #7
0
    def test_assigning_organization_type_for_organization(self, db):
        org = Organization(name='Org', code='org-1')
        org_type1 = OrganizationType(name='orgtype', title='Org Type')
        org_type1.organizations.append(org)

        org2 = Organization(name='Org2', code='org-2')
        org_type2 = OrganizationType(name='orgtype2', title='Org Type2')
        org_type2.organizations.append(org2)

        db.add_all([org_type1, org_type2])
        db.commit()

        assert db.query(OrganizationType).count() == 2
        assert db.query(Organization).count() == 2

        rvalue = db.query(OrganizationType).filter_by(name='orgtype').first()
        assert rvalue and rvalue.uuid is not None
        assert rvalue.organizations and len(rvalue.organizations) == 1
        assert rvalue.organizations[0].uuid == org.uuid
예제 #8
0
 def test_organization_type_has_organizations_property(self, db):
     org_type = OrganizationType(name='root', title='Root')
     db.add(org_type)
     db.commit()
     assert org_type.organizations is not None \
        and len(org_type.organizations) == 0