Beispiel #1
0
    def test_get_dataset_from_kwargs(self):
        data_resource = DataResource()

        bundle = Bundle(data={})
        
        dataset = data_resource.get_dataset_from_kwargs(bundle, dataset_slug=self.dataset.slug)

        self.assertEqual(dataset.id, self.dataset.id)
Beispiel #2
0
    def test_get_dataset_from_kwargs_agree(self):
        data_resource = DataResource()

        bundle = Bundle(data={ 'dataset': '/api/1.0/dataset/%s/' % self.dataset.slug })
        
        dataset = data_resource.get_dataset_from_kwargs(bundle, dataset_slug=self.dataset.slug)

        self.assertEqual(dataset.id, self.dataset.id)
Beispiel #3
0
    def test_get_dataset_from_kwargs_agree(self):
        data_resource = DataResource()

        bundle = Bundle(data={ 'dataset': '/api/1.0/dataset/%s/' % self.dataset.slug })
        
        dataset = data_resource.get_dataset_from_kwargs(bundle, dataset_slug=self.dataset.slug)

        self.assertEqual(dataset.id, self.dataset.id)
Beispiel #4
0
    def test_get_dataset_from_kwargs(self):
        data_resource = DataResource()

        bundle = Bundle(data={})
        
        dataset = data_resource.get_dataset_from_kwargs(bundle, dataset_slug=self.dataset.slug)

        self.assertEqual(dataset.id, self.dataset.id)
Beispiel #5
0
    def test_get_dataset_from_kwargs_conflict(self):
        data_resource = DataResource()

        second_dataset = Dataset.objects.create(name="Second dataset", creator=self.dataset.creator)

        bundle = Bundle(data={"dataset": "/api/1.0/dataset/%s/" % second_dataset.slug})

        with self.assertRaises(BadRequest):
            data_resource.get_dataset_from_kwargs(bundle, dataset_slug=self.dataset.slug)
Beispiel #6
0
    def test_get_dataset_from_kwargs_conflict(self):
        data_resource = DataResource()

        second_dataset = Dataset.objects.create(
            name='Second dataset',
            creator=self.dataset.creator)

        bundle = Bundle(data={ 'dataset': '/api/1.0/dataset/%s/' % second_dataset.slug })
        
        with self.assertRaises(BadRequest):
            data_resource.get_dataset_from_kwargs(bundle, dataset_slug=self.dataset.slug)
Beispiel #7
0
    def override_urls(self):
        """
        Add urls for search endpoint.
        """
        from panda.api.data import DataResource

        data_resource = DataResource(api_name=self._meta.api_name)

        return [
            url(
                r"^(?P<resource_name>%s)/schema%s$" % (self._meta.resource_name, trailing_slash()),
                self.wrap_view("get_schema"),
                name="api_get_schema",
            ),
            url(
                r"^(?P<resource_name>%s)/(?P<slug>[\w\d_-]+)%s$" % (self._meta.resource_name, trailing_slash()),
                self.wrap_view("dispatch_detail"),
                name="api_dispatch_detail",
            ),
            url(
                r"^(?P<resource_name>%s)/(?P<slug>[\w\d_-]+)/import/(?P<upload_id>\d+)%s$"
                % (self._meta.resource_name, trailing_slash()),
                self.wrap_view("import_data"),
                name="api_import_data",
            ),
            url(
                r"^(?P<resource_name>%s)/(?P<slug>[\w\d_-]+)/export%s$" % (self._meta.resource_name, trailing_slash()),
                self.wrap_view("export_data"),
                name="api_export_data",
            ),
            url(
                r"^(?P<resource_name>%s)/(?P<slug>[\w\d_-]+)/reindex%s$" % (self._meta.resource_name, trailing_slash()),
                self.wrap_view("reindex_data"),
                name="api_reindex_data",
            ),
            # Nested urls for accessing data
            url(
                r"^(?P<dataset_resource_name>%s)/(?P<dataset_slug>[\w\d_-]+)/(?P<resource_name>%s)%s$"
                % (self._meta.resource_name, data_resource._meta.resource_name, trailing_slash()),
                data_resource.wrap_view("dispatch_list"),
                name="api_dataset_data_list",
            ),
            url(
                r"^(?P<dataset_resource_name>%s)/(?P<dataset_slug>[\w\d_-]+)/(?P<resource_name>%s)/(?P<external_id>[\w\d_-]+)%s$"
                % (self._meta.resource_name, data_resource._meta.resource_name, trailing_slash()),
                data_resource.wrap_view("dispatch_detail"),
                name="api_dataset_data_detail",
            ),
            url(r"^data%s" % trailing_slash(), data_resource.wrap_view("search_all_data"), name="api_data_search"),
        ]
Beispiel #8
0
    def override_urls(self):
        """
        Add urls for search endpoint.
        """
        from panda.api.data import DataResource

        data_resource = DataResource(api_name=self._meta.api_name)

        return [
            url(r"^(?P<resource_name>%s)/schema%s$" %
                (self._meta.resource_name, trailing_slash()),
                self.wrap_view('get_schema'),
                name="api_get_schema"),
            url(r"^(?P<resource_name>%s)/(?P<slug>[\w\d_-]+)%s$" %
                (self._meta.resource_name, trailing_slash()),
                self.wrap_view('dispatch_detail'),
                name="api_dispatch_detail"),
            url(r'^(?P<resource_name>%s)/(?P<slug>[\w\d_-]+)/import/(?P<upload_id>\d+)%s$'
                % (self._meta.resource_name, trailing_slash()),
                self.wrap_view('import_data'),
                name='api_import_data'),
            url(r'^(?P<resource_name>%s)/(?P<slug>[\w\d_-]+)/export%s$' %
                (self._meta.resource_name, trailing_slash()),
                self.wrap_view('export_data'),
                name='api_export_data'),
            url(r'^(?P<resource_name>%s)/(?P<slug>[\w\d_-]+)/reindex%s$' %
                (self._meta.resource_name, trailing_slash()),
                self.wrap_view('reindex_data'),
                name='api_reindex_data'),

            # Nested urls for accessing data
            url(r'^(?P<dataset_resource_name>%s)/(?P<dataset_slug>[\w\d_-]+)/(?P<resource_name>%s)%s$'
                % (self._meta.resource_name, data_resource._meta.resource_name,
                   trailing_slash()),
                data_resource.wrap_view('dispatch_list'),
                name='api_dataset_data_list'),
            url(r'^(?P<dataset_resource_name>%s)/(?P<dataset_slug>[\w\d_-]+)/(?P<resource_name>%s)/(?P<external_id>[\w\d_-]+)%s$'
                % (self._meta.resource_name, data_resource._meta.resource_name,
                   trailing_slash()),
                data_resource.wrap_view('dispatch_detail'),
                name='api_dataset_data_detail'),
            url(r'^data%s' % trailing_slash(),
                data_resource.wrap_view('search_all_data'),
                name='api_data_search')
        ]