コード例 #1
0
    def test_get_resource_api_keys_is_cached(self):

        ex = MagicMock()
        ds = DataStore(ex)

        ex.get.return_value = {
            'href':
                'https://www.example.com/applications/APPLICATION_ID/apiKeys',
            'items': [
                {
                    'href': 'http://example.com/apiKeys/KEY_ID',
                    'id': 'KEY_ID',
                    'secret': 'KEY_SECRET'
                }
            ]
        }

        ds.get_resource(
            'https://www.example.com/applications/APPLICATION_ID/apiKeys',
            {'id': 'KEY_ID'})

        ex.get.assert_called_once_with(
            'https://www.example.com/applications/APPLICATION_ID/apiKeys',
            params={'id': 'KEY_ID'})

        self.assertEqual(
            ds._cache_get('http://example.com/apiKeys/KEY_ID'),
            {
                'secret': 'KEY_SECRET',
                'href': 'http://example.com/apiKeys/KEY_ID',
                'id': 'KEY_ID'
            })
コード例 #2
0
    def test_get_resource_api_keys_is_cached(self):

        ex = MagicMock()
        ds = DataStore(ex)

        ex.get.return_value = {
            'href':
            'https://www.example.com/applications/APPLICATION_ID/apiKeys',
            'items': [{
                'href': 'http://example.com/apiKeys/KEY_ID',
                'id': 'KEY_ID',
                'secret': 'KEY_SECRET'
            }]
        }

        ds.get_resource(
            'https://www.example.com/applications/APPLICATION_ID/apiKeys',
            {'id': 'KEY_ID'})

        ex.get.assert_called_once_with(
            'https://www.example.com/applications/APPLICATION_ID/apiKeys',
            params={'id': 'KEY_ID'})

        self.assertEqual(
            ds._cache_get('http://example.com/apiKeys/KEY_ID'), {
                'secret': 'KEY_SECRET',
                'href': 'http://example.com/apiKeys/KEY_ID',
                'id': 'KEY_ID'
            })
コード例 #3
0
    def test_get_resource_is_cached(self):
        ex = MagicMock()
        ds = DataStore(ex)

        ex.get.return_value = {
            'href': 'http://example.com/accounts/FOO',
            'name': 'Foo',
        }

        # make the request twice
        ds.get_resource('http://example.com/accounts/FOO')
        ds.get_resource('http://example.com/accounts/FOO')

        ex.get.assert_called_once_with('http://example.com/accounts/FOO',
            params=None)
コード例 #4
0
    def test_get_resource_is_cached(self):
        ex = MagicMock()
        ds = DataStore(ex)

        ex.get.return_value = {
            'href': 'http://example.com/accounts/FOO',
            'name': 'Foo',
        }

        # make the request twice
        ds.get_resource('http://example.com/accounts/FOO')
        ds.get_resource('http://example.com/accounts/FOO')

        ex.get.assert_called_once_with('http://example.com/accounts/FOO',
                                       params=None)
コード例 #5
0
    def test_get_resource_is_not_cached(self):
        ex = MagicMock()
        ds = DataStore(
            ex, {'regions': {'accounts': {'store': NullCacheStore}}})

        ex.get.return_value = {
            'href': 'http://example.com/accounts/FOO',
            'name': 'Foo',
        }

        # make the request twice
        ds.get_resource('http://example.com/accounts/FOO')
        ds.get_resource('http://example.com/accounts/FOO')

        self.assertEqual(ex.get.call_count, 2)
コード例 #6
0
    def test_get_resource_is_not_cached(self):
        ex = MagicMock()
        ds = DataStore(
            ex, {'regions': {'accounts': {'store': NullCacheStore}}})

        ex.get.return_value = {
            'href': 'http://example.com/accounts/FOO',
            'name': 'Foo',
        }

        # make the request twice
        ds.get_resource('http://example.com/accounts/FOO')
        ds.get_resource('http://example.com/accounts/FOO')

        self.assertEqual(ex.get.call_count, 2)
コード例 #7
0
    def test_get_resource(self):
        data_store = DataStore(executor=self.executor)
        self.assertIsInstance(data_store.get_resource(self.app.href), dict)

        acc = self.app.accounts.create({
            'given_name': 'Randall',
            'surname': 'Degges',
            'email': '{}@testmail.stormpath.com'.format(self.get_random_name()),
            'password': '******',
        })
        key = acc.api_keys.create()

        data_store = DataStore(executor=self.executor)
        data = data_store.get_resource(self.app.href + '/apiKeys', {'id': key.id})
        self.assertIsInstance(data, dict)
        self.assertEqual(data['items'][0]['id'], key.id)

        data_store = DataStore(executor=self.executor)
        data = data_store.get_resource(self.app.tenant.href + '/applications')
        self.assertIsInstance(data, dict)

        hrefs = [data['items'][i]['href'] for i in range(len(data['items']))]
        self.assertTrue(self.app.href in hrefs)