Ejemplo n.º 1
0
def i_access_the_management_console(step):
    if world.using_selenium:
        world.browser.get(django.django_url("/manage/"))
    else:
        response = world.client.get(django.django_url("/manage/"),follow=True)
        world.response = response
        world.dom = html.fromstring(response.content)
Ejemplo n.º 2
0
def i_log_out(step):
    if world.using_selenium:
        world.firefox.get(django_url("/accounts/logout/"))
    else:
        response = world.client.get(django_url("/accounts/logout/"),follow=True)
        world.response = response
        world.dom = html.fromstring(response.content)
Ejemplo n.º 3
0
def i_access_the_counselor_landing_page(step):
    if world.using_selenium:
        world.browser.get(django.django_url("/intervention/"))
    else:
        response = world.client.get(django.django_url("/intervention/"),follow=True)
        world.response = response
        world.dom = html.fromstring(response.content)
Ejemplo n.º 4
0
def i_am_username_in_course(step, username, coursename):
    if world.using_selenium:
        world.browser.get(django.django_url("/accounts/logout/?next=/"))
        world.browser.get(django.django_url("accounts/login/?next=/"))

        wait = ui.WebDriverWait(world.browser, 5)
        wait.until(visibility_of_element_located((By.ID, 'guest-login')))

        elt = world.browser.find_element_by_id('guest-login')
        elt.click()

        username_field = world.browser.find_element_by_id("id_username")
        username_field.send_keys(username)

        password_field = world.browser.find_element_by_id("id_password")
        password_field.send_keys("test")

        form = world.browser.find_element_by_name("login_local")
        form.submit()

        wait = ui.WebDriverWait(world.browser, 5)
        wait.until(lambda driver: world.browser.title.find("Home") > -1)

        wait.until(lambda driver: world.browser.find_element_by_id("loaded"))

        course_title = world.browser.find_element_by_id("course_title_link")
        msg = ("Expected the %s class, but found the %s class" %
               (coursename, course_title.text))
        assert course_title.text.find(coursename) > -1, msg

        assert username in world.browser.page_source, world.browser.page_source
    else:
        world.client.login(username=username, password='******')
Ejemplo n.º 5
0
def i_go_to_the_add_participant_page(step):
    if world.using_selenium:
        world.firefox.get(django_url("/manage/add_participant/"))
    response = world.client.get(
        django_url("/manage/add_participant/"), follow=True)
    world.response = response
    world.dom = html.fromstring(response.content)
Ejemplo n.º 6
0
def access_url(step, url):
    if world.skipping:
        return
    if world.using_selenium:
        world.browser.get(django_url(url))
    else:
        response = world.client.get(django_url(url), follow=True)
        world.dom = html.fromstring(response.content)
Ejemplo n.º 7
0
def video_upload_is_enabled(step):
    if world.using_selenium:
        world.browser.get(django_url("/dashboard/sources/"))
        try:
            elt = world.browser.find_element_by_id("mediathread-video-upload")
            if elt:
                elt.click()
                world.browser.get(django_url("/"))
        except NoSuchElementException:
            pass  # It's already enabled. That's ok.
Ejemplo n.º 8
0
def i_am_username_in_course(step, username, coursename):
    if world.using_selenium:
        world.browser.get(django.django_url("/accounts/logout/?next=/"))
        world.browser.get(django.django_url("accounts/login/?next=/"))

        wait = ui.WebDriverWait(world.browser, 5)
        wait.until(visibility_of_element_located((By.ID, 'guest-login')))

        elt = world.browser.find_element_by_id('guest-login')
        elt.click()

        username_field = world.browser.find_element_by_id("id_username")
        username_field.send_keys(username)

        password_field = world.browser.find_element_by_id("id_password")
        password_field.send_keys("test")

        form = world.browser.find_element_by_name("login_local")
        form.submit()

        if re.match(r'^instructor', username):
            try:
                course = world.browser.find_element_by_css_selector(
                    'a.choose-course')
            except NoSuchElementException:
                wait.until(
                    visibility_of_element_located((By.ID, 'sandboxes_link')))
                sandboxes_link = world.browser.find_element_by_id(
                    'sandboxes_link')
                sandboxes_link.click()

                wait = ui.WebDriverWait(world.browser, 5)
                wait.until(
                    visibility_of_element_located(
                        (By.CSS_SELECTOR, 'a.choose-course')))
                course = world.browser.find_element_by_css_selector(
                    'a.choose-course')
            course.click()

        wait = ui.WebDriverWait(world.browser, 5)
        wait.until(lambda driver: world.browser.title.find("Home") > -1)

        wait.until(lambda driver: world.browser.find_element_by_id("loaded"))

        course_title = world.browser.find_element_by_id("course_title_link")
        msg = ("Expected the %s class, but found the %s class" %
               (coursename, course_title.text))
        assert course_title.text.find(coursename) > -1, msg

        assert username in world.browser.page_source, world.browser.page_source
    else:
        world.client.login(username=username, password='******')
