Exemplo n.º 1
0
    def testInvalidDomainSelector(self):
        with self.assertRaises(ValueError):
            Domain().to_selector()

        # Should not produce a selector with spamattr
        with self.assertRaises(ValueError):
            Domain(spamattr='eggvalue').to_selector()
Exemplo n.º 2
0
    def test_modify_domain(self):
        rand_str = random.randint(0, 10**9)

        dom = self.zc.get_domain(Domain(name=self.DOMAIN1))
        a = {'zimbraAutoProvNotificationBody': rand_str}
        self.zc.modify_domain(dom, a)

        dom = self.zc.get_domain(Domain(name=self.DOMAIN1))
        self.assertEqual(dom['zimbraAutoProvNotificationBody'], rand_str)
Exemplo n.º 3
0
 def test_ZObjects_import_a_tags(self):
     props = Domain._parse_a_tags(self.simple_domain_dict["domain"])
     self.assertIsInstance(props, dict)
     # 53 is the number of unique "n" keys in the sample domain.
     self.assertEqual(len(props), 53)
     # Just check one of the <a> tags
     self.assertEqual(props["zimbraAuthMech"], "zimbra")
Exemplo n.º 4
0
 def test_get_all_accounts_by_single_domain_and_server(self):
     test_domain = Domain(name=self.DOMAIN2)
     test_server = Server(name=self.SERVER_NAME)
     accounts = self.zc.get_all_accounts(domain=test_domain,
                                         server=test_server)
     self.assertIsInstance(accounts[0], Account)
     self.assertEqual(len(accounts), 5)
Exemplo n.º 5
0
    def test_get_all_accounts_exclusion_filters(self):
        # The self.DOMAIN1 contains 5 user accounts, 1 system and 1 admin
        test_domain = Domain(name=self.DOMAIN1)

        accounts = self.zc.get_all_accounts(domain=test_domain,
                                            include_system_accounts=True,
                                            include_admin_accounts=True)
        self.assertEqual(len(accounts), 7)

        accounts_no_admin = self.zc.get_all_accounts(
            domain=test_domain,
            include_system_accounts=True,
            include_admin_accounts=False)
        self.assertEqual(len(accounts_no_admin), 6)

        accounts_no_system = self.zc.get_all_accounts(
            domain=test_domain,
            include_system_accounts=False,
            include_admin_accounts=True)
        self.assertEqual(len(accounts_no_system), 6)

        accounts_no_admin_no_system = self.zc.get_all_accounts(
            domain=test_domain,
            include_admin_accounts=False,
            include_system_accounts=False)
        self.assertEqual(len(accounts_no_admin_no_system), 5)
Exemplo n.º 6
0
    def test_create_delete_forced_domain(self):
        account_mail = 'test_user@' + self.TMP_DOMAIN
        cal_res_mail = 'test_res@' + self.TMP_DOMAIN
        alias_name = self.LAMBDA_USER.split('@')[0] + '@' + self.TMP_DOMAIN
        dl_mail = 'test_dl@' + self.TMP_DOMAIN

        # CREATE
        self.zc.create_domain(self.TMP_DOMAIN)
        dom = self.zc.get_domain(Domain(name=self.TMP_DOMAIN))

        self.assertIsInstance(dom, Domain)
        self.assertEqual(dom.name, self.TMP_DOMAIN)

        self.zc.create_account(account_mail, 'pass1234')
        self.zc.create_calendar_resource(cal_res_mail,
                                         attrs={
                                             'displayName':
                                             'test display name',
                                             'zimbraCalResType':
                                             CalendarResource.EQUIPMENT_TYPE
                                         })
        self.zc.add_account_alias(Account(name=self.LAMBDA_USER), alias_name)
        self.zc.create_distribution_list(dl_mail)

        # DELETE
        self.zc.delete_domain_forced(dom)

        with self.assertRaises(ZimbraSoapServerError):
            self.zc.get_domain(dom)
