forked from ckan/ckanext-scheming
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6517299
commit 1e8761e
Showing
4 changed files
with
186 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,139 @@ | ||
import pytest | ||
import six | ||
from ckantoolkit.tests.factories import Sysadmin, Dataset | ||
from ckantoolkit.tests.factories import Sysadmin, Dataset, Resource | ||
from bs4 import BeautifulSoup | ||
|
||
|
||
@pytest.mark.usefixtures("clean_db") | ||
class TestDatasetDisplay(object): | ||
def test_dataset_displays_custom_fields(self, app): | ||
user = Sysadmin() | ||
Dataset( | ||
user=user, | ||
type="test-schema", | ||
name="set-one", | ||
humps=3, | ||
resources=[ | ||
{"url": "http://example.com/camel.txt", "camels_in_photo": 2} | ||
], | ||
) | ||
|
||
response = app.get("/dataset/set-one") | ||
assert "Humps" in response.body | ||
|
||
def test_resource_displays_custom_fields(self, app): | ||
user = Sysadmin() | ||
d = Dataset( | ||
user=user, | ||
type="test-schema", | ||
name="set-two", | ||
humps=3, | ||
def test_dataset_view_core_resources(self, app): | ||
dataset = Dataset( | ||
type='test-schema', | ||
name='test', | ||
resources=[ | ||
{ | ||
"url": "http://example.com/camel.txt", | ||
"camels_in_photo": 2, | ||
"date": "2015-01-01", | ||
'url': 'http://example.com/camel.txt', | ||
'resource_type': 'inputs-unaids-geographic' | ||
} | ||
], | ||
) | ||
|
||
response = app.get( | ||
"/dataset/set-two/resource/" + d["resources"][0]["id"] | ||
) | ||
assert "Camels in Photo" in response.body | ||
assert "Date" in response.body | ||
|
||
def test_choice_field_shows_labels(self, app): | ||
user = Sysadmin() | ||
Dataset( | ||
user=user, | ||
type="test-schema", | ||
name="with-choice", | ||
category="hybrid", | ||
) | ||
response = app.get("/dataset/with-choice") | ||
assert "Hybrid Camel" in response.body | ||
|
||
def test_notes_field_displayed(self, app): | ||
user = Sysadmin() | ||
Dataset( | ||
user=user, | ||
type="dataset", | ||
name="plain-jane", | ||
notes="# styled notes", | ||
) | ||
|
||
response = app.get("/dataset/plain-jane") | ||
assert "<h1>styled notes" in response.body | ||
|
||
def test_choice_field_shows_list_if_multiple_options(self, app): | ||
user = Sysadmin() | ||
Dataset( | ||
user=user, | ||
type="test-schema", | ||
name="with-multiple-choice-n", | ||
personality=["friendly", "spits"], | ||
) | ||
|
||
response = app.get("/dataset/with-multiple-choice-n") | ||
|
||
assert ( | ||
"<ul><li>Often friendly</li><li>Tends to spit</li></ul>" | ||
in response.body | ||
) | ||
|
||
def test_choice_field_does_not_show_list_if_one_options(self, app): | ||
user = Sysadmin() | ||
Dataset( | ||
user=user, | ||
type="test-schema", | ||
name="with-multiple-choice-one", | ||
personality=["friendly"], | ||
) | ||
|
||
response = app.get("/dataset/with-multiple-choice-one") | ||
|
||
assert "Often friendly" in response.body | ||
assert "<ul><li>Often friendly</li></ul>" not in response.body | ||
|
||
def test_json_field_displayed(self, app): | ||
user = Sysadmin() | ||
Dataset( | ||
user=user, | ||
type="test-schema", | ||
name="plain-json", | ||
a_json_field={"a": "1", "b": "2"}, | ||
Resource( | ||
package_id=dataset['id'], | ||
resource_type='inputs-unaids-geographic' | ||
) | ||
response = app.get("/dataset/plain-json") | ||
|
||
if six.PY3: | ||
expected = """{\n "a": "1",\n "b": "2"\n}""" | ||
else: | ||
expected = """{\n "a": "1", \n "b": "2"\n}""" | ||
expected = expected.replace( | ||
'"', """ | ||
) # Ask webhelpers | ||
|
||
assert expected in response.body | ||
assert "Example JSON" in response.body | ||
response = app.get('/{}/{}'.format(dataset['type'], dataset['name'])) | ||
assert 'Geographic Data' in response.body | ||
core_resources_container = BeautifulSoup(response.body)\ | ||
.select('.core-resources')[0] | ||
assert dataset['name'] in core_resources_container | ||
|
||
# def test_dataset_displays_custom_fields(self, app): | ||
# user = Sysadmin() | ||
# Dataset( | ||
# user=user, | ||
# type="test-schema", | ||
# name="set-one", | ||
# humps=3, | ||
# resources=[ | ||
# {"url": "http://example.com/camel.txt", "camels_in_photo": 2} | ||
# ], | ||
# ) | ||
|
||
# response = app.get("/dataset/set-one") | ||
# assert "Humps" in response.body | ||
|
||
# def test_resource_displays_custom_fields(self, app): | ||
# user = Sysadmin() | ||
# d = Dataset( | ||
# user=user, | ||
# type="test-schema", | ||
# name="set-two", | ||
# humps=3, | ||
# resources=[ | ||
# { | ||
# "url": "http://example.com/camel.txt", | ||
# "camels_in_photo": 2, | ||
# "date": "2015-01-01", | ||
# } | ||
# ], | ||
# ) | ||
|
||
# response = app.get( | ||
# "/dataset/set-two/resource/" + d["resources"][0]["id"] | ||
# ) | ||
# assert "Camels in Photo" in response.body | ||
# assert "Date" in response.body | ||
|
||
# def test_choice_field_shows_labels(self, app): | ||
# user = Sysadmin() | ||
# Dataset( | ||
# user=user, | ||
# type="test-schema", | ||
# name="with-choice", | ||
# category="hybrid", | ||
# ) | ||
# response = app.get("/dataset/with-choice") | ||
# assert "Hybrid Camel" in response.body | ||
|
||
# def test_notes_field_displayed(self, app): | ||
# user = Sysadmin() | ||
# Dataset( | ||
# user=user, | ||
# type="dataset", | ||
# name="plain-jane", | ||
# notes="# styled notes", | ||
# ) | ||
|
||
# response = app.get("/dataset/plain-jane") | ||
# assert "<h1>styled notes" in response.body | ||
|
||
# def test_choice_field_shows_list_if_multiple_options(self, app): | ||
# user = Sysadmin() | ||
# Dataset( | ||
# user=user, | ||
# type="test-schema", | ||
# name="with-multiple-choice-n", | ||
# personality=["friendly", "spits"], | ||
# ) | ||
|
||
# response = app.get("/dataset/with-multiple-choice-n") | ||
|
||
# assert ( | ||
# "<ul><li>Often friendly</li><li>Tends to spit</li></ul>" | ||
# in response.body | ||
# ) | ||
|
||
# def test_choice_field_does_not_show_list_if_one_options(self, app): | ||
# user = Sysadmin() | ||
# Dataset( | ||
# user=user, | ||
# type="test-schema", | ||
# name="with-multiple-choice-one", | ||
# personality=["friendly"], | ||
# ) | ||
|
||
# response = app.get("/dataset/with-multiple-choice-one") | ||
|
||
# assert "Often friendly" in response.body | ||
# assert "<ul><li>Often friendly</li></ul>" not in response.body | ||
|
||
# def test_json_field_displayed(self, app): | ||
# user = Sysadmin() | ||
# Dataset( | ||
# user=user, | ||
# type="test-schema", | ||
# name="plain-json", | ||
# a_json_field={"a": "1", "b": "2"}, | ||
# ) | ||
# response = app.get("/dataset/plain-json") | ||
|
||
# if six.PY3: | ||
# expected = """{\n "a": "1",\n "b": "2"\n}""" | ||
# else: | ||
# expected = """{\n "a": "1", \n "b": "2"\n}""" | ||
# expected = expected.replace( | ||
# '"', """ | ||
# ) # Ask webhelpers | ||
|
||
# assert expected in response.body | ||
# assert "Example JSON" in response.body |