예제 #1
0
    def test_user_form(self, live_server, browser, driver_wait_time):
        browser.get(live_server + URI)
        assert URI in browser.current_url
        sleep(driver_wait_time)
        email_input_box = browser.find_elements_by_id('admin_email')[0]
        email_input_box.clear()
        email_input_box.send_keys('*****@*****.**')

        pass1_input_box = browser.find_elements_by_id('admin_pass1')[0]
        pass1_input_box.clear()
        pass1_input_box.send_keys('password')

        pass2_input_box = browser.find_elements_by_id('admin_pass2')[0]
        pass2_input_box.clear()
        pass2_input_box.send_keys('password')

        submit_button = browser.find_elements_by_id('create_admin_button')[0]
        submit_button.click()

        def _test():
            assert User.objects.count() == 1

        assert_with_timeout(_test, 5 * driver_wait_time)

        browser.get(live_server + URI)
        assert URI not in browser.current_url
예제 #2
0
    def test_create_new_keyword(self, live_server, browser_in, keywords,
                                groups, users, driver_wait_time):
        """Test good form submission."""
        assert len(keywords) == models.Keyword.objects.count()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_keyword(b, driver_wait_time)
        b = add_desc(b, driver_wait_time)
        b = add_custom_response(b, driver_wait_time)
        b = add_deac_response(b, driver_wait_time)
        b = add_too_early_response(b, driver_wait_time)
        b = add_activate_time(b, driver_wait_time)
        b = add_deactivate_time(b, driver_wait_time)
        b = add_linked_groups(b, driver_wait_time)
        b = add_owner(b, driver_wait_time)
        b = add_subscriber(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert len(keywords) + 1 == models.Keyword.objects.count()
            assert '/keyword/all/' in b.current_url
            k = models.Keyword.objects.get(keyword='form')
            assert k.is_live
            assert k.subscribed_to_digest.count() == 1
            assert k.owners.count() == 1

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #3
0
    def test_log_in(self, live_server, browser, driver_wait_time, users):
        # login
        browser.get(live_server + URI)
        email_box = browser.find_elements_by_name("login")[0]
        email_box.send_keys(users["staff"].email)
        password_box = browser.find_elements_by_name("password")[0]
        password_box.send_keys("top_secret")
        login_button = browser.find_element_by_id("login_button")
        login_button.click()

        # check we have been redirected
        def _test():
            assert "accounts" not in browser.current_url

        assert_with_timeout(_test, 5 * driver_wait_time)

        # log out again
        browser.get(live_server + "/accounts/logout/")
        logout_confirm = browser.find_element_by_id("logout_button")
        logout_confirm.click()

        def _test():
            assert "accounts/login" in browser.current_url

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #4
0
    def test_user_profile_form(self, live_server, browser_in, users,
                               driver_wait_time):
        """Test an individual user profile form."""
        uri = "/users/profiles/" + str(users["staff"].pk)
        assert users["staff"].profile.can_archive
        # load page
        browser_in.get(live_server + uri)
        assert uri in browser_in.current_url
        sleep(driver_wait_time)
        # toggle
        toggle_button = browser_in.find_element_by_id("id_can_archive")
        assert toggle_button.is_selected()
        toggle_button.click()
        sleep(driver_wait_time)
        assert not toggle_button.is_selected()
        # submit
        save_button = browser_in.find_element_by_id("formSubmitButton")
        save_button.click()

        def _test():
            assert uri not in browser_in.current_url
            u = User.objects.get(pk=users["staff"].pk)
            assert u.profile.can_archive is False

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #5
0
    def test_table_page_and_buttons(self, live_server, browser_in, users, driver_wait_time):
        """Test the table of users."""
        uri = '/users/profiles/'
        # load page
        browser_in.get(live_server + uri)
        assert uri in browser_in.current_url

        # check table is there
        def _test1():
            tables = browser_in.find_elements_by_class_name('table-bordered')
            assert len(tables) == 1
            table = tables[0]
            assert 'Approved' in table.text
            assert 'Incoming' in table.text
            assert '*****@*****.**' in table.text

        assert_with_timeout(_test1, 10 * driver_wait_time)
        # toggle approved button:
        user_staff_approved_button_attr = f'[data-test-id=approved-{users["staff"].profile.pk}]'
        toggle = browser_in.find_element_by_css_selector(user_staff_approved_button_attr)
        assert toggle.text == '✔'
        toggle.click()

        def _test2():
            assert toggle.text == '✖'
            assert not users['staff'].profile.approved

        assert_with_timeout(_test2, 10 * driver_wait_time)
예제 #6
0
    def test_log_in(self, live_server, browser, driver_wait_time, users):
        # login
        browser.get(live_server + URI)
        email_box = browser.find_elements_by_name('login')[0]
        email_box.send_keys(users['staff'].email)
        password_box = browser.find_elements_by_name('password')[0]
        password_box.send_keys('top_secret')
        login_button = browser.find_element_by_id('login_button')
        login_button.click()

        # check we have been redirected
        def _test():
            assert 'accounts' not in browser.current_url

        assert_with_timeout(_test, 5 * driver_wait_time)

        # log out again
        browser.get(live_server + '/accounts/logout/')
        logout_confirm = browser.find_element_by_id('logout_button')
        logout_confirm.click()

        def _test():
            assert 'accounts/login' in browser.current_url

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #7
0
    def test_table_page_and_buttons(self, live_server, browser_in, users,
                                    driver_wait_time):
        """Test the table of users."""
        uri = "/users/profiles/"
        # load page
        browser_in.get(live_server + uri)
        assert uri in browser_in.current_url

        # check table is there
        def _test1():
            tables = browser_in.find_elements_by_css_selector("table")
            assert len(tables) == 1
            table = tables[0]
            assert "Approved" in table.text
            assert "Incoming" in table.text
            assert "*****@*****.**" in table.text

        assert_with_timeout(_test1, 10 * driver_wait_time)
        # toggle approved button:
        user_staff_approved_button_attr = f'[data-test-id=approved-{users["staff"].profile.pk}]'
        toggle = browser_in.find_element_by_css_selector(
            user_staff_approved_button_attr)
        assert toggle.text == "✔"
        toggle.click()

        def _test2():
            assert toggle.text == "✖"
            assert not users["staff"].profile.approved

        assert_with_timeout(_test2, 10 * driver_wait_time)
예제 #8
0
    def test_default_prefix(self, live_server, browser_in, users,
                            driver_wait_time):
        """Test prefix shows on form."""
        from site_config.models import SiteConfiguration

        config = SiteConfiguration.get_solo()
        config.default_number_prefix = "+45"
        config.save()
        b = load_page(browser_in, driver_wait_time, live_server + URI)

        # test is there
        def _test():
            num_input = b.find_element_by_id("id_number")
            assert num_input.get_attribute("value") == "+45"

        assert_with_timeout(_test, 10 * driver_wait_time)

        config.default_number_prefix = ""
        config.save()
        b = load_page(browser_in, driver_wait_time, live_server + URI)

        # test is not there
        def _test():
            num_input = b.find_element_by_id("id_number")
            assert num_input.get_attribute("value") != "+45"
예제 #9
0
    def test_twilio_delete_flow(self, live_server, browser_in, users, smsin,
                                smsout, driver_wait_time):
        """Test good form submission."""
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        n_in = models.SmsInbound.objects.count()
        n_out = models.SmsOutbound.objects.count()
        sleep(driver_wait_time * 3)
        click_and_wait(b.find_element_by_id(f'incoming_sms{smsin["sms1"].pk}'),
                       driver_wait_time)
        click_and_wait(
            b.find_element_by_id(f'outgoing_sms{smsout["smsout"].pk}'),
            driver_wait_time)
        click_and_wait(b.find_element_by_id("deleteButton"), driver_wait_time)
        click_and_wait(b.find_element_by_id("confirmButton"), driver_wait_time)
        b.find_element_by_id("confirmDeleteInput").send_keys(
            "I understand this cannot be undone")
        click_and_wait(b.find_element_by_id("finalConfirmButton"),
                       driver_wait_time)

        def _test():
            assert "Messages successfully queued for deletion." in b.page_source
            assert n_in - 1 == models.SmsInbound.objects.count()
            assert n_out - 1 == models.SmsOutbound.objects.count()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #10
0
    def test_table_page_and_buttons(self, live_server, browser_in, users,
                                    driver_wait_time):
        """Test the table of users."""
        uri = '/users/profiles/'
        # load page
        browser_in.get(live_server + uri)
        assert uri in browser_in.current_url

        # check table is there
        def _test1():
            tables = browser_in.find_elements_by_class_name('table')
            assert len(tables) == 1
            table = tables[0]
            assert 'Approved' in table.text
            assert 'Incoming' in table.text
            assert '*****@*****.**' in table.text

        assert_with_timeout(_test1, 10 * driver_wait_time)
        # toggle all negative permissions
        for toggle in browser_in.find_elements_by_class_name('minus'):
            toggle.click()

        def _test2():
            assert users['staff'].profile.approved

        assert_with_timeout(_test2, 10 * driver_wait_time)
예제 #11
0
def test_csv_import_ok(live_server, browser_in, recipients, users, driver_wait_time):
    assert len(recipients) == models.Recipient.objects.count()
    b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
    b = add_csv_data(b, driver_wait_time, 'csv,import,' + DEFAULT_NUM)
    b = send_form(b, driver_wait_time)

    def _test():
        assert len(recipients) + 1 == models.Recipient.objects.count()
        assert '/recipient/import/' not in b.current_url

    assert_with_timeout(_test, 10 * driver_wait_time)
예제 #12
0
def test_csv_import_bad(live_server, browser_in, recipients, users, driver_wait_time):
    assert len(recipients) == models.Recipient.objects.count()
    b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
    b = add_csv_data(b, driver_wait_time, 'csv,')
    b = send_form(b, driver_wait_time)

    def _test():
        assert len(recipients) == models.Recipient.objects.count()
        assert '/recipient/import/' in b.current_url
        assert 'Uh oh,' in b.page_source

    assert_with_timeout(_test, 10 * driver_wait_time)
예제 #13
0
    def test_scheduled_message(self, live_server, browser_in, users, driver_wait_time, recipients):
        """Test good form submission with a scheduled time."""
        b = load_page(browser_in, driver_wait_time, live_server + ADHOC_URI)
        # add scheduled time
        b = add_scheduled_time(b, driver_wait_time)
        b = add_content_and_recipient(b, driver_wait_time)
        b = click_send(b, driver_wait_time)

        def _test():
            assert '/scheduled/sms/' in b.current_url

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #14
0
    def test_create_existing_keyword(self, live_server, browser_in, keywords,
                                     users, driver_wait_time):
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_keyword(b, driver_wait_time, k='test')
        b = send_form(b, driver_wait_time)

        def _test():
            assert '/keyword/new/' in b.current_url
            assert 'keyword with this keyword already exists' in b.page_source.lower(
            )
            assert len(keywords) == models.Keyword.objects.count()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #15
0
    def test_create_existing_contact(self, live_server, browser_in, recipients, users, driver_wait_time):
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_first_name(b, driver_wait_time)
        b = add_last_name(b, driver_wait_time)
        b = add_number(b, driver_wait_time, num=str(recipients['calvin'].number))
        b = send_form(b, driver_wait_time)

        def _test():
            assert '/recipient/new/' in b.current_url
            assert 'recipient with this number already exists' in b.page_source.lower()
            assert len(recipients) == models.Recipient.objects.count()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #16
0
    def test_create_existing_group(self, live_server, browser_in, users, driver_wait_time):
        self.test_create_new_group(live_server, browser_in, users, driver_wait_time)
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_group_name(b, driver_wait_time)
        b = add_description(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert 1 == models.RecipientGroup.objects.count()
            assert "/group/new/" in b.current_url
            assert "recipient group with this name of group already exists" in b.page_source.lower()
            assert "group members" not in b.page_source.lower()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #17
0
    def test_create_new_group(self, live_server, browser_in, users, driver_wait_time):
        """Test good form submission."""
        assert 0 == models.RecipientGroup.objects.count()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_group_name(b, driver_wait_time)
        b = add_description(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert 1 == models.RecipientGroup.objects.count()
            assert "/group/all/" in b.current_url
            assert "test_new_group" in b.page_source

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #18
0
    def test_create_new_group(self, live_server, browser_in, users, driver_wait_time):
        """Test good form submission."""
        assert 0 == models.RecipientGroup.objects.count()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_group_name(b, driver_wait_time)
        b = add_description(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert 1 == models.RecipientGroup.objects.count()
            assert '/group/all/' in b.current_url
            assert 'test_new_group' in b.page_source

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #19
0
    def test_create_existing_group(self, live_server, browser_in, users, driver_wait_time):
        self.test_create_new_group(live_server, browser_in, users, driver_wait_time)
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_group_name(b, driver_wait_time)
        b = add_description(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert 1 == models.RecipientGroup.objects.count()
            assert '/group/new/' in b.current_url
            assert 'recipient group with this name of group already exists' in b.page_source.lower()
            assert 'group members' not in b.page_source.lower()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #20
0
    def test_create_new_contact(self, live_server, browser_in, recipients, users, driver_wait_time):
        """Test good form submission."""
        assert len(recipients) == models.Recipient.objects.count()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_first_name(b, driver_wait_time)
        b = add_last_name(b, driver_wait_time)
        b = add_number(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert len(recipients) + 1 == models.Recipient.objects.count()
            assert '/recipient/all/' in b.current_url

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #21
0
    def test_edit_group(self, live_server, browser_in, users, driver_wait_time, groups):
        assert len(groups) == models.RecipientGroup.objects.count()
        b = load_page(browser_in, driver_wait_time, live_server + '/group/edit/{}/'.format(groups['test_group'].pk))
        b = add_group_name(b, driver_wait_time)
        b = add_description(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert len(groups) == models.RecipientGroup.objects.count()
            assert '/group/all/' in b.current_url
            assert 'test_new_group' in b.page_source
            assert groups['test_group'].description not in b.page_source
            assert 'group members' not in b.page_source.lower()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #22
0
    def test_create_new_contact(self, live_server, browser_in, recipients,
                                users, driver_wait_time):
        """Test good form submission."""
        assert len(recipients) == models.Recipient.objects.count()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_first_name(b, driver_wait_time)
        b = add_last_name(b, driver_wait_time)
        b = add_number(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert len(recipients) + 1 == models.Recipient.objects.count()
            assert '/recipient/all/' in b.current_url

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #23
0
    def test_edit_form(self, uri, live_server, browser_in):
        browser_in.get(live_server + uri)
        assert uri in browser_in.current_url
        input_box = browser_in.find_elements_by_id('id_start_reply')[0]
        input_box.clear()
        input_box.send_keys('Thank you for signing up :-)')
        input_box.submit()

        from site_config.models import DefaultResponses

        def _test():
            resps = DefaultResponses.get_solo()
            assert 'Thank you for signing up' in resps.start_reply

        assert_with_timeout(_test, 10)
예제 #24
0
    def test_create_existing_archived_group(self, live_server, browser_in, users, driver_wait_time):
        self.test_create_new_group(live_server, browser_in, users, driver_wait_time)
        for g in models.RecipientGroup.objects.all():
            g.is_archived = True
            g.save()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_group_name(b, driver_wait_time)

        def _test():
            assert '/group/new/' in b.current_url
            assert 'There is already a Group that with that name in the archive'.lower() in b.page_source.lower()
            assert 'Or you can restore the group here:'.lower() in b.page_source.lower()
            assert 'group members' not in b.page_source.lower()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #25
0
    def test_create_existing_archived_group(self, live_server, browser_in, users, driver_wait_time):
        self.test_create_new_group(live_server, browser_in, users, driver_wait_time)
        for g in models.RecipientGroup.objects.all():
            g.is_archived = True
            g.save()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_group_name(b, driver_wait_time)

        def _test():
            assert "/group/new/" in b.current_url
            assert "There is already a Group that with that name in the archive".lower() in b.page_source.lower()
            assert "Or you can restore the group here:".lower() in b.page_source.lower()
            assert "group members" not in b.page_source.lower()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #26
0
    def test_edit_group(self, live_server, browser_in, users, driver_wait_time, groups):
        assert len(groups) == models.RecipientGroup.objects.count()
        b = load_page(browser_in, driver_wait_time, live_server + "/group/edit/{}/".format(groups["test_group"].pk))
        b = add_group_name(b, driver_wait_time)
        b = add_description(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert len(groups) == models.RecipientGroup.objects.count()
            assert "/group/all/" in b.current_url
            assert "test_new_group" in b.page_source
            assert groups["test_group"].description not in b.page_source
            assert "group members" not in b.page_source.lower()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #27
0
    def test_edit_keyword(self, live_server, browser_in, keywords, users,
                          driver_wait_time):
        assert len(keywords) == models.Keyword.objects.count()
        b = load_page(browser_in, driver_wait_time,
                      live_server + '/keyword/edit/test/')
        b = add_desc(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert len(keywords) == models.Keyword.objects.count()
            assert '/keyword/all/' in b.current_url
            assert 'form' in b.page_source
            assert models.Keyword.objects.get(keyword='test').keyword == 'test'

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #28
0
    def test_create_existing_archived_contact(self, live_server, browser_in, recipients, users, driver_wait_time):
        self.test_create_new_contact(live_server, browser_in, recipients, users, driver_wait_time)
        for g in models.Recipient.objects.all():
            g.is_archived = True
            g.save()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_first_name(b, driver_wait_time)
        b = add_last_name(b, driver_wait_time)
        b = add_number(b, driver_wait_time)

        def _test():
            assert '/recipient/new/' in b.current_url
            assert 'There is already a Contact that with that number in the archive'.lower() in b.page_source.lower()
            assert 'Or you can restore the contact here:'.lower() in b.page_source.lower()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #29
0
    def test_edit_contact(self, live_server, browser_in, recipients, users, driver_wait_time):
        assert len(recipients) == models.Recipient.objects.count()
        b = load_page(browser_in, driver_wait_time, live_server + '/recipient/edit/{}/'.format(recipients['calvin'].pk))
        b = add_first_name(b, driver_wait_time)
        b = add_last_name(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert len(recipients) == models.Recipient.objects.count()
            assert '/recipient/all/' in b.current_url
            assert 'first' in b.page_source
            assert 'last' in b.page_source
            assert str(models.Recipient.objects.get(pk=recipients['calvin'].pk).number) == str(
                recipients['calvin'].number
            )

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #30
0
    def test_create_existing_archived_keyword(self, live_server, browser_in,
                                              keywords, users,
                                              driver_wait_time):
        for k in models.Keyword.objects.all():
            k.is_archived = True
            k.save()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_keyword(b, driver_wait_time, k='test')

        def _test():
            assert '/keyword/new/' in b.current_url
            assert 'there is already a keyword that with that name in the archive'.lower(
            ) in b.page_source.lower()
            assert 'Or you can restore the keyword here:'.lower(
            ) in b.page_source.lower()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #31
0
    def test_create_existing_contact(self, live_server, browser_in, recipients,
                                     users, driver_wait_time):
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_first_name(b, driver_wait_time)
        b = add_last_name(b, driver_wait_time)
        b = add_number(b,
                       driver_wait_time,
                       num=str(recipients['calvin'].number))
        b = send_form(b, driver_wait_time)

        def _test():
            assert '/recipient/new/' in b.current_url
            assert 'recipient with this number already exists' in b.page_source.lower(
            )
            assert len(recipients) == models.Recipient.objects.count()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #32
0
    def test_edit_contact(self, live_server, browser_in, recipients, users,
                          driver_wait_time):
        assert len(recipients) == models.Recipient.objects.count()
        b = load_page(
            browser_in, driver_wait_time, live_server +
            "/recipient/edit/{}/".format(recipients["calvin"].pk))
        b = add_first_name(b, driver_wait_time)
        b = add_last_name(b, driver_wait_time)
        b = tick_never_contact(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert len(recipients) == models.Recipient.objects.count()
            assert "/recipient/all/" in b.current_url
            assert "first" in b.page_source
            assert "last" in b.page_source
            r = models.Recipient.objects.get(pk=recipients["calvin"].pk)
            assert str(r.number) == str(recipients["calvin"].number)
            assert r.never_contact

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #33
0
    def test_sms_form(self, live_server, browser_in, driver_wait_time, recipients):
        browser_in.get(live_server + URI)
        assert URI in browser_in.current_url
        sleep(driver_wait_time)
        to_input_box = browser_in.find_elements_by_id("sms_to")[0]
        to_input_box.clear()
        to_input_box.send_keys(str(recipients["calvin"].number))

        body_input_box = browser_in.find_elements_by_id("sms_body")[0]
        body_input_box.clear()
        body_input_box.send_keys("test")

        submit_button = browser_in.find_elements_by_id("sms_send_button")[0]
        submit_button.click()

        def _test():
            assert "AC00000000000000000000000000000000" in browser_in.page_source
            assert "Error:" in browser_in.page_source
            assert "Twilio returned the following information:"

        assert_with_timeout(_test, 5 * driver_wait_time)
예제 #34
0
    def test_create_existing_archived_contact(self, live_server, browser_in,
                                              recipients, users,
                                              driver_wait_time):
        self.test_create_new_contact(live_server, browser_in, recipients,
                                     users, driver_wait_time)
        for g in models.Recipient.objects.all():
            g.is_archived = True
            g.save()
        b = load_page(browser_in, driver_wait_time, live_server + NEW_URI)
        b = add_first_name(b, driver_wait_time)
        b = add_last_name(b, driver_wait_time)
        b = add_number(b, driver_wait_time)

        def _test():
            assert '/recipient/new/' in b.current_url
            assert 'There is already a Contact that with that number in the archive'.lower(
            ) in b.page_source.lower()
            assert 'Or you can restore the contact here:'.lower(
            ) in b.page_source.lower()

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #35
0
    def test_edit_contact(self, live_server, browser_in, recipients, users,
                          driver_wait_time):
        assert len(recipients) == models.Recipient.objects.count()
        b = load_page(
            browser_in, driver_wait_time, live_server +
            '/recipient/edit/{}/'.format(recipients['calvin'].pk))
        b = add_first_name(b, driver_wait_time)
        b = add_last_name(b, driver_wait_time)
        b = send_form(b, driver_wait_time)

        def _test():
            assert len(recipients) == models.Recipient.objects.count()
            assert '/recipient/all/' in b.current_url
            assert 'first' in b.page_source
            assert 'last' in b.page_source
            assert str(
                models.Recipient.objects.get(
                    pk=recipients['calvin'].pk).number) == str(
                        recipients['calvin'].number)

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #36
0
    def test_sms_form(self, live_server, browser_in, driver_wait_time, recipients):
        browser_in.get(live_server + URI)
        assert URI in browser_in.current_url
        sleep(driver_wait_time)
        to_input_box = browser_in.find_elements_by_id('sms_to')[0]
        to_input_box.clear()
        to_input_box.send_keys(str(recipients['calvin'].number))

        body_input_box = browser_in.find_elements_by_id('sms_body')[0]
        body_input_box.clear()
        body_input_box.send_keys('test')

        submit_button = browser_in.find_elements_by_id('sms_send_button')[0]
        submit_button.click()

        def _test():
            assert 'AC00000000000000000000000000000000' in browser_in.page_source
            assert 'Error:' in browser_in.page_source
            assert 'Twilio returned the following information:'

        assert_with_timeout(_test, 5 * driver_wait_time)
예제 #37
0
    def test_email_form(self, live_server, browser_in, driver_wait_time):
        browser_in.get(live_server + URI)
        assert URI in browser_in.current_url
        sleep(driver_wait_time)
        email_input_box = browser_in.find_elements_by_id('email_to')[0]
        email_input_box.clear()
        for k in '*****@*****.**':
            email_input_box.send_keys(k)

        body_input_box = browser_in.find_elements_by_id('email_body')[0]
        body_input_box.clear()
        for k in 'test message':
            body_input_box.send_keys(k)

        submit_button = browser_in.find_elements_by_id('email_send_button')[0]
        submit_button.click()

        def _test():
            assert len(mail.outbox) == 1
            assert 'test message' in mail.outbox[0].body

        assert_with_timeout(_test, 5 * driver_wait_time)
예제 #38
0
    def test_email_form(self, live_server, browser_in, driver_wait_time):
        browser_in.get(live_server + URI)
        assert URI in browser_in.current_url
        sleep(driver_wait_time)
        email_input_box = browser_in.find_elements_by_id('email_to')[0]
        email_input_box.clear()
        for k in '*****@*****.**':
            email_input_box.send_keys(k)

        body_input_box = browser_in.find_elements_by_id('email_body')[0]
        body_input_box.clear()
        for k in 'test message':
            body_input_box.send_keys(k)

        submit_button = browser_in.find_elements_by_id('email_send_button')[0]
        submit_button.click()

        def _test():
            assert len(mail.outbox) == 1
            assert 'test message' in mail.outbox[0].body

        assert_with_timeout(_test, 5 * driver_wait_time)
예제 #39
0
    def test_user_profile_form(self, live_server, browser_in, users,
                               driver_wait_time):
        """Test an individual user profile form."""
        uri = users['staff'].profile.get_absolute_url()
        assert users['staff'].profile.can_archive
        # load page
        browser_in.get(live_server + uri)
        assert uri in browser_in.current_url
        sleep(driver_wait_time)
        # toggle
        toggle_button = browser_in.find_elements_by_class_name('checkbox')[-1]
        toggle_button.click()
        # submit
        save_button = browser_in.find_elements_by_class_name('primary')[0]
        save_button.click()

        def _test():
            assert uri not in browser_in.current_url
            u = User.objects.get(pk=users['staff'].pk)
            assert u.profile.can_archive is False

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #40
0
    def test_sign_up(self, live_server, browser, driver_wait_time, users):
        """
        Tests the sign up form and checks that the appropriate emails
        have been sent afterwards.
        """
        # add an office email to test correct email is sent on sign up
        config = SiteConfiguration.get_solo()
        config.office_email = '*****@*****.**'
        config.save()
        # signup
        uri = '/accounts/signup/'
        browser.get(live_server + uri)
        email_box = browser.find_elements_by_name('email')[0]
        email_box.send_keys('*****@*****.**')
        password_box1 = browser.find_elements_by_name('password1')[0]
        password_box1.send_keys('top_secret')
        password_box2 = browser.find_elements_by_name('password2')[0]
        password_box2.send_keys('top_secret')
        login_button = browser.find_element_by_id('signupButton')
        login_button.click()

        def _test():
            assert '/accounts/confirm-email/' in browser.current_url
            assert len(mail.outbox) == 2
            assert '[apostello] New User' in mail.outbox[0].subject

        assert_with_timeout(_test, 10 * driver_wait_time)
        # when we have no office email set
        assert 'Please Confirm Your E-mail Address' in mail.outbox[1].subject
        for x in mail.outbox[1].body.split():
            if x.startswith('http'):
                confirm_url = x
        browser.get(confirm_url)
        confirm_button = browser.find_element_by_id('confirmButton')
        confirm_button.click()
        user = User.objects.get(email='*****@*****.**')
        assert not user.is_staff
        assert not user.is_superuser
예제 #41
0
    def test_user_profile_form(self, live_server, browser_in, users, driver_wait_time):
        """Test an individual user profile form."""
        uri = '/users/profiles/' + str(users['staff'].pk)
        assert users['staff'].profile.can_archive
        # load page
        browser_in.get(live_server + uri)
        assert uri in browser_in.current_url
        sleep(driver_wait_time)
        # toggle
        toggle_button = browser_in.find_element_by_id('id_can_archive')
        assert toggle_button.is_selected()
        toggle_button.click()
        sleep(driver_wait_time)
        assert not toggle_button.is_selected()
        # submit
        save_button = browser_in.find_element_by_id('formSubmitButton')
        save_button.click()

        def _test():
            assert uri not in browser_in.current_url
            u = User.objects.get(pk=users['staff'].pk)
            assert u.profile.can_archive is False

        assert_with_timeout(_test, 10 * driver_wait_time)
예제 #42
0
    def test_api_setup(self, live_server, browser_in, users, driver_wait_time):
        """Test api-setup form."""
        no_api_token_txt = "No API Token"
        b = browser_in
        browser_in.get(live_server + URI)
        # show key
        show_button = b.find_element_by_id("showKeyButton")
        click_and_wait(show_button, driver_wait_time)

        # delete token that doesn't exist
        def _test():
            b.find_element_by_id("delKeyButton").click()
            assert no_api_token_txt in b.page_source

        assert_with_timeout(_test, driver_wait_time)

        # generate token for first time
        def _test():
            b.find_element_by_id("genKeyButton").click()
            assert no_api_token_txt not in b.page_source

        assert_with_timeout(_test, driver_wait_time)

        # regenerate token
        def _test():
            b.find_element_by_id("genKeyButton").click()
            assert no_api_token_txt not in b.page_source

        assert_with_timeout(_test, driver_wait_time)

        # delete token
        def _test():
            b.find_element_by_id("delKeyButton").click()
            assert no_api_token_txt in b.page_source

        assert_with_timeout(_test, driver_wait_time)
예제 #43
0
    def test_api_setup(self, live_server, browser_in, users, driver_wait_time):
        """Test api-setup form."""
        no_api_token_txt = 'No API Token'
        b = browser_in
        browser_in.get(live_server + URI)
        # show key
        show_button = b.find_element_by_id('showKeyButton')
        click_and_wait(show_button, driver_wait_time)

        # delete token that doesn't exist
        def _test():
            b.find_element_by_id('delKeyButton').click()
            assert no_api_token_txt in b.page_source

        assert_with_timeout(_test, driver_wait_time)

        # generate token for first time
        def _test():
            b.find_element_by_id('genKeyButton').click()
            assert no_api_token_txt not in b.page_source

        assert_with_timeout(_test, driver_wait_time)

        # regenerate token
        def _test():
            b.find_element_by_id('genKeyButton').click()
            assert no_api_token_txt not in b.page_source

        assert_with_timeout(_test, driver_wait_time)

        # delete token
        def _test():
            b.find_element_by_id('delKeyButton').click()
            assert no_api_token_txt in b.page_source

        assert_with_timeout(_test, driver_wait_time)