Commit 641a2267 authored by abuddenberg's avatar abuddenberg
Browse files

Added test suite to mitigate my incompetence

parent 343a40c6
__author__ = 'abuddenberg'
test_figure_json = """
{
"files": [
{
"file_type": null,
"uri": "/file/4cdc6d08-9153-49b2-a924-71f1061dd617",
"url": "/img/ce/22/be3c961e83c6f567744be8a28add/ch02_html_m7f662db3.png",
"href": "http://data.gcis-dev-front.joss.ucar.edu/img/ce/22/be3c961e83c6f567744be8a28add/ch02_html_m7f662db3.png",
"file": "ce/22/be3c961e83c6f567744be8a28add/ch02_html_m7f662db3.png",
"identifier": "4cdc6d08-9153-49b2-a924-71f1061dd617"
}
],
"usage_limits": null,
"contributors": [],
"kindred_figures": [],
"time_end": null,
"href": "http://data.gcis-dev-front.joss.ucar.edu/report/nca3draft/chapter/our-changing-climate/figure/observed-us-temperature-change.json",
"references": [],
"images": [
{
"lon_min": "-124.80",
"create_dt": "2013-08-01T00:00:00",
"lat_max": "49.38",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Map - Contiguous U.S.",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-66.95",
"position": null,
"attributes": "Contiguous U.S., temperature, observed",
"identifier": "8e74f576-a5af-46c0-b33a-f30072118b86",
"lat_min": "24.50",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "-116.03",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "49.00",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Great Plains North",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-95.42",
"position": null,
"attributes": "Great Plains, temperature, observed",
"identifier": "1f5a3cdd-fc45-403e-bf11-d1772005b430",
"lat_min": "40.00",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "-106.63",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "40.00",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Great Plains South",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-93.52",
"position": null,
"attributes": "Great Plains, temperature, observed",
"identifier": "68537d68-b14c-4811-908a-5dc0ab73879b",
"lat_min": "25.83",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "-124.80",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "49.38",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - U.S. Average",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-66.95",
"position": null,
"attributes": "Contiguous U.S., temperature, observed",
"identifier": "230cb2f8-92e0-4897-ab5f-4d6339673832",
"lat_min": "24.50",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "-94.70",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "39.62",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Southeast",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-75.22",
"position": null,
"attributes": "Southeast, temperature, observed",
"identifier": "ca983a87-53a7-4c42-b0e9-18d26fad40ba",
"lat_min": "24.50",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "173.00",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "71.83",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Alaska",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-130.00",
"position": null,
"attributes": "Alaska, temperature, observed",
"identifier": "69da6d93-4426-4061-a2a1-7b3d01f2dc1c",
"lat_min": "54.67",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "-82.67",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "47.46",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Northeast",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-66.95",
"position": null,
"attributes": "Northeast, temperature, observed",
"identifier": "fa83c34b-7b67-4b74-bcba-5bf60ba7730f",
"lat_min": "37.17",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "-97.20",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "49.38",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Midwest",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-80.53",
"position": null,
"attributes": "Midwest, temperature, observed",
"identifier": "b180cfd9-b064-4644-a9a1-d2c3660c1be7",
"lat_min": "36.00",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "-124.40",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "42.00",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Southwest",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-102.00",
"position": null,
"attributes": "Southwest, temperature, observed",
"identifier": "26a28c2a-75f2-47f7-a40f-becfc468d3d6",
"lat_min": "31.33",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "-162.00",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "23.00",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Hawaii",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-154.67",
"position": null,
"attributes": "Hawaii, temperature, observed",
"identifier": "f69194e8-397d-4f9c-836c-335d259ee09c",
"lat_min": "16.92",
"time_start": "1901-01-01T00:00:00"
},
{
"lon_min": "-124.80",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "49.00",
"usage_limits": null,
"description": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Northwest",
"time_end": "2012-12-31T00:00:00",
"lon_max": "-111.00",
"position": null,
"attributes": "Northwest, temperature, observed",
"identifier": "db4d291d-17c5-4e10-b760-6c8799a8d709",
"lat_min": "42.00",
"time_start": "1901-01-01T00:00:00"
}
],
"lat_min": null,
"create_dt": "2013-08-03T10:04:00",
"lat_max": null,
"time_start": null,
"title": "Observed U.S. Temperature Change",
"parents": [],
"ordinal": 7,
"lon_min": null,
"report_identifier": "nca3draft",
"chapter": {
"url": null,
"identifier": "our-changing-climate",
"number": 2,
"report_identifier": "nca3draft",
"title": "Our Changing Climate"
},
"submission_dt": null,
"uri": "/report/nca3draft/chapter/our-changing-climate/figure/observed-us-temperature-change",
"lon_max": null,
"caption": "The colors on the map show temperature changes over the past 22 years (1991-2012) compared to the 1901-1960 average. The bars on the graphs show the average temperature changes by decade for 1901-2012 (relative to the 1901-1960 average) for each region. The far right bar in each graph (2000s decade) includes 2011 and 2012. The period from 2001 to 2012 was warmer than any previous decade in every region.",
"source_citation": "NOAA NCDC / CICS-NC",
"attributes": null,
"identifier": "observed-us-temperature-change",
"chapter_identifier": "our-changing-climate"
}
"""
test_image_json = """
{
"files": [
{
"file_type": null,
"uri": "/file/5b6257ec-5277-4d48-a0e7-f457486b1af1",
"url": "/img/08/6a/9debf1a7b538e2887c0a798a1129/unnamed",
"href": "http://data.gcis-dev-front.joss.ucar.edu/img/08/6a/9debf1a7b538e2887c0a798a1129/unnamed",
"file": "08/6a/9debf1a7b538e2887c0a798a1129/unnamed",
"identifier": "5b6257ec-5277-4d48-a0e7-f457486b1af1"
}
],
"lon_min": "-116.03",
"create_dt": "2013-06-27T15:16:00",
"lat_max": "49.00",
"time_start": "1901-01-01T00:00:00",
"submission_dt": null,
"contributors": [],
"title": "Observed U.S. Temperature Change Decadal Bar Graph - Great Plains North",
"uri": "/image/1f5a3cdd-fc45-403e-bf11-d1772005b430",
"lon_max": "-95.42",
"position": null,
"usage_limits": null,
"href": "http://data.gcis-dev-front.joss.ucar.edu/image/1f5a3cdd-fc45-403e-bf11-d1772005b430.json",
"figures": [
{
"ordinal": 7,
"lon_min": null,
"create_dt": "2013-08-03T10:04:00",
"lat_max": null,
"time_start": null,
"submission_dt": null,
"title": "Observed U.S. Temperature Change",
"report_identifier": "nca3draft",
"lon_max": null,
"caption": "The colors on the map show temperature changes over the past 22 years (1991-2012) compared to the 1901-1960 average. The bars on the graphs show the average temperature changes by decade for 1901-2012 (relative to the 1901-1960 average) for each region. The far right bar in each graph (2000s decade) includes 2011 and 2012. The period from 2001 to 2012 was warmer than any previous decade in every region.",
"usage_limits": null,
"source_citation": "NOAA NCDC / CICS-NC",
"attributes": null,
"identifier": "observed-us-temperature-change",
"time_end": null,
"lat_min": null,
"chapter_identifier": "our-changing-climate"
}
],
"references": [],
"attributes": "Great Plains, temperature, observed",
"parents": [
{
"url": "/dataset/CDDv2",
"note": null,
"publication_type_identifier": "dataset",
"relationship": "prov:wasDerivedFrom",
"label": "dataset : CDDv2"
}
],
"identifier": "1f5a3cdd-fc45-403e-bf11-d1772005b430",
"time_end": "2012-12-31T00:00:00",
"lat_min": "40.00",
"description": null
}
"""
\ No newline at end of file
__author__ = 'abuddenberg'
#To run the tests:
# py.test -v test_suite.py
from test_data import test_figure_json, test_image_json
import json
from domain import Gcisbase, Figure, Image, Dataset, Chapter
def test_gcis_client_version():
assert True
def test_domain():
f = Figure(json.loads(test_figure_json))
assert isinstance(f, Gcisbase)
assert isinstance(f, Figure)
assert len(f.images) == 11
assert all([isinstance(i, Image) for i in f.images])
assert isinstance(f.chapter, Chapter)
assert f.chapter.identifier == 'our-changing-climate'
i = Image(json.loads(test_image_json))
assert isinstance(i, Image)
def test_domain_as_json():
f = Figure(json.loads(test_figure_json))
assert f.original['chapter']['identifier'] == 'our-changing-climate'
assert f.original['images'] not in (None, '')
assert f.original['uri'] not in (None, '')
#Make sured fields specifically
fig_json_out = json.loads(f.as_json())
assert all([omitted_key not in fig_json_out for omitted_key in ['chapter', 'images', 'uri', 'href']])
i = Image(json.loads(test_image_json))
assert i.original['uri'] not in (None, '')
assert i.original['href'] not in (None, '')
img_json_out = json.loads(i.as_json())
assert all([omitted_key not in img_json_out for omitted_key in ['uri', 'href']])
if __name__ == '__main__':
test_domain_as_json()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment