[ckan-changes] commit/ckanext-storage: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Thu Sep 1 07:04:41 UTC 2011


2 new changesets in ckanext-storage:

http://bitbucket.org/okfn/ckanext-storage/changeset/f707d27d5d28/
changeset:   f707d27d5d28
user:        rgrp
date:        2011-08-31 10:53:33
summary:     [tests][xs]: make sure 'bad' underlying config does not break test of google storage backend.
affected #:  1 file (177 bytes)

--- a/tests/test_storage.py	Sat Aug 13 20:00:29 2011 +0100
+++ b/tests/test_storage.py	Wed Aug 31 09:53:33 2011 +0100
@@ -15,6 +15,9 @@
         config.local_conf['ofs.impl'] = 'google'
         config.local_conf['ofs.gs_access_key_id'] = 'GOOGCABCDASDASD'
         config.local_conf['ofs.gs_secret_access_key'] = '134zsdfjkw4234addad'
+        # need to ensure not configured for local as breaks google setup
+        if 'ofs.storage_dir' in config.local_conf:
+            del config.local_conf['ofs.storage_dir']
         wsgiapp = make_app(config.global_conf, **config.local_conf)
         cls.app = paste.fixture.TestApp(wsgiapp)
         # setup test data including testsysadmin user


http://bitbucket.org/okfn/ckanext-storage/changeset/e8e6fbf7b8c9/
changeset:   e8e6fbf7b8c9
user:        rgrp
date:        2011-08-31 21:04:28
summary:     [api/auth/form,tests][s]: get auth/form working with local storage and add test for this (refactoring quite heavily to do this).

* make ofs class attribute on controller into property and move storage_backend into methods so we can set different storage backends during tests.
affected #:  2 files (2.3 KB)

--- a/ckanext/storage/controller.py	Wed Aug 31 09:53:33 2011 +0100
+++ b/ckanext/storage/controller.py	Wed Aug 31 20:04:28 2011 +0100
@@ -26,7 +26,6 @@
 
 log = getLogger(__name__)
 
-storage_backend = config['ofs.impl']
 BUCKET = config['ckanext.storage.bucket']
 key_prefix = config.get('ckanext.storage.key_prefix', 'file/')
 
@@ -63,6 +62,7 @@
     return data
 
 def get_ofs():
+    storage_backend = config['ofs.impl']
     kw = {}
     for k,v in config.items():
         if not k.startswith('ofs.') or k == 'ofs.impl':
@@ -87,7 +87,9 @@
 
 
 class StorageAPIController(BaseController):
-    ofs = get_ofs()
+    @property
+    def ofs(self):
+        return get_ofs()
     
     @jsonpify
     def index(self):
@@ -209,7 +211,7 @@
             'headers': http_request.headers
             }
 
