Example #1
0
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
Example #2
0
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
Example #3
0
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)

    assert len(f.contributors) == 2
    assert all([isinstance(cont, Contributor) for cont in f.contributors])

    empty_img = Image({})
    assert empty_img.identifier is None
Example #4
0
def populate_image(img_json):
    img = Image({})
    try:
        img.title = img_json['graphics_title']
        img.identifier = img_json['image_id'] if img_json[
            'image_id'] else re.sub('\W', '_', img.title).lower()
        img.create_dt = img_json['graphics_create_date']
        img.time_start, img.time_end = img_json['period_record']
        img.lat_min, img.lat_max, img.lon_min, img.lon_max = img_json[
            'spatial_extent']
    except Exception, e:
        print 'Image exception: ', e
Example #5
0
def populate_image(img_json):
    img = Image({})
    try:
        img.title = img_json['graphics_title']
        img.identifier = img_json['image_id'] if img_json['image_id'] else re.sub('\W', '_', img.title).lower()
        img.create_dt = img_json['graphics_create_date']
        img.time_start, img.time_end = img_json['period_record']
        img.lat_min, img.lat_max, img.lon_min, img.lon_max = img_json['spatial_extent']
    except Exception, e:
        print 'Image exception: ', e
Example #6
0
def populate_image(img_json):
    img = Image({})
    try:
        img.title = img_json['graphics_title']
        img.identifier = img_json[
            'image_id'] if 'image_id' in img_json and img_json[
                'image_id'] else re.sub('\W', '_',
                                        img.title.strip().lower())
        img.create_dt = img_json['graphics_create_date'].strip()
        if any(img_json['period_record']):
            img.time_start, img.time_end = [
                d.strip() for d in img_json['period_record']
            ]
        img.lat_min, img.lat_max, img.lon_min, img.lon_max = img_json[
            'spatial_extent']
    except Exception, e:
        warning('Image exception: ', e)