Example #1
0
def default_hearing(john_doe, contact_person):
    """
    Fixture for a "default" hearing with three sections (one main, two other sections).
    All objects will have the 3 default images attached.
    All objects will allow open commenting.
    """
    hearing = Hearing.objects.create(
        title='Default test hearing One',
        open_at=now() - datetime.timedelta(days=1),
        close_at=now() + datetime.timedelta(days=1),
        slug='default-hearing-slug'
    )
    for x in range(1, 4):
        section_type = (InitialSectionType.MAIN if x == 1 else InitialSectionType.SCENARIO)
        section = Section.objects.create(
            abstract='Section %d abstract' % x,
            hearing=hearing,
            type=SectionType.objects.get(identifier=section_type),
            commenting=Commenting.OPEN
        )
        create_default_images(section)
        section.comments.create(created_by=john_doe, content=default_comment_content[::-1])
        section.comments.create(created_by=john_doe, content=red_comment_content[::-1])
        section.comments.create(created_by=john_doe, content=green_comment_content[::-1])

    assert_ascending_sequence([s.ordering for s in hearing.sections.all()])

    hearing.contact_persons.add(contact_person)

    return hearing
Example #2
0
def default_hearing(john_doe, contact_person):
    """
    Fixture for a "default" hearing with three sections (one main, two other sections).
    All objects will have the 3 default images attached.
    All objects will allow open commenting.
    """
    hearing = Hearing.objects.create(
        title='Default test hearing One',
        open_at=now() - datetime.timedelta(days=1),
        close_at=now() + datetime.timedelta(days=1),
        slug='default-hearing-slug')
    for x in range(1, 4):
        section_type = (InitialSectionType.MAIN
                        if x == 1 else InitialSectionType.SCENARIO)
        section = Section.objects.create(
            abstract='Section %d abstract' % x,
            hearing=hearing,
            type=SectionType.objects.get(identifier=section_type),
            commenting=Commenting.OPEN)
        create_default_images(section)
        section.comments.create(created_by=john_doe,
                                content=default_comment_content[::-1])
        section.comments.create(created_by=john_doe,
                                content=red_comment_content[::-1])
        section.comments.create(created_by=john_doe,
                                content=green_comment_content[::-1])

    assert_ascending_sequence([s.ordering for s in hearing.sections.all()])

    hearing.contact_persons.add(contact_person)

    return hearing
Example #3
0
def test_root_endpoint_filters(api_client, default_hearing, random_hearing):

    # random hearing has always atleast one section that is not the main, add images to it
    create_default_images(random_hearing.sections.exclude(type__identifier='main').first())

    url = '/v1/image/'
    section = default_hearing.sections.first()

    response = api_client.get('%s?hearing=%s' % (url, default_hearing.id))
    response_data = get_data_from_response(response)
    assert len(response_data['results']) == 9

    response = api_client.get('%s?section=%s' % (url, section.id))
    response_data = get_data_from_response(response)
    assert len(response_data['results']) == 3

    response = api_client.get('%s?section_type=%s' % (url, 'main'))
    response_data = get_data_from_response(response)
    assert len(response_data['results']) == 3
Example #4
0
def test_root_endpoint_filters(api_client, default_hearing, random_hearing):

    # random hearing has always atleast one section that is not the main, add images to it
    create_default_images(random_hearing.sections.exclude(type__identifier='main').first())

    url = '/v1/image/'
    section = default_hearing.sections.first()

    response = api_client.get('%s?hearing=%s' % (url, default_hearing.id))
    response_data = get_data_from_response(response)
    assert len(response_data['results']) == 9

    response = api_client.get('%s?section=%s' % (url, section.id))
    response_data = get_data_from_response(response)
    assert len(response_data['results']) == 3

    response = api_client.get('%s?section_type=%s' % (url, 'main'))
    response_data = get_data_from_response(response)
    assert len(response_data['results']) == 3