Ejemplo n.º 9
0
def i_go_to_session(step,activity_number,session_number):
    i = Intervention.objects.all()[0]
    s = i.clientsession_set.all()[int(session_number) - 1]
    assert s.index() == int(session_number)
    a = s.activity_set.all()[int(activity_number) - 1]
    assert a.index() == int(activity_number)

    if world.using_selenium:
        world.firefox.get(django_url("/activity/%d/" % a.id))
    else:
        response = world.client.get(django_url("/activity/%d/" % a.id))
        world.dom = html.fromstring(response.content)
        world.response = response
Ejemplo n.º 10
0
def insert_image_in_question(step):
    if world.skipping:
        return
    link = world.browser.find_element_by_link_text("Quiz")
    link.click()
    link_manage=world.browser.find_element_by_link_text("manage questions/answers")
    link_manage.click()
    world.browser.get(django_url('_quiz/edit_answer/310/'))
    label = world.browser.find_element_by_id('id_label')
    label.send_keys('<img id="selenium-img" src="'+django_url("/site_media/img/banner.jpg") + '"/>' )
    form = world.browser.find_element_by_css_selector('form')
    form.submit()
    world.browser.get(django_url('/module-1/three/evaluation/'))    
    assert(world.browser.find_element_by_id('selenium-img'))
Ejemplo n.º 11
0
def given_i_am_logged_in_as_an_admin(step):
    if world.using_selenium:
        world.browser.get(django.django_url("/accounts/logout/"))
        world.browser.get(django.django_url("/accounts/login/?next=/intervention/"))
        username_field = world.browser.find_element_by_id("id_username")
        password_field = world.browser.find_element_by_id("id_password")
        form = world.browser.find_element_by_id("login-form")
        username_field.send_keys("testadmin")
        password_field.send_keys("test")
        form.submit()
        assert world.browser.current_url.endswith("/intervention/"), world.browser.current_url
        assert "testadmin" in world.browser.page_source, world.browser.page_source
    else:
        world.client.login(username='******',password='******')
def setup_env():
    setup_test_environment()
    
    truncate(User)
    User.objects.create_user('testuser', email='*****@*****.**', password='******')

    world.language_code = 'en'
    world.project_slug = 'a-sample-project'

    world.browser = Client()
    world.edit_theme_url = django_url(reverse('project_sheet-instance-edit-related', 
                                              args=(world.project_slug,)))
    world.edit_status_url = django_url(reverse('project_sheet-instance-edit-status', 
                                               args=(world.project_slug,)))
Ejemplo n.º 13
0
def given_publish_to_world_is_value(step, value):
    if world.using_selenium:
        world.browser.get(django.django_url("/dashboard/settings/"))

        elt = world.browser.find_element_by_id("id_publish_to_world")
        if value == 'enabled' and elt.get_attribute('checked') is None:
                elt.click()
        elif value != 'enabled' and elt.get_attribute('checked') == 'true':
                elt.click()

        elt = world.browser.find_element_by_css_selector(
            'button[type="submit"]')
        if elt:
            elt.click()
            world.browser.get(django.django_url("/"))
Ejemplo n.º 14
0
def given_the_selection_visibility_is_value(step, value):
    if world.using_selenium:
        world.browser.get(django.django_url("/dashboard/settings/"))

        if value == "Yes":
            elt = world.browser.find_element_by_id("selection_visibility_yes")
            elt.click()
        else:
            elt = world.browser.find_element_by_id("selection_visibility_no")
            elt.click()

        elt = world.browser.find_element_by_id("selection_visibility_submit")
        if elt:
            elt.click()
            world.browser.get(django.django_url("/"))
