Ejemplo n.º 1
0
def test_add_empty_comment_with_label(john_doe_api_client, default_hearing, get_comments_url_and_data):

    label_one = Label(id=1, label='The Label')
    label_one.save()
    section = default_hearing.sections.first()
    url, data = get_comments_url_and_data(default_hearing, section)
    old_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in old_comment_list:
        old_comment_list = old_comment_list['results']

    # set section explicitly
    comment_data = get_comment_data(section=section.pk, content='', label={'id': 1}, geojson=None)
    response = john_doe_api_client.post(url, data=comment_data, format='json')
    data = get_data_from_response(response, status_code=201)

    assert 'label' in data
    assert data["label"] == {'id': 1, 'label': {default_lang_code: 'The Label'}}
    # Check that the comment is available in the comment endpoint now
    new_comment_list = get_data_from_response(john_doe_api_client.get(url))

    comment_data = get_comment_data(section=section.pk, label={'label': {default_lang_code: 'The Label'}, 'id': 1}, content='', geojson=None)
    # If pagination is used the actual data is in "results"
    if 'results' in new_comment_list:
        new_comment_list = new_comment_list['results']

    assert len(new_comment_list) == len(old_comment_list) + 1
    new_comment = [c for c in new_comment_list if c["id"] == data["id"]][0]
    assert_common_keys_equal(new_comment, comment_data)
    assert new_comment["is_registered"] == True
    assert new_comment["label"] == {'id': 1, 'label': {default_lang_code: 'The Label'}}
    assert new_comment["author_name"] is None
    assert new_comment["content"] is ''
Ejemplo n.º 2
0
def test_56_add_empty_comment_with_geojson(john_doe_api_client, default_hearing, get_comments_url_and_data, geojson_feature):
    section = default_hearing.sections.first()
    url, data = get_comments_url_and_data(default_hearing, section)
    old_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in old_comment_list:
        old_comment_list = old_comment_list['results']

    # set section explicitly
    comment_data = get_comment_data(section=section.pk, content='')
    response = john_doe_api_client.post(url, data=comment_data)

    data = get_data_from_response(response, status_code=201)
    assert 'section' in data
    assert data['section'] == section.pk

    assert 'geojson' in data
    assert data['geojson'] == geojson_feature

    # Check that the comment is available in the comment endpoint now
    new_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in new_comment_list:
        new_comment_list = new_comment_list['results']

    assert len(new_comment_list) == len(old_comment_list) + 1
    new_comment = [c for c in new_comment_list if c["id"] == data["id"]][0]
    assert_common_keys_equal(new_comment, comment_data)
    assert new_comment["is_registered"] == True
    assert new_comment["author_name"] is None
Ejemplo n.º 3
0
def test_56_add_comment_to_section_test_geojson(john_doe_api_client,
                                                default_hearing,
                                                get_comments_url_and_data):
    section = default_hearing.sections.first()
    url, data = get_comments_url_and_data(default_hearing, section)
    old_comment_list = get_data_from_response(
        john_doe_api_client.get(url, {'format': 'geojson'}))

    # set section explicitly
    comment_data = get_comment_data(section=section.pk)
    response = john_doe_api_client.post(url, data=comment_data, format='json')
    data = get_data_from_response(response, status_code=201)

    # Check that the comment is available in the comment endpoint now
    new_comment_list = get_data_from_response(
        john_doe_api_client.get(url, {'format': 'geojson'}))

    assert len(
        new_comment_list["features"]) == len(old_comment_list["features"]) + 1
    new_comment = [
        c for c in new_comment_list["features"] if c["id"] == data["id"]
    ][0]
    assert_common_keys_equal(new_comment["geometry"],
                             comment_data["geojson"]["geometry"])
    assert_common_keys_equal(new_comment["properties"],
                             comment_data["geojson"]["properties"])
Ejemplo n.º 4
0
def test_56_add_comment_to_section(john_doe_api_client, default_hearing, get_comments_url_and_data):
    section = default_hearing.sections.first()
    url, data = get_comments_url_and_data(default_hearing, section)
    old_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in old_comment_list:
        old_comment_list = old_comment_list['results']

    # set section explicitly
    comment_data = get_comment_data(section=section.pk)
    response = john_doe_api_client.post(url, data=comment_data)

    data = get_data_from_response(response, status_code=201)
    assert 'section' in data
    assert data['section'] == section.pk

    assert 'content' in data
    assert data['content'] == default_comment_content

    assert 'geojson' in data
    assert data['geojson'] == get_geojson()

    # Check that the comment is available in the comment endpoint now
    new_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in new_comment_list:
        new_comment_list = new_comment_list['results']

    assert len(new_comment_list) == len(old_comment_list) + 1
    new_comment = [c for c in new_comment_list if c["id"] == data["id"]][0]
    assert_common_keys_equal(new_comment, comment_data)
    assert new_comment["is_registered"] == True
    assert new_comment["author_name"] is None
