Exemple #1
0
def test_regenerate_css_with_new_checksum(event):
    with scope(event=event):
        event.primary_color = "#ff0000"
        event.save()

        regenerate_css(event.pk)
        regenerate_css(event.pk)  # Second time will match the checksum
Exemple #2
0
def test_regenerate_css_no_color(event):
    from pretalx.common.tasks import regenerate_css
    event.primary_color = None
    event.save()
    regenerate_css(event.pk)
    event = Event.objects.get(pk=event.pk)
    for local_app in ['agenda', 'cfp', 'orga']:
        assert not event.settings.get(f'{local_app}_css_file')
        assert not event.settings.get(f'{local_app}_css_checksum')
def test_regenerate_css_no_color(event):
    from pretalx.common.tasks import regenerate_css

    event.primary_color = None
    event.save()
    regenerate_css(event.pk)
    event = Event.objects.get(pk=event.pk)
    for local_app in ["agenda", "cfp"]:
        assert not event.settings.get(f"{local_app}_css_file")
        assert not event.settings.get(f"{local_app}_css_checksum")
    assert not event.settings.widget_css
def test_regenerate_css(event):
    from pretalx.common.tasks import regenerate_css

    event.primary_color = "#00ff00"
    event.settings.widget_css_checksum = "placeholder"
    event.save()
    regenerate_css(event.pk)
    event = Event.objects.get(pk=event.pk)
    for local_app in ["agenda", "cfp"]:
        assert event.settings.get(f"{local_app}_css_file")
        assert event.settings.get(f"{local_app}_css_checksum")
    assert event.settings.widget_css_checksum != "placeholder"
    assert event.settings.widget_css
def test_html_export_full(event, other_event, slot, confirmed_resource,
                          canceled_talk):
    from django.core.management import call_command  # Import here to avoid overriding mocks

    event.primary_color = '#111111'
    event.is_public = False
    event.save()
    other_event.primary_color = '#222222'
    other_event.save()

    with override_settings(COMPRESS_ENABLED=True, COMPRESS_OFFLINE=True):
        call_command('rebuild')
        regenerate_css(event.pk)
        regenerate_css(other_event.pk)
        event = Event.objects.get(slug=event.slug)
        assert event.settings.agenda_css_file
        call_command('export_schedule_html', event.slug, '--zip')

    paths = [
        'static/common/img/logo.svg',
        f'media/test/{event.settings.agenda_css_file.split("/")[-1]}',
        'test/schedule/index.html',
        'test/schedule/export/schedule.json',
        'test/schedule/export/schedule.xcal',
        'test/schedule/export/schedule.xml',
        'test/schedule/export/schedule.ics',
        *[
            f'test/speaker/{speaker.code}/index.html'
            for speaker in slot.submission.speakers.all()
        ],
        f'test/talk/{slot.submission.code}/index.html',
        f'test/talk/{slot.submission.code}.ics',
        confirmed_resource.resource.url.lstrip('/'),
    ]

    for path in paths:
        full_path = settings.HTMLEXPORT_ROOT / 'test' / path
        assert full_path.exists()

    for path in (settings.HTMLEXPORT_ROOT / 'test/media/').glob('*'):
        path = str(path)
        assert event.slug in path
        assert other_event.slug not in path

    full_path = settings.HTMLEXPORT_ROOT / 'test.zip'
    assert full_path.exists()

    # views and templates are the same for export and online viewing, so a naive test is enough here
    talk_html = (settings.HTMLEXPORT_ROOT / 'test' /
                 f'test/talk/{slot.submission.code}/index.html').open().read()
    assert talk_html.count(slot.submission.title) >= 2

    speaker = slot.submission.speakers.all()[0]
    schedule_html = (settings.HTMLEXPORT_ROOT / 'test' /
                     f'test/schedule/index.html').open().read()
    assert 'Contact us' in schedule_html  # locale
    assert canceled_talk.submission.title not in schedule_html

    schedule_json = json.load(
        (settings.HTMLEXPORT_ROOT /
         f'test/test/schedule/export/schedule.json').open())
    assert schedule_json['schedule']['conference']['title'] == event.name

    schedule_ics = (settings.HTMLEXPORT_ROOT /
                    f'test/test/schedule/export/schedule.ics').open().read()
    assert slot.submission.code in schedule_ics
    assert canceled_talk.submission.code not in schedule_ics

    schedule_xcal = (settings.HTMLEXPORT_ROOT /
                     f'test/test/schedule/export/schedule.xcal').open().read()
    assert event.slug in schedule_xcal
    assert speaker.name in schedule_xcal

    schedule_xml = (settings.HTMLEXPORT_ROOT /
                    f'test/test/schedule/export/schedule.xml').open().read()
    assert slot.submission.title in schedule_xml
    assert canceled_talk.submission.frab_slug not in schedule_xml
    assert str(canceled_talk.submission.uuid) not in schedule_xml

    talk_ics = (settings.HTMLEXPORT_ROOT /
                f'test/test/talk/{slot.submission.code}.ics').open().read()
    assert slot.submission.title in talk_ics
    assert event.is_public is False
