def test_get_with_tasks(random_service, mf_api_client):
    if mf_api_client.format != "json":
        pytest.xfail("tasks are misrendered using the spark convention"
                     )  # TODO: Fix that
    issue = Issue.objects.create(
        service=random_service,
        description=get_random_string(),
        address='Test Street 10',
    )
    for x, time in enumerate((
            now() - timedelta(days=5),
            now() - timedelta(days=2),
    ), 1):
        id = 'foo%04d' % x
        issue.tasks.create(
            task_state=id,
            task_type=id,
            owner_name=id,
            task_created=time,
        )
    content = get_data_from_response(mf_api_client.get(ISSUE_LIST_ENDPOINT, {
        'extensions': 'hel',
    }),
                                     schema=LIST_OF_ISSUES_SCHEMA)
    tasks = content[0]['extended_attributes']['tasks']
    assert tasks
def test_get_by_service_object(testing_issues, mf_api_client):
    issue = testing_issues.first()
    service_object_id = '10844'
    service_object_type = 'http://www.hel.fi/servicemap/v2'
    Issue_CitySDK.objects.create(
        issue=issue,
        service_object_id=service_object_id,
        service_object_type=service_object_type,
    )

    content = get_data_from_response(
        mf_api_client.get(
            ISSUE_LIST_ENDPOINT,
            {
                'extensions': 'citysdk',
                'service_object_id': service_object_id,
                'service_object_type': service_object_type,
            }
        ),
        schema=LIST_OF_ISSUES_SCHEMA
    )

    for issue in content:
        assert issue['extended_attributes']['service_object_id'] == service_object_id
        assert issue['extended_attributes']['service_object_type'] == service_object_type
def test_get_by_service_object_id_without_type(testing_issues, mf_api_client):
    get_data_from_response(mf_api_client.get(
        ISSUE_LIST_ENDPOINT, {
            'extensions': 'citysdk',
            'service_object_id': '10844',
        }),
                           status_code=400)
示例#4
0
def test_handler_query(random_service, mf_api_client):
    handlerless_issue = Issue.objects.create(
        service=random_service,
        description=get_random_string(12),
        address='Test Street 10',
    )
    for x in range(3):
        handlerful_issue = Issue.objects.create(
            service=random_service,
            description=get_random_string(12),
            address='Test Street 10',
        )
        handlerful_issue.log_entries.create(
            status='allocated',
            handler='*****@*****.**',
        )

    content = get_data_from_response(
        mf_api_client.get(
            ISSUE_LIST_ENDPOINT,
            {
                'extensions': 'log',
                'handler': '*****@*****.**',
            }
        ),
        schema=LIST_OF_ISSUES_SCHEMA
    )
    assert len(content) == 3
    assert all(i['extended_attributes']['handler'] == '*****@*****.**' for i in content)
def test_get_with_tasks(random_service, mf_api_client):
    if mf_api_client.format != "json":
        pytest.xfail("tasks are misrendered using the spark convention")  # TODO: Fix that
    issue = Issue.objects.create(
        service=random_service,
        description=get_random_string(),
        address='Test Street 10',
    )
    for x, time in enumerate((
            now() - timedelta(days=5),
            now() - timedelta(days=2),
    ), 1):
        id = 'foo%04d' % x
        issue.tasks.create(
            task_state=id,
            task_type=id,
            owner_name=id,
            task_created=time,
        )
    content = get_data_from_response(
        mf_api_client.get(
            ISSUE_LIST_ENDPOINT,
            {
                'extensions': 'hel',
            }
        ),
        schema=LIST_OF_ISSUES_SCHEMA
    )
    tasks = content[0]['extended_attributes']['tasks']
    assert tasks