Exemplo n.º 7
0
 def test_ZObjects_import_a_tags(self):
     props = Domain._parse_a_tags(self.simple_domain_dict['domain'])
     self.assertIsInstance(props, dict)
     # 53 is the number of unique "n" keys in the sample domain.
     self.assertEqual(len(props), 53)
     # Just check one of the <a> tags
     self.assertEqual(props['zimbraAuthMech'], 'zimbra')
Exemplo n.º 8
0
 def testDomainFromDict(self):
     data = self.simple_domain_dict["domain"]
     d = Domain.from_dict(data)
     self.assertIsInstance(d, Domain)
     self.assertIsInstance(d.id, text_type)
     self.assertIsInstance(d.name, text_type)
     self.assertIsNotNone(d.id)
     self.assertEqual(d.name, "client1.unbound.example.com")
     self.assertEqual(d.get_full_data(), data)
Exemplo n.º 9
0
 def testDomainFromDict(self):
     data = self.simple_domain_dict['domain']
     d = Domain.from_dict(data)
     self.assertIsInstance(d, Domain)
     self.assertIsInstance(d.id, text_type)
     self.assertIsInstance(d.name, text_type)
     self.assertIsNotNone(d.id)
     self.assertEqual(d.name, 'client1.unbound.example.com')
     self.assertEqual(d.get_full_data(), data)
Exemplo n.º 10
0
 def testDomainFromDict(self):
     data = self.simple_domain_dict['domain']
     d = Domain.from_dict(data)
     self.assertIsInstance(d, Domain)
     self.assertIsInstance(d.id, str)
     self.assertIsInstance(d.name, str)
     self.assertIsNotNone(d.id)
     self.assertEqual(d.name, 'client1.unbound.example.com')
     self.assertEqual(d.get_full_data(), data)
Exemplo n.º 11
0
    def test_count_account(self):
        d = Domain(name=self.DOMAIN1)

        # ex return: list: ((<ClassOfService object>, <int>), ...)
        cos_counts = self.zc.count_account(d)

        self.assertIsInstance(cos_counts, list)
        self.assertIsInstance(cos_counts[0], tuple)
        self.assertIsInstance(cos_counts[0][0], ClassOfService)
        self.assertIsInstance(cos_counts[0][1], int)
Exemplo n.º 12
0
    def test_create_delete_domain(self):

        # CREATE
        self.zc.create_domain(self.TMP_DOMAIN)
        dom = self.zc.get_domain(Domain(name=self.TMP_DOMAIN))

        self.assertIsInstance(dom, Domain)
        self.assertEqual(dom.name, self.TMP_DOMAIN)

        # DELETE
        self.zc.delete_domain(dom)

        with self.assertRaises(ZimbraSoapServerError):
            self.zc.get_domain(dom)
Exemplo n.º 13
0
    def test_ZObjects_comparison_invalid_type(self):
        d1 = Domain(id='d78fd9c9-f000-440b-bce6-ea938d40fa2d')
        m1 = Mailbox(id='d78fd9c9-f000-440b-bce6-ea938d40fa2d')

        with self.assertRaises(TypeError):
            d1 == m1
Exemplo n.º 14
0
    def test_ZObjects_comparison_invalid_id_second(self):
        d1 = Domain(id='123')
        d2 = Domain(id='d78fd9c9-f000-440b-bce6-ea938d40fa2d')

        with self.assertRaises(ValueError):
            d2 == d1
Exemplo n.º 15
0
 def test_ZObjects_comparison(self):
     d1 = Domain(id='d78fd9c9-f000-440b-bce6-ea938d40fa2d')
     d2 = Domain(id='dddddddd-f000-440b-bce6-dddddddddddd')
     self.assertTrue(d1 != d2)
     self.assertFalse(d1 == d2)
Exemplo n.º 16
0
 def test_ZObjects_access_a_tag_as_item(self):
     d = Domain.from_dict(self.simple_domain_dict['domain'])
     self.assertEqual(d['zimbraAuthMech'], 'zimbra')