Exemple #6
0
    def build_event(self, end_stage):
        administrators = User.objects.filter(is_administrator=True)
        if not administrators:
            self.stdout.write(
                self.style.ERROR(
                    'Please run the "init" command to create an administrator user.'
                ))
            return
        organiser, team = create_organiser_with_team(
            name='DemoCon Org',
            slug='democonorg',
            users=administrators,
        )
        if end_stage == 'cfp':
            event_start = now() + dt.timedelta(days=35)
        elif end_stage == 'review':
            event_start = now() + dt.timedelta(days=25)
        elif end_stage == 'over':
            event_start = now() - dt.timedelta(days=10)
        else:  # end_stage == 'schedule'
            event_start = now() - dt.timedelta(days=1)
        self.bs = self.fake.bs()
        self.catch_phrase = self.fake.catch_phrase()
        intro = f'We provide a {self.catch_phrase.lower()} to {self.bs}.'
        disclaimer = '''This is an automatically generated event to test and showcase pretalx features.
Feel free to look around, but don\'t be alarmed if something doesn\'t quite make sense. You can always create your own free test event at [pretalx.com](https://pretalx.com)!'''
        with scopes_disabled():
            event = Event.objects.create(
                name='DemoCon',
                slug='democon',
                organiser=organiser,
                is_public=True,
                date_from=event_start.date(),
                date_to=event_start.date() + dt.timedelta(days=2),
                timezone='Europe/Berlin',
                email=self.fake.user_name() + '@example.org',
                primary_color=self.fake.hex_color(),
                locale_array='en',
                locale='en',
                landing_page_text=
                f'# Welcome to DemoCon!\n\n{intro}\n\n{disclaimer}',
            )
        with scope(event=event):
            event.build_initial_data()
            team.limit_events.add(event)
            SubmissionType.objects.create(event=event,
                                          name='Workshop',
                                          default_duration=90)

            event.settings.use_tracks = True
            for _ in range(self.fake.random_int(min=2, max=5)):
                Track.objects.create(
                    event=event,
                    name=self.fake.catch_phrase().split()[0],
                    color=self.fake.hex_color(),
                )
            event.cfp.headline = 'DemoCon submissions are {}!'.format(
                'open' if end_stage == 'cfp' else 'closed')
            track_text = '\n'.join(f'- {track.name}'
                                   for track in event.tracks.all())
            event.cfp.text = f'''This is the Call for Participation for DemoCon!\n\n{intro}\n\n

We are always on the look-out for speakers who can provide {self.fake.bs()} – if that is you, please submit a talk or a workshop! We accept submissions for the following tracks:

{track_text}

We explicitly encourage new speakers and multiple submissions per person.
If you have any interest in {self.fake.catch_phrase().lower()}, {self.fake.catch_phrase().lower()}, {self.fake.catch_phrase().lower()} – or something else you think matches our conference, please submit your proposal!

{disclaimer}
'''
            event.cfp.deadline = event.datetime_from - dt.timedelta(days=60)
            event.cfp.save()
            event.settings.display_header_pattern = random.choice(
                ('', 'pcb', 'bubbles', 'signal', 'topo', 'graph'))
            event.settings.review_max_score = 2
            self.event = event
            self.build_room()
            self.build_room()
            regenerate_css(event.pk)
        return event