Ejemplo n.º 15
0
def login_as(username):
    try:
        user = User.objects.get(username=username)
    except User.DoesNotExist:
        user = User.objects.create_user(username, username + "@test.com", "pass")

    # HACHHACKHACK - Steal the session cookie from the django client to log in
    from django.test.client import Client

    cl = Client()
    cl.login(username=username, password="******")

    world.browser.get(django_url("/"))  # this seems to be required
    world.browser.add_cookie({"name": "sessionid", "value": cl.cookies["sessionid"].value, "path": "/"})
    world.browser.get(django_url("/"))
Ejemplo n.º 16
0
def given_the_item_visibility_is_value(step, value):
    if world.using_selenium:
        world.browser.get(django.django_url("/dashboard/settings/"))

        elt = world.browser.find_element_by_id("id_see_eachothers_items")
        if value == 'Yes' and elt.get_attribute('checked') is None:
            elt.click()
        elif value != 'Yes' and elt.get_attribute('checked') == 'true':
                elt.click()

        elt = world.browser.find_element_by_css_selector(
            'button[type="submit"]')
        if elt:
            elt.click()
            world.browser.get(django.django_url("/"))
Ejemplo n.º 17
0
def navigate_to_an_openended_question_as_staff(step):
    world.register_by_course_id('MITx/3.091x/2012_Fall', True)
    world.log_in(email='*****@*****.**', password='******')
    problem = '/courses/MITx/3.091x/2012_Fall/courseware/Week_10/Polymer_Synthesis/'
    world.browser.visit(django_url(problem))
    tab_css = 'ol#sequence-list > li > a[data-element="5"]'
    world.css_click(tab_css)
Ejemplo n.º 18
0
def given_i_fetch_the_urls(step):
    urls = map(lambda i: django_url(i['url']), step.hashes)
    for url in urls:
        http = world.get_url(url)
        world.statuses.append((url, http.code))
        world.content_types.append((url, http.headers['content-type']))
        http.close()
Ejemplo n.º 19
0
 def selenium(self, url):
     # selenium can't/won't set additional http headers
     # so to do the equivalent here, we would have to
     # run a proxy server. yuck.
     # for now, just keep in mind that
     # selenium won't be accessing the site the same way
     world.browser.get(django_url(url))
Ejemplo n.º 20
0
def register():
    url = 'courses/{org}/{number}/{name}/about'.format(
        org='edx', number='999', name='Certificates')
    world.browser.visit(django_url(url))

    world.css_click('section.intro a.register')
    assert world.is_css_present('section.wrapper h3.title')
Ejemplo n.º 21
0
def given_i_access_the_group1_page(step, group1):
    """ access a page by pagename expect 200"""
    pageurl = reverse(group1)
    world.full_url = django_url(pageurl)
    world.response = world.browser.get(pageurl, follow=True)
    world.dom = html.fromstring(world.response.content)
    assert_true(world.response.status_code == 200)
def open_story_in_builder_hash_id_step(step, title, wkflw_step):
    story = Story.objects.get(storytranslation__title=title)
    path = reverse('story_builder',
            kwargs={'story_id': story.story_id,
                    'step': wkflw_step,})
    path = path.replace(story.story_id, "#%s" % (story.story_id))
    world.browser.visit(django_url(path))
Ejemplo n.º 23
0
def i_register_to_audit_the_course(_step):
    url = django_url('courses/%s/about' % world.scenario_dict['COURSE'].id.to_deprecated_string())
    world.browser.visit(url)
    world.css_click('section.intro a.register')
    audit_button = world.browser.find_by_name("audit_mode")
    audit_button.click()
    assert world.is_css_present('section.container.dashboard')
Ejemplo n.º 24
0
def given_i_fetch_the_urls(step):
    urls = [django_url(i['url']) for i in step.hashes]
    for url in urls:
        http = world.get_url(url)
        world.statuses.append((url, http.code))
        world.content_types.append((url, http.headers.dict['content-type']))
        http.close()
Ejemplo n.º 25
0
def i_go_to_session(step,session_number):
    i = Intervention.objects.all()[0]
    s = i.clientsession_set.all()[int(session_number) - 1]
    assert s.index() == int(session_number)
    response = world.client.get(django_url("/session/%d/" % s.id))
    world.dom = html.fromstring(response.content)
    world.response = response
