Ejemplo n.º 1
0
def test_webinar_invite_emails_for_initial_publish(
    alternative_hosts,
    panelists,
    invites_by_email_address,
    invited_user_cohort,
    expected,
    business_line,
    mocker
):
    """
    Test that the webinar invitation emails are sent correctly to all the correct recipients
    when a webinar is published for the first time
    """
    mocker.patch(
        'openedx.adg.lms.webinars.models.Webinar.get_platform_and_non_platform_team_members',
        return_value=(set(extract_emails_from_string(alternative_hosts) + extract_emails_from_string(panelists)), set())
    )
    mocker.patch('openedx.adg.lms.webinars.models.send_webinar_update_emails')
    mock_zoom_client = mocker.patch.object(ZoomClient, 'create_webinar')
    mock_send_webinar_emails = mocker.patch('openedx.adg.lms.webinars.helpers.send_webinar_emails')

    user_a = UserFactory(email='*****@*****.**')
    UserApplicationFactory(business_line=BusinessLineFactory(title=BUSINESS_LINE), user=user_a)

    user_b = UserFactory(email='*****@*****.**')
    UserApplicationFactory(business_line=business_line, user=user_b)

    webinar = WebinarFactory(
        alternative_hosts=alternative_hosts,
        panelists=panelists,
        invites_by_email_address=invites_by_email_address,
        invited_user_cohort=invited_user_cohort,
        is_published=False
    )

    mock_zoom_client.return_value = {
        'join_url': webinar.meeting_link,
        'id': webinar.id,
    }

    webinar.publish()

    expected_emails = set(expected)
    if invited_user_cohort == INVITE_ALL_USERS:
        expected_emails = expected_emails.union(set(User.objects.exclude(email='').values_list('email', flat=True)))
    else:
        expected_emails = expected_emails.union(set(BusinessLine.user_emails_for_business_line(invited_user_cohort)))

    if expected or invited_user_cohort:
        template, _, actual_email_addresses = mock_send_webinar_emails.call_args.args
        assert template == MandrillClient.WEBINAR_CREATED
        assert sorted(list(expected_emails)) == sorted(actual_email_addresses)
    else:
        mock_send_webinar_emails.assert_not_called()
Ejemplo n.º 2
0
def test_team_invitation_is_sent_to_unregistered_panelists_and_alt_hosts(
    registered_panelist,
    unregistered_panelist,
    registered_alt_host,
    unregistered_alt_host,
    normal_invites,
    team_invites,
    mocker
):
    """
    Test that only the panelists and alternative hosts that do not have an account on the platform are
    sent a special kind of invitation with extra text. The rest of the invitees are sent
    a normal invitation
    """
    mocker.patch(
        'openedx.adg.lms.webinars.models.Webinar.get_platform_and_non_platform_team_members',
        return_value=(
            set(extract_emails_from_string(registered_alt_host) + extract_emails_from_string(registered_panelist)),
            set(extract_emails_from_string(unregistered_alt_host) + extract_emails_from_string(unregistered_panelist))
        )
    )
    mocker.patch('openedx.adg.lms.webinars.models.send_webinar_update_emails')
    mock_zoom_client = mocker.patch.object(ZoomClient, 'create_webinar')
    mock_send_webinar_emails = mocker.patch('openedx.adg.lms.webinars.helpers.send_webinar_emails')

    UserFactory(email=registered_panelist)
    UserFactory(email=registered_alt_host)

    webinar = WebinarFactory(
        alternative_hosts=f'{registered_alt_host}, {unregistered_alt_host}',
        panelists=f'{registered_panelist}, {unregistered_panelist}',
        is_published=False
    )

    mock_zoom_client.return_value = {
        'join_url': webinar.meeting_link,
        'id': webinar.id,
    }

    webinar.publish()

    if normal_invites or team_invites:
        all_calls_for_send_webinar_emails = mock_send_webinar_emails.call_args_list
        assert len(all_calls_for_send_webinar_emails) == bool(normal_invites) + bool(team_invites)

        for mock_send_webinar_emails_call in all_calls_for_send_webinar_emails:
            template, _, recipients = mock_send_webinar_emails_call.args
            if template == MandrillClient.WEBINAR_CREATED:
                assert sorted(recipients) == sorted(normal_invites)
            else:
                assert sorted(recipients) == sorted(team_invites)
    else:
        mock_send_webinar_emails.assert_not_called()
