Exemple #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 ''
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 ''
Exemple #3
0
def test_56_add_comment_with_no_label_id(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, label={'pk': 1})
    response = john_doe_api_client.post(url, data=comment_data, format='json')
    data = get_data_from_response(response, status_code=400)
    assert data['label'][0] == 'The primary key is missing. Expected {"id": id, ...}, received %(data)s.' % {'data':{'pk': 1}}
def test_56_add_comment_with_no_label_id(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, label={'pk': 1})
    response = john_doe_api_client.post(url, data=comment_data, format='json')
    data = get_data_from_response(response, status_code=400)
    assert data['label'][0] == 'The primary key is missing. Expected {"id": id, ...}, received %(data)s.' % {'data':{'pk': 1}}
def test_8_get_detail_labels(api_client):
    hearing = Hearing()
    hearing.save()

    label_one = Label(label='Label One')
    label_one.save()
    label_two = Label(label='Label Two')
    label_two.save()
    label_three = Label(label='Label Three')
    label_three.save()

    hearing.labels.add(label_one, label_two, label_three)

    response = api_client.get(get_detail_url(hearing.id))

    data = get_data_from_response(response)

    assert 'results' not in data
    assert len(data['labels']) is 3
    assert label_one.label in data['labels']
Exemple #6
0
def test_8_get_detail_labels(api_client):
    hearing = Hearing(title='')
    hearing.save()

    label_one = Label(label='Label One')
    label_one.save()
    label_two = Label(label='Label Two')
    label_two.save()
    label_three = Label(label='Label Three')
    label_three.save()

    hearing.labels.add(label_one, label_two, label_three)

    response = api_client.get(get_detail_url(hearing.id))

    data = get_data_from_response(response)

    assert 'results' not in data
    assert len(data['labels']) is 3
    assert {
        'id': label_one.id,
        'label': {
            'en': label_one.label
        }
    } in data['labels']
Exemple #7
0
def test_label_str():
    assert str(Label(label="label")) == "label"