Ejemplo n.º 5
0
def test_add_empty_comment_with_label(john_doe_api_client, default_hearing, get_comments_url_and_data):

    label_one = Label(id=1, label='The Label')
    label_one.save()
    section = default_hearing.sections.first()
    url, data = get_comments_url_and_data(default_hearing, section)
    old_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in old_comment_list:
        old_comment_list = old_comment_list['results']

    # set section explicitly
    comment_data = get_comment_data(section=section.pk, content='', label={'id': 1})
    response = john_doe_api_client.post(url, data=comment_data, format='json')
    data = get_data_from_response(response, status_code=201)

    assert 'label' in data
    assert data["label"] == {'id': 1, 'label': 'The Label'}
    # Check that the comment is available in the comment endpoint now
    new_comment_list = get_data_from_response(john_doe_api_client.get(url))

    comment_data = get_comment_data(section=section.pk, label={'label': 'The Label', 'id': 1}, content='')
    # If pagination is used the actual data is in "results"
    if 'results' in new_comment_list:
        new_comment_list = new_comment_list['results']

    assert len(new_comment_list) == len(old_comment_list) + 1
    new_comment = [c for c in new_comment_list if c["id"] == data["id"]][0]
    assert_common_keys_equal(new_comment, comment_data)
    assert new_comment["is_registered"] == True
    assert new_comment["label"] == {'id': 1, 'label': 'The Label'}
    assert new_comment["author_name"] is None
    assert new_comment["content"] is ''
Ejemplo n.º 6
0
def test_get_contact_person_list_check_fields(api_client, contact_person, valid_contact_person_json):
    data = get_data_from_response(api_client.get('/v1/contact_person/'))
    assert len(data['results']) == 1

    contact_person_data = data['results'][0]
    assert set(contact_person_data.keys()) == {'id', 'title', 'phone', 'email', 'name', 'organization'}
    assert_common_keys_equal(contact_person_data, valid_contact_person_json)
Ejemplo n.º 7
0
def test_56_add_comment_to_section(john_doe_api_client, default_hearing):
    section = default_hearing.sections.first()
    url = get_hearing_detail_url(default_hearing.id, 'sections/%s/comments' % section.id)
    old_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # set section explicitly
    comment_data = get_comment_data(section=section.pk)
    response = john_doe_api_client.post(url, data=comment_data)

    data = get_data_from_response(response, status_code=201)
    assert 'section' in data
    assert data['section'] == section.pk

    assert 'content' in data
    assert data['content'] == default_comment_content

    # Check that the comment is available in the comment endpoint now
    new_comment_list = get_data_from_response(john_doe_api_client.get(url))
    assert len(new_comment_list) == len(old_comment_list) + 1
    new_comment = [c for c in new_comment_list if c["id"] == data["id"]][0]
    assert_common_keys_equal(new_comment, comment_data)
    assert_common_keys_equal(new_comment["created_by"], {
        "first_name": john_doe_api_client.user.first_name,
        "last_name": john_doe_api_client.user.last_name,
        "username": john_doe_api_client.user.username,
    })
Ejemplo n.º 8
0
def test_admin_user_can_PUT_contact_person(john_smith_api_client, contact_person, valid_contact_person_json):
    valid_contact_person_json['organization'] = 'The department for squirrel welfare'
    valid_contact_person_json['name'] = 'John Changed-My-Last-Name'
    response = john_smith_api_client.put('%s%s/' % (endpoint, contact_person.pk), data=valid_contact_person_json, format='json')
    print(response.content)
    data = get_data_from_response(response, status_code=200)
    assert set(data.keys()) == {'id', 'title', 'phone', 'email', 'name', 'organization'}
    assert_common_keys_equal(data, valid_contact_person_json)
def test_get_contact_person_list_check_fields(api_client, contact_person):
    data = get_data_from_response(api_client.get('/v1/contact_person/'))
    assert len(data['results']) == 1

    contact_person_data = data['results'][0]
    assert set(contact_person_data.keys()) == {'id', 'title', 'phone', 'email', 'name', 'organization'}
    assert_common_keys_equal(contact_person_data, {
        'name': 'John Contact',
        'title': 'Chief',
        'phone': '555-555',
        'email': '*****@*****.**',
        'organization': 'The department for squirrel welfare',
    })
Ejemplo n.º 10
0
def test_hearing_geo(api_client, random_hearing):
    random_hearing.geojson = get_geojson()
    random_hearing.save()
    data = get_data_from_response(
        api_client.get(get_detail_url(random_hearing.id)))
    assert data["geojson"] == random_hearing.geojson
    geojson_data = get_data_from_response(
        api_client.get(get_detail_url(random_hearing.id),
                       {'format': 'geojson'}))
    assert_common_keys_equal(geojson_data["geometry"],
                             random_hearing.geojson["geometry"])
    assert_common_keys_equal(geojson_data["properties"],
                             random_hearing.geojson["properties"])
    map_data = get_data_from_response(api_client.get(list_endpoint + "map/"))
    assert map_data['results'][0]["geojson"] == random_hearing.geojson