Ejemplo n.º 3
0
def test_webinar_form_save(mocker, current_time, webinar_data,
                           is_valid_start_date):
    """
    Test that the WebinarForm saves the webinar attributes data correctly
    """
    webinar = WebinarFactory()
    webinar_data['alternative_hosts'] = '[email protected], [email protected]'
    mock_check_and_get_invalid_alternative_hosts = mocker.patch(
        'openedx.adg.admin_dashboard.webinars.forms.ZoomClient.check_and_get_invalid_alternative_hosts'
    )
    mock_check_and_get_invalid_alternative_hosts.return_value = (True, [])
    webinar_form = WebinarForm(instance=webinar, data=webinar_data)

    if not is_valid_start_date:
        webinar_data['start_time_year'] -= 1
        assert not webinar_form.is_valid()
    else:
        assert webinar_form.is_valid()
        webinar_form.save()

        assert webinar.title == 'Test Title'
        assert webinar.description == 'Test Description'
        assert webinar.start_time.day == current_time.day
        assert webinar.start_time.month == current_time.month
        assert webinar.start_time.year == current_time.year + 1
        assert webinar.audio_settings == Webinar.BOTH
Ejemplo n.º 4
0
def test_get_selected_number_of_webinars(show_all_or_limit, expected_number):
    """
    Test that the `_get_selected_number_of_webinars` method returns the right amount of webinars
    """
    dummy_webinars = WebinarFactory.create_batch(10)
    # pylint:disable=protected-access
    assert len(WebinarListView()._get_selected_number_of_webinars(
        dummy_webinars, show_all_or_limit)) == expected_number
Ejemplo n.º 5
0
def test_webinar_description_view_valid_pk(mock_select_template, user_client):
    """
    Test webinar description with valid pk
    """
    _, client = user_client
    webinar = WebinarFactory(is_cancelled=False)

    client.get(reverse('webinar_event', kwargs={'pk': webinar.id}))

    mock_select_template.assert_called_once_with(
        ['adg/lms/webinar/description_page.html'], using=None)
Ejemplo n.º 6
0
def test_convert_date_time_zone_and_format():
    """
    Test convert_time_zone helper
    """
    webinar = WebinarFactory(start_time=datetime(2020, 1, 1, 13, 10, 1))

    expected_date_time = 'Wednesday, January 01, 2020 04:10 PM AST'
    actual_date_time = convert_date_time_zone_and_format(
        webinar.start_time, WEBINAR_DEFAULT_TIME_ZONE,
        WEBINAR_DATE_TIME_FORMAT)

    assert expected_date_time == actual_date_time
Ejemplo n.º 7
0
def test_webinar_form_save__invalid_alternative_hosts(
        mocker, webinar_data,
        check_and_get_invalid_alternative_hosts_return_value):
    """
    Test invalid WebinarForm due to alternative_hosts
    """
    webinar = WebinarFactory()
    webinar_data['alternative_hosts'] = '[email protected], [email protected]'
    mock_check_and_get_invalid_alternative_hosts = mocker.patch(
        'openedx.adg.admin_dashboard.webinars.forms.ZoomClient.check_and_get_invalid_alternative_hosts'
    )
    mock_check_and_get_invalid_alternative_hosts.return_value = check_and_get_invalid_alternative_hosts_return_value
    webinar_form = WebinarForm(instance=webinar, data=webinar_data)
    assert not webinar_form.is_valid()
Ejemplo n.º 8
0
def test_webinar_registration_view_cancelled_webinar(client, user_client):
    """
    Test webinar registration if webinar is cancelled
    """
    _, client = user_client
    webinar = WebinarFactory(is_cancelled=True)

    response = client.post(
        reverse('webinars_api:webinar_registration',
                kwargs={
                    'pk': webinar.id,
                    'action': 'register'
                }))

    assert response.status_code == HTTP_500_INTERNAL_SERVER_ERROR
Ejemplo n.º 9
0
def test_send_webinar_registration_email(mocker):
    """
    Test sending webinar registration email to user
    """
    mocker.patch('openedx.adg.lms.webinars.models.send_webinar_invitation_emails')
    mock_task = mocker.patch('openedx.adg.lms.webinars.helpers.task_send_mandrill_email.delay')
    webinar = WebinarFactory(start_time=datetime(2020, 1, 1, 13, 10, 1))
    email = '*****@*****.**'

    send_webinar_registration_email(webinar, email)

    mock_task.assert_called_once_with(MandrillClient.WEBINAR_REGISTRATION_CONFIRMATION, [email], {
        'webinar_title': webinar.title,
        'webinar_description': webinar.description,
        'webinar_link': webinar.meeting_link,
        'webinar_start_time': 'Wednesday, January 01, 2020 04:10 PM AST',
    })
