def test_gathering_resource_attributes(self):
     coll = ApplicationList(MagicMock(), href="test/resource")
     args = {'<attributes>': ['name=test', 'description=test']}
     ret = actions._gather_resource_attributes(coll, args)
     self.assertEqual(ret, {
         '--name': 'test',
         '--description': 'test',
         '<attributes>': ['name=test', 'description=test']})
 def test_gathering_resource_attributes_raises_error_on_bad_syntax(self):
     coll = ApplicationList(MagicMock(), href="test/resource")
     args = {'<attributes>': ['no_eq_sign', 'description=test']}
     self.assertRaises(ValueError, actions._gather_resource_attributes,
                       coll, args)
     args = {'<attributes>': ['no_eq_sign=', 'description=']}
     self.assertRaises(ValueError, actions._gather_resource_attributes,
                       coll, args)
示例#3
0
 def test_setting_context(self):
     context.store_config_file = lambda x, y: True
     context.get_resource = lambda x, y, z: True
     coll = ApplicationList(MagicMock(), href="test/resource")
     args = {'--name': 'test'}
     try:
         context.set_context(coll, args)
     except:
         self.fail('Exception should not have been raised.')
示例#4
0
    def setUp(self):
        super(IDSiteCallbackTest, self).setUp()
        self.store = MagicMock()
        self.store.get_resource.return_value = {
            'href':
            'acchref',
            'sp_http_status':
            200,
            'applications':
            ApplicationList(client=self.client,
                            properties={
                                'href': 'apps',
                                'items': [{
                                    'href': 'apphref'
                                }],
                                'offset': 0,
                                'limit': 25
                            })
        }
        self.store._cache_get.return_value = False  # ignore nonce

        self.client.data_store = self.store

        self.app = Application(client=self.client,
                               properties={
                                   'href': 'apphref',
                                   'accounts': {
                                       'href': 'acchref'
                                   }
                               })

        self.acc = MagicMock(href='acchref')
        now = datetime.datetime.utcnow()

        try:
            irt = uuid4().get_hex()
        except AttributeError:
            irt = uuid4().hex

        fake_jwt_data = {
            'exp': now + datetime.timedelta(seconds=3600),
            'aud': self.app._client.auth.id,
            'irt': irt,
            'iss': 'Stormpath',
            'sub': self.acc.href,
            'isNewSub': False,
            'state': None,
        }

        self.fake_jwt = to_unicode(
            jwt.encode(fake_jwt_data, self.app._client.auth.secret, 'HS256'),
            'UTF-8')
示例#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)
示例#6
0
 def test_setting_context_doesnt_allow_wildcard(self):
     context.store_config_file = lambda x, y: True
     context.get_resource = lambda x, y, z: True
     coll = ApplicationList(MagicMock(), href="test/resource")
     args = {'--name': 'test*'}
     self.assertRaises(ValueError, context.set_context, coll, args)
    def test_that_resource_identifiers_are_required_and_parsed_properly(self):
        coll = ApplicationList(MagicMock(), href="test/resource")
        attrs = {'name': 'Test Application'}

        ret = actions._primary_attribute(coll, attrs)
        self.assertEqual(ret, ('name', 'Test Application'))