Ejemplo n.º 1
0
def test_hearing_copy(default_hearing, random_label):
    Section.objects.create(
        type=SectionType.objects.get(
            identifier=InitialSectionType.CLOSURE_INFO),
        hearing=default_hearing,
        title='',
        abstract='',
        content='',
    )
    default_hearing.labels.add(random_label)
    new_hearing = copy_hearing(default_hearing,
                               published=False,
                               title='overridden title')
    assert Hearing.objects.count() == 2

    # check that num of sections and images has doubled
    assert Section.objects.count(
    ) == 7  # 3 sections per hearing + 1 old closure info section
    assert SectionImage.objects.count(
    ) == 18  # 3 section images per non closure section

    # check that num of labels hasn't changed
    assert Label.objects.count() == 1

    # check hearing model fields
    for field_name in ('open_at', 'close_at', 'force_closed', 'borough',
                       'servicemap_url', 'geojson'):
        assert getattr(new_hearing,
                       field_name) == getattr(default_hearing, field_name)

    # check overridden fields
    assert new_hearing.published is False
    assert new_hearing.title == 'overridden title'

    assert new_hearing.sections.count() == 3
    for i, new_section in enumerate(
            new_hearing.sections.all().order_by('translations__abstract'), 1):
        # each section should have 3 images, the correct abstract and no comments
        new_section.images.count() == 3
        assert new_section.abstract == 'Section %d abstract' % i
        assert new_section.comments.count() == 0
        assert new_section.n_comments == 0

    assert random_label in new_hearing.labels.all()

    # there should be no comments for the new hearing
    assert new_hearing.n_comments == 0

    # closure info section should not have been copied
    assert not new_hearing.sections.filter(
        type__identifier=InitialSectionType.CLOSURE_INFO).exists()
Ejemplo n.º 2
0
def test_hearing_copy(default_hearing, random_label):
    Section.objects.create(
        type=SectionType.objects.get(identifier=InitialSectionType.CLOSURE_INFO),
        hearing=default_hearing
    )
    default_hearing.labels.add(random_label)
    new_hearing = copy_hearing(default_hearing, published=False, title='overridden title')
    assert Hearing.objects.count() == 2

    # check that num of sections and images has doubled
    assert Section.objects.count() == 7  # 3 sections per hearing + 1 old closure info section
    assert SectionImage.objects.count() == 18  # 3 section images per non closure section
    assert HearingImage.objects.count() == 6  # 3 hearing images per hearing

    # check that num of labels hasn't changed
    assert Label.objects.count() == 1

    # check hearing model fields
    for field_name in ('open_at', 'close_at', 'force_closed', 'abstract', 'borough',
                       'servicemap_url', 'geojson'):
        assert getattr(new_hearing, field_name) == getattr(default_hearing, field_name)

    # check overridden fields
    assert new_hearing.published is False
    assert new_hearing.title == 'overridden title'

    assert new_hearing.sections.count() == 3
    for i, new_section in enumerate(new_hearing.sections.all().order_by('abstract'), 1):
        # each section should have 3 images, the correct abstract and no comments
        new_section.images.count() == 3
        assert new_section.abstract == 'Section %d abstract' % i
        assert new_section.comments.count() == 0
        assert new_section.n_comments == 0

    assert new_hearing.images.count() == 3
    assert random_label in new_hearing.labels.all()

    # there should be no comments for the new hearing
    assert new_hearing.comments.count() == 0
    assert new_hearing.n_comments == 0

    # closure info section should not have been copied
    assert not new_hearing.sections.filter(type__identifier=InitialSectionType.CLOSURE_INFO).exists()
Ejemplo n.º 3
0
 def copy_as_draft(self, request, queryset):
     for hearing in queryset:
         copy_hearing(hearing, published=False)
         self.message_user(
             request, _('Copied Hearing "%s" as a draft.' % hearing.title))
Ejemplo n.º 4
0
 def copy_as_draft(self, request, queryset):
     for hearing in queryset:
         copy_hearing(hearing, published=False)
         self.message_user(request, _('Copied Hearing "%s" as a draft.' % hearing.title))