Ejemplo n.º 26
0
def the_participant_has_completed_activity_in_session_1(step,num_activities,session_number):
    world.participant.participantsession_set.all().delete()
    world.participant.participantactivity_set.all().delete()
    i = Intervention.objects.all()[0]
    s = i.clientsession_set.all()[int(session_number) - 1]
    for a in s.activity_set.all()[:int(num_activities)]:
        r = world.client.post(django_url("/activity/%d/complete/" % a.id),{})
Ejemplo n.º 27
0
def i_click_the_link(step, text):
    if not world.using_selenium:
        for a in world.dom.cssselect("a"):
            if a.text:
                if text.strip().lower() in a.text.strip().lower():
                    href = a.attrib['href']
                    response = world.client.get(django_url(href))
                    world.dom = html.fromstring(response.content)
                    return
        assert False, "could not find the '%s' link" % text
    else:
        link = None
        try:
            link = world.firefox.find_element_by_partial_link_text(text)
            assert link.is_displayed()
            link.click()
        except:
            try:
                time.sleep(1)
                link = world.firefox.find_element_by_partial_link_text(text)
                assert link.is_displayed()
                link.click()
            except:
                world.firefox.get_screenshot_as_file("/tmp/selenium.png")
                assert False, link.location
Ejemplo n.º 28
0
def add_correct_lti_to_course(_step):
    category = 'lti'
    world.scenario_dict['LTI'] = world.ItemFactory.create(
        # parent_location=section_location(course),
        parent_location=world.scenario_dict['SEQUENTIAL'].location,
        category=category,
        display_name='LTI',
        metadata={
            'lti_id': 'correct_lti_id',
            'launch_url': world.lti_server.oauth_settings['lti_base'] + world.lti_server.oauth_settings['lti_endpoint']
        }
    )
    course = world.scenario_dict["COURSE"]
    chapter_name = world.scenario_dict['SECTION'].display_name.replace(
        " ", "_")
    section_name = chapter_name
    path = "/courses/{org}/{num}/{name}/courseware/{chapter}/{section}".format(
        org=course.org,
        num=course.number,
        name=course.display_name.replace(' ', '_'),
        chapter=chapter_name,
        section=section_name)
    url = django_url(path)

    world.browser.visit(url)
Ejemplo n.º 29
0
def but_i_see_the_post_in_the_post_manager(step):
    world.browser.get(django_url("/posts/manage"))
    for el in csss("a"):
        if el.text.strip() == "My Title Draft":
            break
    else:
        assert False, "Draft not found in post manager"
Ejemplo n.º 30
0
def assign_org_to_user(step, username, name):
    """ Assign user to organization via the User admin """
    organization = Organization.objects.get(organizationtranslation__name=name)
    world.browser.visit(django_url('/admin/auth/user/'))
    world.browser.click_link_by_text(username)
    world.browser.select('organizations', organization.pk)
    world.browser.find_by_name('_save').first.click()
def navigate_to_url(step, url):
    full_url = django_url(url)
    world.response = world.browser.get(full_url, follow=True)
    assert (world.response.status_code == 200)
Ejemplo n.º 32
0
def i_visit_the_course_info_url(step):
    url = django_url('/courses/MITx/6.002x/2012_Fall/courseware')
    world.browser.visit(url)
Ejemplo n.º 33
0
 def validate_page_url(self):
     assert self.browser.url == django_url(self.url)
Ejemplo n.º 34
0
def unassign_user_from_group(step, username, group_name):
    world.browser.visit(django_url('/admin'))
    world.browser.click_link_by_text("Users")
    world.browser.click_link_by_text(username)
    world.browser.select('groups', '1')
    world.browser.find_by_name('_save').first.click()
Ejemplo n.º 35
0
def i_am_signed_in_as_unmanaged_blogger(step):
    access_url(step, "/accounts/login/?next=/")
    i_login_as(step, "testunmanaged", "testunmanaged")
    assert world.browser.current_url == django_url("/"), "Login failed."
Ejemplo n.º 36
0
def visit_url(step, url):
    world.browser.visit(django_url(url))
Ejemplo n.º 37
0
def visit_detail_page(step):
    world.browser.visit(
        django_url('/organizations/%s' % world.organization.organization_id))
Ejemplo n.º 38
0
def i_am_logged_in(step):
    world.create_user('robot', 'test')
    world.log_in(username='******', password='******')
    world.browser.visit(django_url('/'))
    # You should not see the login link
    assert world.is_css_not_present('a#login')