Ejemplo n.º 11
0
def test_56_add_comment_with_images_to_section(john_doe_api_client,
                                               default_hearing,
                                               get_comments_url_and_data):

    section = default_hearing.sections.first()
    url, data = get_comments_url_and_data(default_hearing, section)
    old_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in old_comment_list:
        old_comment_list = old_comment_list['results']

    # set section explicitly
    comment_data = get_comment_data(section=section.pk,
                                    images=[image_test_json()])
    response = john_doe_api_client.post(url, data=comment_data, format='json')
    data = get_data_from_response(response, status_code=201)

    assert 'images' in data
    assert data['images'][0]['url'].startswith(
        'http://testserver/media/images/')
    # Check that the comment is available in the comment endpoint now
    new_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in new_comment_list:
        new_comment_list = new_comment_list['results']

    # Replace the images with the list of URL returned by the creation
    response_data = deepcopy(comment_data)
    response_data['images'][0].pop('image')
    response_data['images'][0].update({
        'url': data['images'][0]['url'],
        'height': 635,
        'width': 952,
    })

    assert len(new_comment_list) == len(old_comment_list) + 1
    new_comment = [c for c in new_comment_list if c["id"] == data["id"]][0]
    new_comment['images'][0].pop('id')
    assert_common_keys_equal(new_comment, response_data)
    assert new_comment["is_registered"] == True
    assert new_comment["author_name"] is None
Ejemplo n.º 12
0
def assert_hearing_equals(data, posted, user, create=True):
    posted['contact_persons'][0].update({'organization': 'The department for squirrel welfare'})
    posted.pop('id')
    created_at = data.pop('created_at')
    if create:
        assert_datetime_fuzzy_equal(created_at, now())
    organization = data.pop('organization')
    assert organization == user.get_default_organization().name
    assert len(data['sections']) == len(posted['sections'])
    sections_created = data.pop('sections')
    sections_posted = posted.pop('sections')
    assert_common_keys_equal(data, posted)
    for section_created, section_posted in zip(sections_created, sections_posted):
        section_created.pop('id', None)
        created_at = section_created.pop('created_at')
        if create:
            assert_datetime_fuzzy_equal(created_at, now())
            images = section_created.pop('images')
            assert len(images) == len(section_posted['images'])
        assert_common_keys_equal(section_created, section_posted)
Ejemplo n.º 13
0
def assert_hearing_equals(data, posted, user, create=True):
    posted['contact_persons'][0].update({'organization': 'The department for squirrel welfare'})
    posted.pop('id')
    created_at = data.pop('created_at')
    if create:
        assert_datetime_fuzzy_equal(created_at, now())
    organization = data.pop('organization')
    assert organization == user.get_default_organization().name
    assert len(data['sections']) == len(posted['sections'])
    sections_created = data.pop('sections')
    sections_posted = posted.pop('sections')
    assert_common_keys_equal(data, posted)
    for section_created, section_posted in zip(sections_created, sections_posted):
        section_created.pop('id', None)
        created_at = section_created.pop('created_at')
        if create:
            assert_datetime_fuzzy_equal(created_at, now())
            images = section_created.pop('images')
            assert len(images) == len(section_posted['images'])
        assert_common_keys_equal(section_created, section_posted)
Ejemplo n.º 14
0
def test_56_add_comment_with_images_to_section(john_doe_api_client, default_hearing, get_comments_url_and_data):

    section = default_hearing.sections.first()
    url, data = get_comments_url_and_data(default_hearing, section)
    old_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in old_comment_list:
        old_comment_list = old_comment_list['results']

    # set section explicitly
    comment_data = get_comment_data(section=section.pk, images=[image_test_json()])
    response = john_doe_api_client.post(url, data=comment_data, format='json')
    data = get_data_from_response(response, status_code=201)

    assert 'images' in data
    assert data['images'][0]['url'].startswith('http://testserver/media/images/')
    # Check that the comment is available in the comment endpoint now
    new_comment_list = get_data_from_response(john_doe_api_client.get(url))

    # If pagination is used the actual data is in "results"
    if 'results' in new_comment_list:
        new_comment_list = new_comment_list['results']

    # Replace the images with the list of URL returned by the creation
    response_data = deepcopy(comment_data)
    response_data['images'][0].pop('image')
    response_data['images'][0].update({
        'url': data['images'][0]['url'],
        'height': 635,
        'width': 952,
    })

    assert len(new_comment_list) == len(old_comment_list) + 1
    new_comment = [c for c in new_comment_list if c["id"] == data["id"]][0]
    new_comment['images'][0].pop('id')
    assert_common_keys_equal(new_comment, response_data)
    assert new_comment["is_registered"] == True
    assert new_comment["author_name"] is None
Ejemplo n.º 15
0
def test_admin_user_can_post_contact_person(john_smith_api_client, valid_contact_person_json):
    response = john_smith_api_client.post(endpoint, data=valid_contact_person_json, format='json')
    data = get_data_from_response(response, status_code=201)
    print(data)
    assert set(data.keys()) == {'id', 'title', 'phone', 'email', 'name', 'organization'}
    assert_common_keys_equal(data, valid_contact_person_json)