def test_resource_show_revision_has_download_url(self):
        context = self._get_context(self.org_admin)
        initial_revision = helpers.get_dataset_current_revision(
            self.dataset['name'])

        test_helpers.call_action('package_update',
                                 context,
                                 name=self.dataset['name'],
                                 title='New Title',
                                 notes='New Notes')

        initial_resource = test_helpers.call_action(
            'resource_show',
            context,
            id=self.uploaded_resource['id'],
            revision_ref=initial_revision)

        expected = ('http://localhost:5000/dataset/{dataset_id}/resource/'
                    '{resource_id}/download/{filename}?revision_ref={revision_ref}')\
            .format(dataset_id=self.dataset['id'],
                    resource_id=self.uploaded_resource['id'],
                    filename='my-resource.csv',
                    revision_ref=initial_revision)

        assert_equals(initial_resource['url'], expected)
    def test_resource_show_revision_external_url_is_unchanged(self):
        context = self._get_context(self.org_admin)
        initial_revision = helpers.get_dataset_current_revision(
            self.dataset['name'])

        test_helpers.call_action('package_update',
                                 context,
                                 name=self.dataset['name'],
                                 title='New Title',
                                 notes='New Notes')

        initial_resource = test_helpers.call_action(
            'resource_show',
            context,
            id=self.url_resource['id'],
            revision_ref=initial_revision)

        assert_equals(initial_resource['url'], 'http://link.to.some.data')
    def test_package_show_revision_gets_revision(self):
        context = self._get_context(self.org_admin)
        initial_revision = helpers.get_dataset_current_revision(
            self.dataset['name'])

        test_helpers.call_action('package_update',
                                 context,
                                 name=self.dataset['name'],
                                 title='New Title',
                                 notes='New Notes')

        initial_dataset = test_helpers.call_action(
            'package_show',
            context,
            id=self.dataset['id'],
            revision_ref=initial_revision)

        assert_equals(initial_dataset['title'], 'Test Dataset')
    def test_create_release(self):
        """Test basic dataset release creation
        """
        context = self._get_context(self.org_admin)
        release = test_helpers.call_action(
            'dataset_release_create',
            context,
            dataset=self.dataset['id'],
            name="0.1.2",
            description="The best dataset ever, it **rules!**")

        revision = helpers.get_dataset_current_revision(self.dataset['name'])

        assert_equals(release['package_id'], self.dataset['name'])
        assert_equals(release['revision_ref'], revision)
        assert_equals(release['description'],
                      "The best dataset ever, it **rules!**")
        assert_equals(release['author'], self.org_admin['name'])
        assert_equals(release['author_email'], self.org_admin['email'])