Beispiel #1
0
def test_utilities(client):
    # Hit the docs.
    response = client.get('/')
    assert 200 == response.status_code

    datetime_range = "[2013-03-01 TO 2014-05-02T23:00:00]"
    start, end = registry.parse_datetime_range(datetime_range)
    assert start.get("is_common_era")

    assert start.get("parsed_datetime").year == 2013
    assert start.get("parsed_datetime").month == 3
    assert start.get("parsed_datetime").day == 1
    assert end.get("is_common_era")
    assert end.get("parsed_datetime").year == 2014
    assert end.get("parsed_datetime").month == 5
    assert end.get("parsed_datetime").day == 2
    assert end.get("parsed_datetime").hour == 23
    assert end.get("parsed_datetime").minute == 0
    assert end.get("parsed_datetime").second == 0

    datetime_range = "[-500000000 TO 2014-05-02T23:00:00]"
    start, end = registry.parse_datetime_range(datetime_range)
    assert not start.get("is_common_era")
    assert start.get("parsed_datetime") == "-500000000-01-01T00:00:00Z"

    start, end = registry.parse_datetime_range("[* TO *]")
    assert start.get("is_common_era")
    assert start.get("parsed_datetime") is None
    assert end.get("parsed_datetime") is None

    # test_parse_ISO8601
    quantity, units = registry.parse_ISO8601("P3D")
    assert quantity == 3
    assert units[0] == "DAYS"

    # test_parse_geo_box
    value = registry.parse_geo_box("[-90,-180 TO 90,180]")
    assert value.bounds[0] == -90
    assert value.bounds[1] == -180
    assert value.bounds[2] == 90
    assert value.bounds[3] == 180

    wrong_url = 'http://localhost:9500'
    with pytest.raises(requests.exceptions.ConnectionError) as excinfo:
        response = registry.es_connect(wrong_url)
    assert 'Failed to establish a new connection' in str(excinfo.value)
Beispiel #2
0
def test_single_transaction(client, clear_records):
    '''
    Test single csw transaction.
    '''
    payload = construct_payload(records_number=1)
    response = client.post('/', payload, content_type='text/xml')
    assert 200 == response.status_code

    response = client.get(get_records_url)
    number_records_matched = get_number_records(response)
    assert 200 == response.status_code
    assert 1 == number_records_matched

    # Give backend some time.
    time.sleep(3)

    search_response = requests.get(search_url)
    search_response = search_response.json()
    assert 'hits' in search_response
    assert 'total' in search_response['hits']
    assert 1 == search_response['hits']['total']

    wrong_url = 'http://localhost:9500'
    assert 'connection error' in registry.es_connect(wrong_url)
Beispiel #3
0
def test_utilities(client):
    # Hit the docs.
    response = client.get('/')
    assert 200 == response.status_code

    datetime_range = "[2013-03-01 TO 2014-05-02T23:00:00]"
    start, end = registry.parse_datetime_range(datetime_range)
    assert start.get("is_common_era")

    assert start.get("parsed_datetime").year == 2013
    assert start.get("parsed_datetime").month == 3
    assert start.get("parsed_datetime").day == 1
    assert end.get("is_common_era")
    assert end.get("parsed_datetime").year == 2014
    assert end.get("parsed_datetime").month == 5
    assert end.get("parsed_datetime").day == 2
    assert end.get("parsed_datetime").hour == 23
    assert end.get("parsed_datetime").minute == 0
    assert end.get("parsed_datetime").second == 0

    datetime_range = "[-500000000 TO 2014-05-02T23:00:00]"
    start, end = registry.parse_datetime_range(datetime_range)
    assert not start.get("is_common_era")
    assert start.get("parsed_datetime") == "-500000000-01-01T00:00:00Z"

    start, end = registry.parse_datetime_range("[* TO *]")
    assert start.get("is_common_era")
    assert start.get("parsed_datetime") is None
    assert end.get("parsed_datetime") is None

    # test_parse_ISO8601
    quantity, units = registry.parse_ISO8601("P3D")
    assert quantity == 3
    assert units[0] == "DAYS"

    # test_parse_geo_box
    value = registry.parse_geo_box("[-90,-180 TO 90,180]")
    assert value.bounds[0] == -90
    assert value.bounds[1] == -180
    assert value.bounds[2] == 90
    assert value.bounds[3] == 180

    line = 'fb76f1d7-55bc-4c19-9182-0dbeef4208e6 0 0 0 0 1483721501'
    uuid, reliability_dic = registry.parse_values_from_string(line)
    assert '0' == reliability_dic['valid_bbox']
    assert '0' == reliability_dic['valid_image']
    assert '0' == reliability_dic['valid_config']

    wrong_url = 'http://localhost:9500'
    with pytest.raises(requests.exceptions.ConnectionError) as excinfo:
        response = registry.es_connect(wrong_url)
    assert 'Failed to establish a new connection' in str(excinfo.value)

    check_list = [
        {
            'check_color': '1',
            'timestamp': '2017-01-11 14:30:45',
            'valid_bbox': '0',
            'valid_config': '0',
            'valid_image': '0'
        },
        {
            'check_color': '1',
            'timestamp': '2017-01-11 14:30:56',
            'valid_bbox': '0',
            'valid_config': '0',
            'valid_image': '0'
        },
        {
            'check_color': '0',
            'timestamp': '2017-01-11 14:32:26',
            'valid_bbox': '0',
            'valid_config': '0',
            'valid_image': '0'
        }
    ]
    new_dict = {
        'check_color': '0',
        'timestamp': '2017-01-11 14:32:26',
        'valid_bbox': '0',
        'valid_config': '0',
        'valid_image': '0'
    }
    assert 3 == len(check_list)
    new_list = registry.add_dict_to_list(check_list, new_dict)
    assert 4 == len(new_list)
    reliability_rate = registry.compute_reliability(new_list)
    assert 50.0 == reliability_rate

    # Creating whole white and dark images for testing.
    # We will include new pixel values as noise.
    img = Image.new('L', (200, 150))
    img.putpixel((20, 20), 172)
    img.putpixel((30, 70), 240)
    img.putpixel((120, 100), 120)
    check_color = registry.check_image(img)
    assert 1 == check_color

    img = Image.new('L', (200, 150), 255)
    img.putpixel((20, 20), 172)
    img.putpixel((30, 70), 240)
    img.putpixel((120, 100), 120)
    check_color = registry.check_image(img)
    assert 1 == check_color