Exemplo n.º 17
0
 def test_get_all_calendar_resources_by_single_domain(self):
     test_domain = Domain(name=self.DOMAIN2)
     resources = self.zc.get_all_calendar_resources(domain=test_domain)
     self.assertEqual(len(resources), 1)
Exemplo n.º 18
0

if __name__ == '__main__':
    print("WARNING: this is an example script, do not use in production")
    args = parse_args()
    password = getpass.getpass('Password for %s: ' % args.username)

    zc = zimsoap.client.ZimbraAdminClient(args.server, args.port)
    try:
        zc.login(args.username, password)
    except (zimsoap.client.ZimbraSoapServerError, URLError) as sf:
        print(sf)
        exit(5)

    if args.domain:
        domains_to_inspect = [Domain(name=i) for i in args.domains_list]
    else:
        domains_to_inspect = zc.get_all_domains()

    total_accounts = 0

    print("\nPrint accounts count, per-COS:")
    for domain in domains_to_inspect:
        print()
        print("Domain %s" % domain.name)
        for cos, count in zc.count_account(domain):
            print('{0:.<20}{1}'.format(cos.name, count))
            total_accounts += count

print('\nTOTAL ACCOUNTS ({0} domains): {1}'.format(len(domains_to_inspect),
                                                   total_accounts))
Exemplo n.º 19
0
 def testDomainSelector(self):
     d = Domain(name="foo")
     s = d.to_selector()
     self.assertEqual(s["by"], "name")
     self.assertEqual(s["_content"], "foo")
Exemplo n.º 20
0
 def test_ZObjects_import_a_tags_multivalue(self):
     props = Domain._parse_a_tags(self.simple_domain_dict['domain'])
     self.assertIsInstance(props['objectClass'], list)
     self.assertEqual(
         props['objectClass'],
         ['dcObject', 'organization', 'zimbraDomain', 'amavisAccount'])
Exemplo n.º 21
0
 def testDomainSelector(self):
     d = Domain(name='foo')
     s = d.to_selector()
     self.assertEqual(s['by'], 'name')
     self.assertEqual(s['_content'], 'foo')
Exemplo n.º 22
0
 def test_get_domain(self):
     dom = self.zc.get_domain(Domain(name=self.DOMAIN1))
     self.assertIsInstance(dom, Domain)
     self.assertEqual(dom.name, self.DOMAIN1)
Exemplo n.º 23
0
 def test_ZObjects_import_a_tags_multivalue(self):
     props = Domain._parse_a_tags(self.simple_domain_dict["domain"])
     self.assertIsInstance(props["objectClass"], list)
     self.assertEqual(props["objectClass"], ["dcObject", "organization", "zimbraDomain", "amavisAccount"])
Exemplo n.º 24
0
 def test_ZObjects_access_a_tag_as_item(self):
     d = Domain.from_dict(self.simple_domain_dict["domain"])
     self.assertEqual(d["zimbraAuthMech"], "zimbra")
Exemplo n.º 25
0
 def test_get_all_accounts_by_single_domain(self):
     test_domain = Domain(name=self.DOMAIN2)
     accounts = self.zc.get_all_accounts(domain=test_domain)
     self.assertIsInstance(accounts[0], Account)
     self.assertEqual(len(accounts), 5)
Exemplo n.º 26
0
 def testDomainSelector(self):
     d = Domain(name='foo')
     s = d.to_selector()
     self.assertEqual(s['by'], 'name')
     self.assertEqual(s['_content'], 'foo')
Exemplo n.º 27
0
 def test_ZObjects_import_a_tags_multivalue(self):
     props = Domain._parse_a_tags(self.simple_domain_dict['domain'])
     self.assertIsInstance(props['objectClass'], list)
     self.assertEqual(
         props['objectClass'],
         ['dcObject', 'organization', 'zimbraDomain', 'amavisAccount'])
Exemplo n.º 28
0
 def test_ZObjects_access_a_tag_as_item(self):
     d = Domain.from_dict(self.simple_domain_dict['domain'])
     self.assertEqual(d['zimbraAuthMech'], 'zimbra')