def test_add_accounts_to_group(self):
        account2 = Account(self.client,
                           properties={
                               'href': 'http://example.com/account2',
                               'username': '******',
                               'given_name': 'given_name',
                               'surname': 'surname',
                               'email': '*****@*****.**',
                               'password': '******'
                           })
        ds = MagicMock()
        self.acs = AccountList(MagicMock(data_store=ds), href='test/accounts')
        self.d._set_properties({'accounts': self.acs})
        ds.get_resource.return_value = {
            'href': self.account.href,
            'username': self.account.username
        }

        self.g.add_accounts(['http://example.com/account', account2])
        self.assertEqual(
            self.account._client.group_memberships.create.call_count, 2)
        calls = self.account._client.group_memberships.create.call_args_list
        args, _ = calls[0]
        self.assertEqual(args[0]['account'].href, self.account.href)
        self.assertEqual(args[0]['group'].href, self.g.href)
        args, _ = calls[1]
        self.assertEqual(args[0]['account'].href, account2.href)
        self.assertEqual(args[0]['group'].href, self.g.href)
    def test_specialized_query_loads_json_if_specified(self):
        coll = AccountList(MagicMock(), href="test/resource")
        maps = {AccountList: {'attrname': '--foo'}}
        args = {'--json': """{"attrname": "FOO"}"""}

        ret = actions._specialized_query(coll, args, maps)
        self.assertEqual(ret, {'attrname': 'FOO'})
    def test_specialized_query_gets_attributes_from_options(self):
        coll = AccountList(MagicMock(), href="test/resource")
        maps = {AccountList: {'attrname': '--foo'}}
        args = {'--foo': 'FOO', '--bar': 'BAR'}

        ret = actions._specialized_query(coll, args, maps)
        self.assertEqual(ret, {'attrname': 'FOO'})
    def test_add_account_to_group(self):
        ds = MagicMock()
        self.acs = AccountList(MagicMock(data_store=ds), href='test/accounts')
        self.d._set_properties({'accounts': self.acs})
        ds.get_resource.return_value = {
            'href': self.account.href,
            'username': self.account.username
        }

        self.g.add_account('http://example.com/account')
        args, _ = self.account._client.group_memberships.create.call_args
        self.assertEqual(args[0]['account'].href, self.account.href)
        self.assertEqual(args[0]['group'].href, self.g.href)
Beispiel #5
0
 def test_setting_context_only_works_for_application_and_directory_resources(self):
     context.store_config_file = lambda x, y: True
     context.get_resource = lambda x, y, z: True
     app = ApplicationList(MagicMock(), href="test/resource")
     d = DirectoryList(MagicMock(), href="test/resource")
     args = {'--name': 'test'}
     try:
         context.set_context(app, args)
     except:
         self.fail('Exception should not have been raised.')
     try:
         context.set_context(d, args)
     except:
         self.fail('Exception should not have been raised.')
     acc = AccountList(MagicMock(), href='test/resource')
     self.assertRaises(ValueError, context.set_context, acc, args)
    def test_remove_account_from_group_account_is_not_in(self):
        ds = MagicMock()
        self.acs = AccountList(MagicMock(data_store=ds), href='test/accounts')
        self.d._set_properties({'accounts': self.acs})
        ds.get_resource.return_value = {
            'href': self.account.href,
            'username': self.account.username
        }

        ds = MagicMock()
        ams = GroupMembershipList(MagicMock(data_store=ds),
                                  href='test/memberships')
        ds.get_resource.return_value = {'items': [], 'offset': 0, 'limit': 0}
        self.g._set_properties({'account_memberships': ams})

        self.assertRaises(StormpathError, self.g.remove_account,
                          'http://example.com/account')
    def test_add_account_to_group_by_search_dict(self):
        ds = MagicMock()
        self.acs = AccountList(MagicMock(data_store=ds), href='test/accounts')
        self.d._set_properties({'accounts': self.acs})
        ds.get_resource.return_value = {
            'href':
            'test/accounts',
            'offset':
            0,
            'limit':
            25,
            'items': [{
                'href': self.account.href,
                'username': self.account.username
            }],
        }

        self.g.add_account({'username': self.account.username})
        args, _ = self.account._client.group_memberships.create.call_args
        self.assertEqual(args[0]['account'].href, self.account.href)
        self.assertEqual(args[0]['group'].href, self.g.href)
    def test_remove_account_from_group(self):
        ds = MagicMock()
        self.acs = AccountList(MagicMock(data_store=ds), href='test/accounts')
        self.d._set_properties({'accounts': self.acs})
        ds.get_resource.return_value = {
            'href': self.account.href,
            'username': self.account.username
        }

        ds = MagicMock()
        ams = GroupMembershipList(MagicMock(data_store=ds),
                                  href='test/memberships')
        gm = GroupMembership(self.client,
                             properties={
                                 'href': 'test/group-membership',
                                 'account': self.account,
                                 'group': self.g
                             })
        ds.get_resource.return_value = {'items': [gm], 'offset': 0, 'limit': 0}
        self.g._set_properties({'account_memberships': ams})
        self.g.remove_account(self.account.href)
        args, _ = gm._client.data_store.delete_resource.call_args
        self.assertEqual(args[0], gm.href)