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 sure fields specifically omitted are actually omitted 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']]) #Make sure merges work f2_json = json.loads(test_figure_json) f2_json['caption'] = '' f2 = Figure(f2_json) assert f2.caption in ('', None) f2.merge(f) assert f2.caption == f.caption
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 sure fields specifically omitted are actually omitted 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']]) #Make sure merges work f2_json = json.loads(test_figure_json) f2_json['caption'] = '' f2 = Figure(f2_json) assert f2.caption in ('', None) f2.merge(f) assert f2.caption == f.caption
def test_chapter_parsing(): webform_fig = Figure(json.loads(webform_json_precip), trans=trans.FIG_TRANSLATIONS) gcis_fig = Figure(json.loads(test_figure_json)) assert isinstance(webform_fig.ordinal, int) assert webform_fig.figure_num == '2.17' assert webform_fig.ordinal == 17 assert webform_fig.chapter == 2 merged_figure = webform_fig.merge(gcis_fig) #FYI, these are identical; I just wanted the variable name to reflect the merge assert id(merged_figure) == id(webform_fig) assert isinstance(gcis_fig.chapter, Chapter) assert merged_figure.figure_num == '2.17' assert merged_figure.ordinal == 17 assert isinstance(merged_figure.chapter, Chapter) assert merged_figure.chapter.number == 2