Ejemplo n.º 10
0
def test_send_webinar_emails(mocker, template_slug):
    """
    Test if `send_webinar_emails` is sending the email with the correct data
    """
    mocked_task_send_mandrill_email = mocker.patch('openedx.adg.lms.webinars.helpers.task_send_mandrill_email')

    webinar = WebinarFactory()
    send_webinar_emails(template_slug, webinar, ['*****@*****.**'])

    expected_context = {
        'webinar_id': webinar.id,
        'webinar_title': webinar.title,
        'webinar_description': webinar.description,
        'webinar_start_time': webinar.start_date_time_AST,
        'webinar_link': webinar.meeting_link,
    }

    if template_slug in [MandrillClient.WEBINAR_CREATED, MandrillClient.WEBINAR_TEAM_INVITE]:
        expected_context['register_link'] = get_webinar_description_link(webinar.id)

    mocked_task_send_mandrill_email.delay.assert_called_with(template_slug, ['*****@*****.**'], expected_context, None)
Ejemplo n.º 11
0
def test_webinar_description_context_data(user_with_profile):
    """
    Test webinar description context data
    """
    webinar = WebinarFactory(is_cancelled=False)
    kwargs = {'pk': webinar.id}
    webinar_description_request = RequestFactory().get(
        reverse('webinar_event', kwargs=kwargs))
    webinar_description_request.user = user_with_profile

    response = WebinarDetailView.as_view()(webinar_description_request,
                                           **kwargs)
    context_data = response.context_data

    expected_register_url = reverse('webinars_api:webinar_registration',
                                    kwargs={
                                        'pk': webinar.id,
                                        'action': 'register'
                                    })
    expected_cancel_url = reverse('webinars_api:webinar_registration',
                                  kwargs={
                                      'pk': webinar.id,
                                      'action': 'cancel'
                                  })
    expected_description_url = reverse('webinar_event',
                                       kwargs={'pk': webinar.id})

    assert context_data['register_url'] == expected_register_url
    assert context_data['cancel_url'] == expected_cancel_url
    assert context_data['webinar_description_url'] == expected_description_url
    assert 'is_registered' in context_data
    assert 'send_post_call_to_register' in context_data
    assert 'register_url_for_unauth_users' in context_data
    assert 'registration' in context_data
    assert 'google_url' in context_data
    assert 'yahoo_url' in context_data
Ejemplo n.º 12
0
def test_context_data_webinar_list_view(show_upcoming, show_saved,
                                        show_cancelled, expected_upcoming,
                                        expected_saved, expected_cancelled,
                                        super_user):
    """
    Test that the `get_webinars` method returns all the webinar querysets correctly for
    all cases i.e For show all webinars case and for show limited webinars case
    """
    WebinarFactory.create_batch(4)
    WebinarFactory.create_batch(5, is_published=False)
    WebinarFactory.create_batch(6, is_cancelled=True)

    webinar_list_url = reverse('webinars_list')
    request_for_webinar_list_page = RequestFactory().get(
        f'{webinar_list_url}?upcoming={show_upcoming}&saved={show_saved}&cancelled={show_cancelled}'
    )
    request_for_webinar_list_page.user = super_user

    response = WebinarListView.as_view()(request_for_webinar_list_page)

    context = response.context_data
    context_keys = context.keys()

    assert response.status_code == 200

    assert 'show_upcoming' in context_keys
    assert 'upcoming_webinars' in context_keys
    assert 'upcoming_webinars_count' in context_keys
    assert context['upcoming_webinars'].count() == expected_upcoming
    assert context['upcoming_webinars_count'] == 4

    assert 'show_saved' in context_keys
    assert 'saved_webinars' in context_keys
    assert 'saved_webinars_count' in context_keys
    assert context['saved_webinars'].count() == expected_saved
    assert context['saved_webinars_count'] == 5

    assert 'show_cancelled' in context_keys
    assert 'cancelled_webinars' in context_keys
    assert 'cancelled_webinars_count' in context_keys
    assert context['cancelled_webinars'].count() == expected_cancelled
    assert context['cancelled_webinars_count'] == 6
Ejemplo n.º 13
0
def draft_webinar():
    return WebinarFactory(is_published=False)
Ejemplo n.º 14
0
def webinar():
    return WebinarFactory()
Ejemplo n.º 15
0
def cancelled_webinar():
    return WebinarFactory(is_cancelled=True)
Ejemplo n.º 16
0
def delivered_webinar():
    return WebinarFactory(start_time=now() - timedelta(hours=1), duration=timedelta(minutes=30))