示例#6
0
def test_handler_query(random_service, mf_api_client):
    handlerless_issue = Issue.objects.create(
        service=random_service,
        description=get_random_string(),
        address='Test Street 10',
    )
    for x in range(3):
        handlerful_issue = Issue.objects.create(
            service=random_service,
            description=get_random_string(),
            address='Test Street 10',
        )
        handlerful_issue.log_entries.create(
            status='allocated',
            handler='*****@*****.**',
        )

    content = get_data_from_response(
        mf_api_client.get(
            ISSUE_LIST_ENDPOINT,
            {
                'extensions': 'log',
                'handler': '*****@*****.**',
            }
        ),
        schema=LIST_OF_ISSUES_SCHEMA
    )
    assert len(content) == 3
    assert all(i['extended_attributes']['handler'] == '*****@*****.**' for i in content)
def test_by_description(testing_issues, mf_api_client):
    search = 'some'

    content = get_data_from_response(mf_api_client.get(ISSUE_LIST_ENDPOINT, {
        'extensions': 'citysdk',
        'search': search
    }),
                                     schema=LIST_OF_ISSUES_SCHEMA)
    assert search.lower() in content[0]['description'].lower()
示例#8
0
def test_get_with_log(random_service, mf_api_client):
    if mf_api_client.format != "json":
        pytest.xfail("logs are misrendered using the spark convention")  # TODO: Fix that

    # Simulate an issue going through a loggy flow:

    creation = now() - timedelta(days=7)
    issue = Issue.objects.create(
        service=random_service,
        description=get_random_string(12),
        requested_datetime=creation,
        address='Test Street 10',
    )
    issue.log_entries.create(
        time=creation + timedelta(days=2),
        status='allocated',
        handler='*****@*****.**',
    )
    assert Issue_LogExtension.objects.get(issue=issue).last_handler == '*****@*****.**'
    issue.log_entries.create(
        time=creation + timedelta(days=5),
        status='handling',
        handler='*****@*****.**',
        note="i'll deal with this",
    )
    assert Issue_LogExtension.objects.get(issue=issue).last_handler == '*****@*****.**'
    issue.log_entries.create(
        time=creation + timedelta(days=6),
        status='done',
        handler='',
    )
    issue.updated_datetime = now()
    issue.status = 'closed'
    issue.save()

    content = get_data_from_response(
        mf_api_client.get(
            ISSUE_LIST_ENDPOINT,
            {
                'extensions': 'log',
            }
        ),
        schema=LIST_OF_ISSUES_SCHEMA
    )
    assert len(content[0]['extended_attributes']['log']) == 3
    assert content[0]['extended_attributes']['handler'] == '*****@*****.**'  # last non-null handler
示例#9
0
def test_get_with_log(random_service, mf_api_client):
    if mf_api_client.format != "json":
        pytest.xfail("logs are misrendered using the spark convention")  # TODO: Fix that

    # Simulate an issue going through a loggy flow:

    creation = now() - timedelta(days=7)
    issue = Issue.objects.create(
        service=random_service,
        description=get_random_string(),
        requested_datetime=creation,
        address='Test Street 10',
    )
    issue.log_entries.create(
        time=creation + timedelta(days=2),
        status='allocated',
        handler='*****@*****.**',
    )
    assert Issue_LogExtension.objects.get(issue=issue).last_handler == '*****@*****.**'
    issue.log_entries.create(
        time=creation + timedelta(days=5),
        status='handling',
        handler='*****@*****.**',
        note="i'll deal with this",
    )
    assert Issue_LogExtension.objects.get(issue=issue).last_handler == '*****@*****.**'
    issue.log_entries.create(
        time=creation + timedelta(days=6),
        status='done',
        handler='',
    )
    issue.updated_datetime = now()
    issue.status = 'closed'
    issue.save()

    content = get_data_from_response(
        mf_api_client.get(
            ISSUE_LIST_ENDPOINT,
            {
                'extensions': 'log',
            }
        ),
        schema=LIST_OF_ISSUES_SCHEMA
    )
    assert len(content[0]['extended_attributes']['log']) == 3
    assert content[0]['extended_attributes']['handler'] == '*****@*****.**'  # last non-null handler
示例#10
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'])
示例#11
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'])
示例#12
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
示例#13
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