-    def _get_form_data(self, label):
+    def _get_remote_form_data(self, label):
         method = 'POST'
         content_length_range = int(
                 config.get('ckanext.storage.max_content_length',
@@ -235,6 +237,7 @@
             )
         # HACK: fix up some broken stuff from boto
         # e.g. should not have content-length-range in list of fields!
+        storage_backend = config['ofs.impl']
         for idx,field in enumerate(data['fields']):
             if storage_backend == 'google':
                 if field['name'] == 'AWSAccessKeyId':
@@ -243,6 +246,22 @@
                 del data['fields'][idx]
         return data
 
+    def _get_form_data(self, label):
+        storage_backend = config['ofs.impl']
+        if storage_backend in ['google', 's3']:
+            return self._get_remote_form_data(label)
+        else:
+            data = {
+                'action': h.url_for('storage_upload_handle'),
+                'fields': [
+                    {
+                        'name': 'key',
+                        'value': label
+                    }
+                ]
+            }
+            return data
+
     @jsonpify
     def auth_form(self, label):
         '''Provide fields for a form upload to storage including
@@ -274,7 +293,9 @@
 class StorageController(BaseController):
     '''Upload to storage backend.
     '''
-    ofs = get_ofs()
+    @property
+    def ofs(self):
+        return get_ofs()
 
     def _get_form_for_remote(self):
         # would be nice to use filename of file
@@ -308,6 +329,7 @@
             )
         # HACK: fix up some broken stuff from boto
         # e.g. should not have content-length-range in list of fields!
+        storage_backend = config['ofs.impl']
         for idx,field in enumerate(c.data['fields']):
             if storage_backend == 'google':
                 if field['name'] == 'AWSAccessKeyId':
@@ -317,6 +339,7 @@
         c.data_json = json.dumps(c.data, indent=2)
 
     def upload(self):
+        storage_backend = config['ofs.impl']
         if storage_backend in ['google', 's3']:
             self._get_form_for_remote()
         else:


--- a/tests/test_storage.py	Wed Aug 31 09:53:33 2011 +0100
+++ b/tests/test_storage.py	Wed Aug 31 20:04:28 2011 +0100
@@ -6,8 +6,28 @@
 from ckan.tests import conf_dir, url_for, CreateTestData
 from ckanext.admin.controller import get_sysadmins
 
+class TestStorageAPIController:
+    @classmethod
+    def setup_class(cls):
+        config = appconfig('config:test.ini', relative_to=conf_dir)
+        config.local_conf['ckan.plugins'] = 'storage'
+        config.local_conf['ofs.impl'] = 'pairtree'
+        config.local_conf['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'
+        wsgiapp = make_app(config.global_conf, **config.local_conf)
+        cls.app = paste.fixture.TestApp(wsgiapp)
 
-class TestStorageAPIController:
+    def test_index(self):
+        url = url_for('storage_api')
+        res = self.app.get(url)
+        out = res.json
+        assert len(res.json) == 3
+
+    def test_authz(self):
+        url = url_for('storage_api_auth_form', label='abc')
+        res = self.app.get(url, status=[302,401])
+
+
+class TestStorageAPIControllerGoogle:
     @classmethod
     def setup_class(cls):
         config = appconfig('config:test.ini', relative_to=conf_dir)
@@ -27,19 +47,9 @@
         cls.extra_environ = {'Authorization': str(user.apikey)}
 
     @classmethod
-    def teardown_class(self):
+    def teardown_class(cls):
         CreateTestData.delete()
 
-    def test_index(self):
-        url = url_for('storage_api')
-        res = self.app.get(url)
-        out = res.json
-        assert len(res.json) == 3
-
-    def test_authz(self):
-        url = url_for('storage_api_auth_form', label='abc')
-        res = self.app.get(url, status=[302,401])
-
     def test_auth_form(self):
         url = url_for('storage_api_auth_form', label='abc')
         res = self.app.get(url, extra_environ=self.extra_environ, status=200)
@@ -52,13 +62,40 @@
         url = url_for('storage_api_auth_form', label='abc',
                 success_action_redirect='abc')
         res = self.app.get(url, extra_environ=self.extra_environ, status=200)
-        exp = {u'name': u'success_action_redirect', u'value': u'abc'}
-        assert exp == res.json['fields'][0], res.json
+        fields = dict([ (x['name'], x['value']) for x in res.json['fields'] ])
+        assert fields['success_action_redirect'] == u'http://localhost/api/storage/metadata/abc', fields
 
     def test_auth_request(self):
-        user = model.User.by_name('tester')
         url = url_for('storage_api_auth_request', label='abc')
         res = self.app.get(url, extra_environ=self.extra_environ, status=200)
         assert res.json['method'] == 'POST'
         assert res.json['headers']['Authorization']
 
+
+class TestStorageAPIControllerLocal:
+    @classmethod
+    def setup_class(cls):
+        config = appconfig('config:test.ini', relative_to=conf_dir)
+        config.local_conf['ckan.plugins'] = 'storage'
+        config.local_conf['ofs.impl'] = 'pairtree'
+        config.local_conf['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'
+        wsgiapp = make_app(config.global_conf, **config.local_conf)
+        cls.app = paste.fixture.TestApp(wsgiapp)
+        CreateTestData.create()
+        model.Session.remove()
+        user = model.User.by_name('tester')
+        cls.extra_environ = {'Authorization': str(user.apikey)}
+
+    @classmethod
+    def teardown_class(cls):
+        CreateTestData.delete()
+
+    def test_auth_form(self):
+        url = url_for('storage_api_auth_form', label='abc')
+        res = self.app.get(url, extra_environ=self.extra_environ, status=200)
+        assert res.json['fields'][-1]['value'] == 'abc', res
+
+        url = url_for('storage_api_auth_form', label='abc/xxx')
+        res = self.app.get(url, extra_environ=self.extra_environ, status=200)
+        assert res.json['fields'][-1]['value'] == 'abc/xxx'
+

Repository URL: https://bitbucket.org/okfn/ckanext-storage/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list