def test_post_service_object(random_service, mf_api_client):
    service_object_id = get_random_string(12)
    service_object_type = 'http://www.hel.fi/servicemap/v2'
    title = get_random_string(12)

    issues = get_data_from_response(
        mf_api_client.post(
            ISSUE_LIST_ENDPOINT + '?extensions=citysdk',
            {
                'service_code': random_service.service_code,
                'lat': 42,
                'long': 42,
                'description': 'hellote',
                'service_object_id': service_object_id,
                'service_object_type': service_object_type,
                'title': title,
            }
        ),
        schema=LIST_OF_ISSUES_SCHEMA,
        status_code=201
    )
    issue = issues[0]
    verify_issue(issue)
    iex = Issue_CitySDK.objects.get(issue__identifier=issue['service_request_id'])

    assert iex.service_object_id == issue['extended_attributes']['service_object_id'] == service_object_id
    assert iex.service_object_type == issue['extended_attributes']['service_object_type'] == service_object_type
    assert iex.title == issue['extended_attributes']['title'] == title
Esempio n. 2
0
def test_post_invalid_json(random_service, mf_api_client):
    response = get_data_from_response(mf_api_client.post(
        ISSUE_LIST_ENDPOINT, {
            'extensions': 'geometry',
            'service_code': random_service.service_code,
            'description': 'Miten tätä ajetaan?',
            'geometry': json.dumps(['oops']),
        }),
                                      status_code=400)
    assert 'JSON' in str(
        response)  # Yeah, it complains about JSON, that's fine
Esempio n. 3
0
def test_post_invalid_geojson(random_service, mf_api_client):
    response = get_data_from_response(mf_api_client.post(
        ISSUE_LIST_ENDPOINT,
        {
            'extensions': 'geometry',
            'service_code': random_service.service_code,
            'description': 'Miten tätä ajetaan?',
            'geometry': json.dumps({'tepe': 'palygon'}),
        },
    ),
                                      status_code=400)
    assert 'Invalid GeoJSON' in str(
        response)  # Complains about GeoJSON, that's nice
Esempio n. 4
0
def test_post_invalid_geojson(random_service, mf_api_client):
    response = get_data_from_response(
        mf_api_client.post(
            ISSUE_LIST_ENDPOINT,
            {
                'extensions': 'geometry',
                'service_code': random_service.service_code,
                'description': 'Miten tätä ajetaan?',
                'geometry': json.dumps({'tepe': 'palygon'}),
            },
        ),
        status_code=400
    )
    assert 'Invalid GeoJSON' in str(response)  # Complains about GeoJSON, that's nice
Esempio n. 5
0
def test_post_invalid_json(random_service, mf_api_client):
    response = get_data_from_response(
        mf_api_client.post(
            ISSUE_LIST_ENDPOINT,
            {
                'extensions': 'geometry',
                'service_code': random_service.service_code,
                'description': 'Miten tätä ajetaan?',
                'geometry': json.dumps(['oops']),
            }
        ),
        status_code=400
    )
    assert 'JSON' in str(response)  # Yeah, it complains about JSON, that's fine
Esempio n. 6
0
def test_post_geometry(random_service, mf_api_client, geometry_data):
    if sys.version_info[0] == 2 and mf_api_client.format != 'json':
        pytest.xfail('unsupported')
    from issues_geometry.models import IssueGeometry
    post_data = {
        'extensions': 'geometry',
        'service_code': random_service.service_code,
        'description': 'Olut on loppu koko jokirannasta',
        'geometry': (
            json.dumps(geometry_data)
            if geometry_data
            else ''
        ),
    }
    if not post_data.get('geometry'):
        post_data['address'] = 'foo street'
    response = mf_api_client.post(ISSUE_LIST_ENDPOINT, data=post_data)

    content = get_data_from_response(
        response,
        status_code=201,
        schema=LIST_OF_ISSUES_SCHEMA,
    )
    issue_data = content[0]
    issue = verify_issue(issue_data)
    if not geometry_data:
        # This exercises the code path where one requests the geometry extension
        # but doesn't actually post geometry after all.
        return
    # No matter the format, we should always have a GeoJSON fragment, whether encoded or indented, in there:
    assert re.search(r'\\*"type\\*":\s*\\*"Polygon\\*"', response.content.decode('utf8'))
    assert IssueGeometry.objects.filter(issue=issue).exists()
    retrieved_issue_data = get_data_from_response(
        mf_api_client.get(
            reverse('georeport/v2:issue-detail', kwargs={'identifier': issue.identifier}),
            {'extensions': 'geometry'},
        )
    )[0]

    for data in (issue_data, retrieved_issue_data):
        verify_issue(data)
        if mf_api_client.format == 'json':
            # We can't access the extended attribute correctly when it has been mangled by the
            # test harness, so only test it when doing native JSON.
            GeoJSONValidator.validate(data['extended_attributes']['geometry'])
