def test_equality(self): self.assertEqual(OrgUnit('aa'), OrgUnit('aa')) self.assertNotEqual(OrgUnit('aa'), OrgUnit('bb')) self.assertNotEqual(OrgUnit('aa'), OrgUnit(123)) self.assertNotEqual(OrgUnit('aa'), OrgUnit(None)) self.assertNotEqual(OrgUnit('aa'), object()) self.assertNotEqual(OrgUnit('aa'), None)
def create_example_client(session, unit_id, properties): if len(session.query(OrgUnit).filter_by(unit_id=unit_id).all()) == 0: #create users_group if not exist temp = session.query(Group).filter( Group.groupid == properties.get('group')).all() if len(temp) == 0: users_group = Group(properties.get('group')) else: users_group = temp[0] properties.pop('group') #create inbox_group if not exist temp = session.query(Group).filter( Group.groupid == properties.get('inbox_group')).all() if len(temp) == 0: inbox_group = Group(properties.get('inbox_group')) else: inbox_group = temp[0] properties.pop('inbox_group') orgunit = OrgUnit(unit_id, **properties) orgunit.users_group = users_group orgunit.inbox_group = inbox_group session.add(orgunit) return orgunit
def disable_additional_org_units(self, org_unit_ids=None): if org_unit_ids is None: org_unit_ids = ('rk',) current_ou = get_current_org_unit() if current_ou in org_unit_ids: raise ValueError for ou_id in org_unit_ids: ou = OrgUnit.get(ou_id) create_session().delete(ou) current_ou._chosen_strategy = None
def get_org_unit(self): return OrgUnit.get(self._org_unit_id)
def setUp(self): self.unit_a = OrgUnit('clienta', title="Client A") self.unit_b = OrgUnit('clientb', title="Client B") self.unit_c = OrgUnit('clientc', title="Client C")
def test_create_org_unit_id_required(self): with self.assertRaises(TypeError): OrgUnit()
def test_create_sets_attrs(self): attrs = {'unit_id': 'unit-two', 'title': 'Unit two', 'enabled': False} org_unit = OrgUnit(**attrs) for key, value in attrs.items(): self.assertEqual(getattr(org_unit, key), value)
def test_repr(self): self.assertEqual(str(OrgUnit('a-unit')), '<OrgUnit a-unit>')