def setUp(self): super(TestAssignedUsersSource, self).setUp() self.admin_unit = create(Builder('admin_unit').as_current_admin_unit()) user = create( Builder('ogds_user').having(firstname='Test', lastname='User')) additional = create( Builder('admin_unit').id('additional').having(title='additional')) self.org_unit = create( Builder('org_unit').id('client1').having( title=u"Client 1", admin_unit=self.admin_unit).with_default_groups()) org_unit_2 = create( Builder('org_unit').id('client2').having( title=u"Client 2", admin_unit=self.admin_unit).with_default_groups().assign_users( [user]).as_current_org_unit()) org_unit_3 = create( Builder('org_unit').id('client3').having( title=u"Client 3", admin_unit=additional).with_default_groups()) disabled_unit = create( Builder('org_unit').id('client4').having( title=u'Steueramt', enabled=False, admin_unit=self.admin_unit).with_default_groups()) create( Builder('ogds_user').id('hugo.boss').having( firstname='Test', lastname='User').assign_to_org_units([self.org_unit])) create( Builder('ogds_user').id('peter.muster').having( firstname='Peter', lastname='Muster').assign_to_org_units([org_unit_2])) create( Builder('ogds_user').id('jamie.lannister').having( firstname='Jamie', lastname='Lannister').assign_to_org_units( [self.org_unit, org_unit_2])) create( Builder('ogds_user').id('peter.meier').having( firstname='Peter', lastname='Meier').assign_to_org_units([org_unit_3])) create( Builder('ogds_user').id('simon.says').having( firstname='Simon', lastname='Says').assign_to_org_units([disabled_unit])) self.source = AssignedUsersSource(self.portal)
def setUp(self): super(TestAssignedUsersSource, self).setUp() self.admin_unit = create(Builder('admin_unit').as_current_admin_unit()) user = create(Builder('ogds_user').having(firstname='Test', lastname='User')) additional = create(Builder('admin_unit') .id('additional') .having(title='additional')) self.org_unit = create(Builder('org_unit').id('client1') .having(title=u"Client 1", admin_unit=self.admin_unit) .with_default_groups()) org_unit_2 = create(Builder('org_unit').id('client2') .having(title=u"Client 2", admin_unit=self.admin_unit) .with_default_groups() .assign_users([user]) .as_current_org_unit()) org_unit_3 = create(Builder('org_unit') .id('client3') .having(title=u"Client 3", admin_unit=additional) .with_default_groups()) disabled_unit = create(Builder('org_unit') .id('client4') .having(title=u'Steueramt', enabled=False, admin_unit=self.admin_unit) .with_default_groups()) create(Builder('ogds_user').id('hugo.boss') .having(firstname='Test', lastname='User') .assign_to_org_units([self.org_unit])) create(Builder('ogds_user').id('peter.muster') .having(firstname='Peter', lastname='Muster') .assign_to_org_units([org_unit_2])) create(Builder('ogds_user').id('jamie.lannister') .having(firstname='Jamie', lastname='Lannister') .assign_to_org_units([self.org_unit, org_unit_2])) create(Builder('ogds_user').id('peter.meier') .having(firstname='Peter', lastname='Meier') .assign_to_org_units([org_unit_3])) create(Builder('ogds_user').id('simon.says') .having(firstname='Simon', lastname='Says') .assign_to_org_units([disabled_unit])) self.source = AssignedUsersSource(self.portal)
class TestAssignedUsersSource(FunctionalTestCase): use_default_fixture = False def setUp(self): super(TestAssignedUsersSource, self).setUp() self.admin_unit = create(Builder('admin_unit').as_current_admin_unit()) user = create(Builder('ogds_user').having(firstname='Test', lastname='User')) additional = create(Builder('admin_unit') .id('additional') .having(title='additional')) self.org_unit = create(Builder('org_unit').id('client1') .having(title=u"Client 1", admin_unit=self.admin_unit) .with_default_groups()) org_unit_2 = create(Builder('org_unit').id('client2') .having(title=u"Client 2", admin_unit=self.admin_unit) .with_default_groups() .assign_users([user]) .as_current_org_unit()) org_unit_3 = create(Builder('org_unit') .id('client3') .having(title=u"Client 3", admin_unit=additional) .with_default_groups()) disabled_unit = create(Builder('org_unit') .id('client4') .having(title=u'Steueramt', enabled=False, admin_unit=self.admin_unit) .with_default_groups()) create(Builder('ogds_user').id('hugo.boss') .having(firstname='Test', lastname='User') .assign_to_org_units([self.org_unit])) create(Builder('ogds_user').id('peter.muster') .having(firstname='Peter', lastname='Muster') .assign_to_org_units([org_unit_2])) create(Builder('ogds_user').id('jamie.lannister') .having(firstname='Jamie', lastname='Lannister') .assign_to_org_units([self.org_unit, org_unit_2])) create(Builder('ogds_user').id('peter.meier') .having(firstname='Peter', lastname='Meier') .assign_to_org_units([org_unit_3])) create(Builder('ogds_user').id('simon.says') .having(firstname='Simon', lastname='Says') .assign_to_org_units([disabled_unit])) self.source = AssignedUsersSource(self.portal) def test_get_term_by_token(self): term = self.source.getTermByToken(u'hugo.boss') self.assertTrue(isinstance(term, SimpleTerm)) self.assertEquals(u'User Test (hugo.boss)', term.title) def test_get_term_by_token_raises_BadReques_if_no_token(self): with self.assertRaises(LookupError): self.source.getTermByToken(None) def test_get_term_by_token_raises_LookupError_if_no_result(self): with self.assertRaises(LookupError): self.source.getTermByToken('dummy:dummy') def test_title_token_and_value_of_term(self): result = self.source.search('hugo') self.assertEqual(1, len(result), 'Expect one result. only Hugo') self.assertEquals(u'hugo.boss', result[0].token) self.assertEquals(u'hugo.boss', result[0].value) self.assertEquals(u'User Test (hugo.boss)', result[0].title) def test_only_users_of_the_current_admin_unit_are_valid(self): self.assertIn('hugo.boss', self.source) self.assertIn('peter.muster', self.source) self.assertIn('jamie.lannister', self.source) self.assertIn(TEST_USER_ID, self.source) def test_users_from_inactive_orgunits_are_not_valid_but_not_found_by_search(self): self.assertIn('simon.says', self.source) self.assertEquals([], self.source.search('simon')) def test_getTerm_handles_inactive_users(self): create(Builder('ogds_user') .id('john.doe') .having(firstname='John', lastname='Doe', active=False) .assign_to_org_units([self.org_unit])) self.assertTrue(self.source.getTerm('john.doe'), 'Expect a term from inactive user') def test_search_for_inactive_users_is_not_possible(self): create(Builder('ogds_user') .id('john.doe') .having(firstname='John', lastname='Doe', active=False) .assign_to_org_units([self.org_unit])) self.assertFalse(self.source.search('Doe'), 'Expect no user, since peter.muster is inactive')
class TestAssignedUsersSource(FunctionalTestCase): use_default_fixture = False def setUp(self): super(TestAssignedUsersSource, self).setUp() self.admin_unit = create(Builder('admin_unit').as_current_admin_unit()) user = create( Builder('ogds_user').having(firstname='Test', lastname='User')) additional = create( Builder('admin_unit').id('additional').having(title='additional')) self.org_unit = create( Builder('org_unit').id('client1').having( title=u"Client 1", admin_unit=self.admin_unit).with_default_groups()) org_unit_2 = create( Builder('org_unit').id('client2').having( title=u"Client 2", admin_unit=self.admin_unit).with_default_groups().assign_users( [user]).as_current_org_unit()) org_unit_3 = create( Builder('org_unit').id('client3').having( title=u"Client 3", admin_unit=additional).with_default_groups()) disabled_unit = create( Builder('org_unit').id('client4').having( title=u'Steueramt', enabled=False, admin_unit=self.admin_unit).with_default_groups()) create( Builder('ogds_user').id('hugo.boss').having( firstname='Test', lastname='User').assign_to_org_units([self.org_unit])) create( Builder('ogds_user').id('peter.muster').having( firstname='Peter', lastname='Muster').assign_to_org_units([org_unit_2])) create( Builder('ogds_user').id('jamie.lannister').having( firstname='Jamie', lastname='Lannister').assign_to_org_units( [self.org_unit, org_unit_2])) create( Builder('ogds_user').id('peter.meier').having( firstname='Peter', lastname='Meier').assign_to_org_units([org_unit_3])) create( Builder('ogds_user').id('simon.says').having( firstname='Simon', lastname='Says').assign_to_org_units([disabled_unit])) self.source = AssignedUsersSource(self.portal) def test_get_term_by_token(self): term = self.source.getTermByToken(u'hugo.boss') self.assertTrue(isinstance(term, SimpleTerm)) self.assertEquals(u'User Test (hugo.boss)', term.title) def test_get_term_by_token_raises_BadReques_if_no_token(self): with self.assertRaises(LookupError): self.source.getTermByToken(None) def test_get_term_by_token_raises_LookupError_if_no_result(self): with self.assertRaises(LookupError): self.source.getTermByToken('dummy:dummy') def test_title_token_and_value_of_term(self): result = self.source.search('hugo') self.assertEqual(1, len(result), 'Expect one result. only Hugo') self.assertEquals(u'hugo.boss', result[0].token) self.assertEquals(u'hugo.boss', result[0].value) self.assertEquals(u'User Test (hugo.boss)', result[0].title) def test_only_users_of_the_current_admin_unit_are_valid(self): self.assertIn('hugo.boss', self.source) self.assertIn('peter.muster', self.source) self.assertIn('jamie.lannister', self.source) self.assertIn(TEST_USER_ID, self.source) def test_users_from_inactive_orgunits_are_not_valid_but_not_found_by_search( self): self.assertIn('simon.says', self.source) self.assertEquals([], self.source.search('simon')) def test_getTerm_handles_inactive_users(self): create( Builder('ogds_user').id('john.doe').having( firstname='John', lastname='Doe', active=False).assign_to_org_units([self.org_unit])) self.assertTrue(self.source.getTerm('john.doe'), 'Expect a term from inactive user') def test_search_for_inactive_users_is_not_possible(self): create( Builder('ogds_user').id('john.doe').having( firstname='John', lastname='Doe', active=False).assign_to_org_units([self.org_unit])) self.assertFalse(self.source.search('Doe'), 'Expect no user, since peter.muster is inactive')