Esempio n. 7
0
def test_post_geometry(random_service, mf_api_client, geometry_data):
    if sys.version_info[0] == 2 and mf_api_client.format != 'json':
        pytest.xfail('unsupported')
    from issues_geometry.models import IssueGeometry
    post_data = {
        'extensions': 'geometry',
        'service_code': random_service.service_code,
        'description': 'Olut on loppu koko jokirannasta',
        'geometry': (json.dumps(geometry_data) if geometry_data else ''),
    }
    if not post_data.get('geometry'):
        post_data['address'] = 'foo street'
    response = mf_api_client.post(ISSUE_LIST_ENDPOINT, data=post_data)

    content = get_data_from_response(
        response,
        status_code=201,
        schema=LIST_OF_ISSUES_SCHEMA,
    )
    issue_data = content[0]
    issue = verify_issue(issue_data)
    if not geometry_data:
        # This exercises the code path where one requests the geometry extension
        # but doesn't actually post geometry after all.
        return
    # No matter the format, we should always have a GeoJSON fragment, whether encoded or indented, in there:
    assert re.search(r'\\*"type\\*":\s*\\*"Polygon\\*"',
                     response.content.decode('utf8'))
    assert IssueGeometry.objects.filter(issue=issue).exists()
    retrieved_issue_data = get_data_from_response(
        mf_api_client.get(
            reverse('georeport/v2:issue-detail',
                    kwargs={'identifier': issue.identifier}),
            {'extensions': 'geometry'},
        ))[0]

    for data in (issue_data, retrieved_issue_data):
        verify_issue(data)
        if mf_api_client.format == 'json':
            # We can't access the extended attribute correctly when it has been mangled by the
            # test harness, so only test it when doing native JSON.
            GeoJSONValidator.validate(data['extended_attributes']['geometry'])
Esempio n. 8
0
def test_post_media(mf_api_client, random_service):
    if sys.version_info[0] == 2 and mf_api_client.format in ('xml', 'sjson'):
        pytest.xfail('this test is somehow broken on Py2')

    files = [
        ContentFile(content=VERY_SMALL_JPEG, name="x%d.jpg" % x)
        for x in range(3)
    ]
    issues = get_data_from_response(
        mf_api_client.post(
            f'{ISSUE_LIST_ENDPOINT}?extensions=media',
            data={
                'service_code': random_service.service_code,
                'lat': 30,
                'long': 30,
                'description': get_random_string(12),
                'media': files,
            }
        ),
        status_code=201,
        schema=LIST_OF_ISSUES_SCHEMA,
    )
    id = issues[0]['service_request_id']
    assert Issue.objects.filter(identifier=id).exists()
    assert IssueMedia.objects.filter(issue__identifier=id).count() == 3

    # Now see that we can actually get the media back
    issues = get_data_from_response(
        mf_api_client.get(
            reverse('georeport/v2:issue-detail', kwargs={"identifier": id}),
            {
                'extensions': 'media',
            }
        ),
        schema=LIST_OF_ISSUES_SCHEMA
    )
    issue = issues[0]
    media_list = issue['extended_attributes']['media_urls']
    assert issue
    assert len(media_list) == 3
Esempio n. 9
0
def test_post_media(mf_api_client, random_service):
    if sys.version_info[0] == 2 and mf_api_client.format in ('xml', 'sjson'):
        pytest.xfail('this test is somehow broken on Py2')

    files = [
        ContentFile(content=VERY_SMALL_JPEG, name="x%d.jpg" % x)
        for x in range(3)
    ]
    issues = get_data_from_response(
        mf_api_client.post(
            '%s?extensions=media' % ISSUE_LIST_ENDPOINT,
            data={
                'service_code': random_service.service_code,
                'lat': 30,
                'long': 30,
                'description': get_random_string(),
                'media': files,
            }
        ),
        status_code=201,
        schema=LIST_OF_ISSUES_SCHEMA,
    )
    id = issues[0]['service_request_id']
    assert Issue.objects.filter(identifier=id).exists()
    assert IssueMedia.objects.filter(issue__identifier=id).count() == 3

    # Now see that we can actually get the media back
    issues = get_data_from_response(
        mf_api_client.get(
            reverse('georeport/v2:issue-detail', kwargs={"identifier": id}),
            {
                'extensions': 'media',
            }
        ),
        schema=LIST_OF_ISSUES_SCHEMA
    )
    issue = issues[0]
    media_list = issue['extended_attributes']['media_urls']
    assert issue
    assert len(media_list) == 3