當前位置: 首頁>>代碼示例>>Python>>正文


Python factories.Dataset方法代碼示例

本文整理匯總了Python中ckan.tests.factories.Dataset方法的典型用法代碼示例。如果您正苦於以下問題:Python factories.Dataset方法的具體用法?Python factories.Dataset怎麽用?Python factories.Dataset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ckan.tests.factories的用法示例。


在下文中一共展示了factories.Dataset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_validation_fails_on_upload

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_validation_fails_on_upload(self, mock_open):

        invalid_file = StringIO.StringIO()
        invalid_file.write(INVALID_CSV)

        mock_upload = MockFieldStorage(invalid_file, 'invalid.csv')

        dataset = factories.Dataset()

        invalid_stream = io.BufferedReader(io.BytesIO(INVALID_CSV))

        with mock.patch('io.open', return_value=invalid_stream):

            with assert_raises(t.ValidationError) as e:

                    call_action(
                        'resource_create',
                        package_id=dataset['id'],
                        format='CSV',
                        upload=mock_upload
                    )

        assert 'validation' in e.exception.error_dict
        assert 'missing-value' in str(e.exception)
        assert 'Row 2 has a missing value in column 4' in str(e.exception) 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:27,代碼來源:test_logic.py

示例2: setup_class

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def setup_class(cls):
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        p.load('datapusher')
        p.load('test_datapusher_plugin')

        resource = factories.Resource(url_type='datastore')
        cls.dataset = factories.Dataset(resources=[resource])

        cls.sysadmin_user = factories.User(name='testsysadmin', sysadmin=True)
        cls.normal_user = factories.User(name='annafan')
        engine = db._get_engine(
            {'connection_url': config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:19,代碼來源:test_interfaces.py

示例3: test_run_auth_user

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_run_auth_user(self):

        user = factories.User()
        org = factories.Organization(
            users=[{'name': user['name'], 'capacity': 'editor'}])
        dataset = factories.Dataset(
            owner_org=org['id'], resources=[factories.Resource()])

        context = {
            'user': user['name'],
            'model': model
        }

        assert_equals(call_auth('resource_validation_run', context=context,
                                resource_id=dataset['resources'][0]['id']),
                      True) 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:18,代碼來源:test_logic.py

示例4: test_delete_auth_user

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_delete_auth_user(self):

        user = factories.User()
        org = factories.Organization(
            users=[{'name': user['name'], 'capacity': 'editor'}])
        dataset = factories.Dataset(
            owner_org=org['id'], resources=[factories.Resource()])

        context = {
            'user': user['name'],
            'model': model
        }

        assert_equals(call_auth('resource_validation_delete', context=context,
                                resource_id=dataset['resources'][0]['id']),
                      True) 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:18,代碼來源:test_logic.py

示例5: test_show_anon_public_dataset

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_show_anon_public_dataset(self):

        user = factories.User()
        org = factories.Organization()
        dataset = factories.Dataset(
            owner_org=org['id'], resources=[factories.Resource()],
            private=False)

        context = {
            'user': user['name'],
            'model': model
        }

        assert_equals(call_auth('resource_validation_show', context=context,
                                resource_id=dataset['resources'][0]['id']),
                      True) 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:18,代碼來源:test_logic.py

示例6: test_validation_passes_on_upload

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_validation_passes_on_upload(self, mock_open):

        invalid_file = StringIO.StringIO()
        invalid_file.write(VALID_CSV)

        mock_upload = MockFieldStorage(invalid_file, 'invalid.csv')

        dataset = factories.Dataset()

        valid_stream = io.BufferedReader(io.BytesIO(VALID_CSV))

        with mock.patch('io.open', return_value=valid_stream):

            resource = call_action(
                'resource_create',
                package_id=dataset['id'],
                format='CSV',
                upload=mock_upload
            )

        assert_equals(resource['validation_status'], 'success')
        assert 'validation_timestamp' in resource 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:24,代碼來源:test_logic.py

示例7: test_validation_passes_with_url

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_validation_passes_with_url(self, mock_validate):

        dataset = factories.Dataset(resources=[
            {
                'url': 'https://example.com/data.csv'
            }
        ])

        resource = call_action(
            'resource_update',
            id=dataset['resources'][0]['id'],
            format='CSV',
            url='https://example.com/some.other.csv',
        )

        assert_equals(resource['validation_status'], 'success')
        assert 'validation_timestamp' in resource 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:19,代碼來源:test_logic.py

示例8: test_schema_field_url

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_schema_field_url(self):

        url = 'https://example.com/schema.json'

        dataset = factories.Dataset()

        resource = call_action(
            'resource_create',
            package_id=dataset['id'],
            url='http://example.com/file.csv',
            schema=url
        )

        assert_equals(resource['schema'], url)

        assert 'schema_upload' not in resource
        assert 'schema_url' not in resource 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:19,代碼來源:test_logic.py

示例9: test_schema_url_field

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_schema_url_field(self):

        url = 'https://example.com/schema.json'

        dataset = factories.Dataset()

        resource = call_action(
            'resource_create',
            package_id=dataset['id'],
            url='http://example.com/file.csv',
            schema_url=url
        )

        assert_equals(resource['schema'], url)

        assert 'schema_upload' not in resource
        assert 'schema_url' not in resource 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:19,代碼來源:test_logic.py

示例10: test_validation_options_field

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_validation_options_field(self):

        dataset = factories.Dataset()

        validation_options = {
            'delimiter': ';',
            'headers': 2,
            'skip_rows': ['#'],
        }

        resource = call_action(
            'resource_create',
            package_id=dataset['id'],
            url='http://example.com/file.csv',
            validation_options=validation_options,
        )

        assert_equals(resource['validation_options'], validation_options) 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:20,代碼來源:test_logic.py

示例11: test_validation_options_field_string

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_validation_options_field_string(self):

        dataset = factories.Dataset()

        validation_options = '''{
            "delimiter": ";",
            "headers": 2,
            "skip_rows": ["#"]
        }'''

        resource = call_action(
            'resource_create',
            package_id=dataset['id'],
            url='http://example.com/file.csv',
            validation_options=validation_options,
        )

        assert_equals(resource['validation_options'],
                      json.loads(validation_options)) 
開發者ID:frictionlessdata,項目名稱:ckanext-validation,代碼行數:21,代碼來源:test_logic.py

示例12: test_dataset_doi_admin_sysadmin_verify_xml

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_dataset_doi_admin_sysadmin_verify_xml(self):
        model.repo.rebuild_db()
        dataset = factories.Dataset(author='test author')
        sysadmin = factories.Sysadmin()
        env = {'REMOTE_USER': sysadmin['name'].encode('ascii')}
        url = url_for(
            controller='ckanext.ands.controller:DatasetDoiController', action='dataset_doi_admin',
            id=dataset['name'])
        mock_response = Mock(content=json.dumps(dict(response=dict(responsecode='MT001', doi='testdoi'))))
        mock_post = Mock(return_value=mock_response)

        response = self.app.get(url, extra_environ=env)
        form = response.forms['dataset-doi']
        assert_equal(sorted(form.fields.keys()), ['save', 'xml'])

        with patch.object(requests, 'post', new=mock_post):
            response = form.submit('submit', extra_environ=env)

        # Don't bother checking the mocks, other tests do this

        response = response.follow(extra_environ=env)
        # Shouldn't appear as already created
        response.mustcontain(no='Approve DOI')
        response.mustcontain(no='Request DOI')
        response.mustcontain('Cite this as') 
開發者ID:Psykar,項目名稱:ckanext-ands,代碼行數:27,代碼來源:test_plugin.py

示例13: test_catalog_ttl

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_catalog_ttl(self):

        for i in xrange(4):
            factories.Dataset()

        url = url_for('dcat_catalog', _format='ttl')

        app = self._get_test_app()

        response = app.get(url)

        eq_(response.headers['Content-Type'], 'text/turtle')

        content = response.body

        # Parse the contents to check it's an actual serialization
        p = RDFParser()

        p.parse(content, _format='turtle')

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 4) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:25,代碼來源:test_controllers.py

示例14: test_catalog_modified_date

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_catalog_modified_date(self):

        dataset1 = factories.Dataset(title='First dataset')
        time.sleep(1)
        dataset2 = factories.Dataset(title='Second dataset')

        url = url_for('dcat_catalog',
                      _format='ttl',
                      modified_since=dataset2['metadata_modified'])

        app = self._get_test_app()

        response = app.get(url)

        content = response.body

        p = RDFParser()

        p.parse(content, _format='turtle')

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 1)

        eq_(dcat_datasets[0]['title'], dataset2['title']) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:27,代碼來源:test_controllers.py

示例15: test_spatial_extra_bad_json

# 需要導入模塊: from ckan.tests import factories [as 別名]
# 或者: from ckan.tests.factories import Dataset [as 別名]
def test_spatial_extra_bad_json(self):
        app = self._get_test_app()

        user = factories.User()
        env = {'REMOTE_USER': user['name'].encode('ascii')}
        dataset = factories.Dataset(user=user)

        offset = url_for(controller='package', action='edit', id=dataset['id'])
        res = app.get(offset, extra_environ=env)

        form = res.forms[1]
        form['extras__0__key'] = u'spatial'
        form['extras__0__value'] = u'{"Type":Bad Json]'

        res = helpers.webtest_submit(form, extra_environ=env, name='save')

        assert 'Error' in res, res
        assert 'Spatial' in res
        assert 'Error decoding JSON object' in res 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:21,代碼來源:test_package.py


注:本文中的ckan.tests.factories.Dataset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。