Ejemplo n.º 39
0
 def validate_back_link(self):
     self.browser.find_link_by_href(django_url(InvestigatorsListPage.url))
Ejemplo n.º 40
0
def access_url(step, url):
    if world.using_selenium:
        world.firefox.get(django_url(url))
    else:
        response = world.client.get(django_url(url))
        world.dom = html.fromstring(response.content)
Ejemplo n.º 41
0
def url_equals(url):
    return world.browser.url == django_url(url)
Ejemplo n.º 42
0
def visit(url):
    world.browser.visit(django_url(url))
Ejemplo n.º 43
0
def visit_story_detail(step, title):
    story = Story.objects.get(storytranslation__title=title)
    path = reverse('story_detail', kwargs={'slug': story.slug})
    world.browser.visit(django_url(path))
Ejemplo n.º 44
0
def i_register_for_the_course(_step, course):
    url = django_url('courses/%s/about' % world.scenario_dict['COURSE'].id.to_deprecated_string())
    world.browser.visit(url)
    world.css_click('.intro a.register')
    assert world.is_css_present('.dashboard')
Ejemplo n.º 45
0
def i_go_to(step, url):
    url = django_url(url)
    world.driver.get(url)
    world.dom = html.fromstring(world.driver.page_source)
Ejemplo n.º 46
0
def i_go_to_member_page(step, member_name):
    member_obj = Member.objects.get(name=member_name)
    world.browser.visit(django_url('/membro/%i' % member_obj.id))
Ejemplo n.º 47
0
def not_member(step, username, name):
    world.browser.visit(
        django_url('/organizations/%s' % world.organization.organization_id))
    world.assert_text_not_in_list('ul.members li', username)
Ejemplo n.º 48
0
def should_have_link_with_path_and_text(step, path, text):
    link = world.browser.find_link_by_text(text)
    assert len(link) > 0
    assert_equals(link.first["href"], django_url(path))
Ejemplo n.º 49
0
def access_url(step, url):
    world.browser.get(django_url(url))
Ejemplo n.º 50
0
def i_am_logged_in(step):
    world.create_user('robot', 'test')
    world.log_in('robot', 'test')
    world.browser.visit(django_url('/'))
    # You should not see the login link
    assert_equals(world.browser.find_by_css('a#login'), [])
Ejemplo n.º 51
0
def i_am_redirected_to_login(step):
    # URL is correct....
    time.sleep(1)
    assert world.browser.current_url.split("?")[0] == django_url("/accounts/login/"), "Expected %s, got %s" % (django_url("/accounts/login/"), world.browser.current_url.split("?")[0])
    # ... and login form exists (e.g. page rendered properly)
    world.browser.find_element_by_class_name('login-form')
Ejemplo n.º 52
0
def when_i_mistype_a_quiz(step):
    Quiz.objects.create(key='abcde')
    world.browser.visit(django_url('/q/abcdE'))
Ejemplo n.º 53
0
def given_i_navigate_to_group1(step, url):
    url = django_url(url)
    assert_equals(url, 'http://127.0.0.1:8000/')

    raw = urllib.request.urlopen(url).read()
    world.dom = html.fromstring(raw)
Ejemplo n.º 54
0
def when_i_am_answering_random_questions(step):
    world.browser.visit(django_url(''))
Ejemplo n.º 55
0
def visit_admin_edit_page(step, name):
    world.browser.visit(django_url('/admin/storybase_user/organization/'))
    world.browser.click_link_by_text(name)
Ejemplo n.º 56
0
 def go_to_the_url(step, url):
     world.response = world.browser.visit(django_url(url))
Ejemplo n.º 57
0
def visit(url):
    world.browser.visit(django_url(url))
    wait_for_js_to_load()
Ejemplo n.º 58
0
def has_website_url_in_admin(step, name, website_url):
    # Visit the Organization's admin panel
    world.browser.visit(django_url('/admin/storybase_user/organization/'))
    world.browser.click_link_by_text(name)
    org_website_url = world.browser.find_by_css('#id_website_url').first.value
    assert_equal(org_website_url, website_url)
Ejemplo n.º 59
0
def i_am_not_logged_in(step):
    if world.using_selenium:
        world.firefox.get(django_url("/accounts/logout/"))
    else:
        world.client.logout()
Ejemplo n.º 60
0
 def validate_edit_investigator_url(self):
     assert self.browser.url == django_url(self.url)