def test_utilities(client):
    # Hit the docs.
    response = client.get('/')
    assert 200 == response.status_code

    datetime_range = "[2013-03-01 TO 2014-05-02T23:00:00]"
    start, end = registry.parse_datetime_range(datetime_range)
    assert start.get("is_common_era")

    assert start.get("parsed_datetime").year == 2013
    assert start.get("parsed_datetime").month == 3
    assert start.get("parsed_datetime").day == 1
    assert end.get("is_common_era")
    assert end.get("parsed_datetime").year == 2014
    assert end.get("parsed_datetime").month == 5
    assert end.get("parsed_datetime").day == 2
    assert end.get("parsed_datetime").hour == 23
    assert end.get("parsed_datetime").minute == 0
    assert end.get("parsed_datetime").second == 0

    datetime_range = "[-500000000 TO 2014-05-02T23:00:00]"
    start, end = registry.parse_datetime_range(datetime_range)
    assert not start.get("is_common_era")
    assert start.get("parsed_datetime") == "-500000000-01-01T00:00:00Z"

    start, end = registry.parse_datetime_range("[* TO *]")
    assert start.get("is_common_era")
    assert start.get("parsed_datetime") is None
    assert end.get("parsed_datetime") is None

    # test_parse_ISO8601
    quantity, units = registry.parse_ISO8601("P3D")
    assert quantity == 3
    assert units[0] == "DAYS"

    # test_parse_geo_box
    value = registry.parse_geo_box("[-90,-180 TO 90,180]")
    assert value.bounds[0] == -90
    assert value.bounds[1] == -180
    assert value.bounds[2] == 90
    assert value.bounds[3] == 180

    line = 'fb76f1d7-55bc-4c19-9182-0dbeef4208e6 0 0 0 0 1483721501'
    uuid, reliability_dic = registry.parse_values_from_string(line)
    assert '0' == reliability_dic['valid_bbox']
    assert '0' == reliability_dic['valid_image']
    assert '0' == reliability_dic['valid_config']

    wrong_url = 'http://localhost:9500'
    with pytest.raises(requests.exceptions.ConnectionError) as excinfo:
        response = registry.es_connect(wrong_url)
    assert 'Failed to establish a new connection' in str(excinfo.value)

    check_list = [{
        'check_color': '1',
        'timestamp': '2017-01-11 14:30:45',
        'valid_bbox': '0',
        'valid_config': '0',
        'valid_image': '0'
    }, {
        'check_color': '1',
        'timestamp': '2017-01-11 14:30:56',
        'valid_bbox': '0',
        'valid_config': '0',
        'valid_image': '0'
    }, {
        'check_color': '0',
        'timestamp': '2017-01-11 14:32:26',
        'valid_bbox': '0',
        'valid_config': '0',
        'valid_image': '0'
    }]
    new_dict = {
        'check_color': '0',
        'timestamp': '2017-01-11 14:32:26',
        'valid_bbox': '0',
        'valid_config': '0',
        'valid_image': '0'
    }
    assert 3 == len(check_list)
    new_list = registry.add_dict_to_list(check_list, new_dict)
    assert 4 == len(new_list)
    reliability_rate = registry.compute_reliability(new_list)
    assert 50.0 == reliability_rate

    # Creating whole white and dark images for testing.
    # We will include new pixel values as noise.
    img = Image.new('L', (200, 150))
    img.putpixel((20, 20), 172)
    img.putpixel((30, 70), 240)
    img.putpixel((120, 100), 120)
    check_color = registry.check_image(img)
    assert 1 == check_color

    img = Image.new('L', (200, 150), 255)
    img.putpixel((20, 20), 172)
    img.putpixel((30, 70), 240)
    img.putpixel((120, 100), 120)
    check_color = registry.check_image(img)
    assert 1 == check_color