Exemple #7
0
def test_html_export_full(
    event,
    other_event,
    slot,
    confirmed_resource,
    canceled_talk,
    orga_client,
    django_assert_max_num_queries,
):
    from django.core.management import (
        call_command, )  # Import here to avoid overriding mocks

    event.primary_color = "#111111"
    event.is_public = False
    event.save()
    other_event.primary_color = "#222222"
    other_event.save()

    with override_settings(COMPRESS_ENABLED=True, COMPRESS_OFFLINE=True):
        call_command("rebuild")
        regenerate_css(event.pk)
        regenerate_css(other_event.pk)
        event = Event.objects.get(slug=event.slug)
        assert event.settings.agenda_css_file
        call_command("export_schedule_html", event.slug, "--zip")

    paths = [
        "static/common/img/logo.svg",
        f'media/test/{event.settings.agenda_css_file.split("/")[-1]}',
        "test/schedule/index.html",
        "test/schedule/export/schedule.json",
        "test/schedule/export/schedule.xcal",
        "test/schedule/export/schedule.xml",
        "test/schedule/export/schedule.ics",
        *[
            f"test/speaker/{speaker.code}/index.html"
            for speaker in slot.submission.speakers.all()
        ],
        f"test/talk/{slot.submission.code}/index.html",
        f"test/talk/{slot.submission.code}.ics",
        confirmed_resource.resource.url.lstrip("/"),
    ]

    for path in paths:
        full_path = settings.HTMLEXPORT_ROOT / "test" / path
        assert full_path.exists()

    for path in (settings.HTMLEXPORT_ROOT / "test/media/").glob("*"):
        path = str(path)
        assert event.slug in path
        assert other_event.slug not in path

    full_path = settings.HTMLEXPORT_ROOT / "test.zip"
    assert full_path.exists()

    # views and templates are the same for export and online viewing, so a naive test is enough here
    talk_html = (
        (settings.HTMLEXPORT_ROOT / "test" /
         f"test/talk/{slot.submission.code}/index.html").open().read())
    assert talk_html.count(slot.submission.title) >= 2

    speaker = slot.submission.speakers.all()[0]
    schedule_html = ((settings.HTMLEXPORT_ROOT / "test" /
                      f"test/schedule/index.html").open().read())
    assert "Contact us" in schedule_html  # locale
    assert canceled_talk.submission.title not in schedule_html

    schedule_json = json.load(
        (settings.HTMLEXPORT_ROOT /
         f"test/test/schedule/export/schedule.json").open())
    assert schedule_json["schedule"]["conference"]["title"] == event.name

    schedule_ics = ((settings.HTMLEXPORT_ROOT /
                     f"test/test/schedule/export/schedule.ics").open().read())
    assert slot.submission.code in schedule_ics
    assert canceled_talk.submission.code not in schedule_ics

    schedule_xcal = (
        (settings.HTMLEXPORT_ROOT /
         f"test/test/schedule/export/schedule.xcal").open().read())
    assert event.slug in schedule_xcal
    assert speaker.name in schedule_xcal

    schedule_xml = ((settings.HTMLEXPORT_ROOT /
                     f"test/test/schedule/export/schedule.xml").open().read())
    with scope(event=slot.submission.event):
        assert slot.submission.title in schedule_xml
        assert canceled_talk.frab_slug not in schedule_xml
        assert str(canceled_talk.uuid) not in schedule_xml

    talk_ics = ((settings.HTMLEXPORT_ROOT /
                 f"test/test/talk/{slot.submission.code}.ics").open().read())
    assert slot.submission.title in talk_ics
    assert event.is_public is False

    with django_assert_max_num_queries(45):
        response = orga_client.get(event.orga_urls.schedule_export_download,
                                   follow=True)
    assert response.status_code == 200
    streaming_content = getattr(response, "streaming_content", None)
    if streaming_content:
        assert len(b"".join(response.streaming_content)) > 100_000  # 100 KB
def test_regenerate_css_no_event():
    from pretalx.common.tasks import regenerate_css

    regenerate_css(123)