def catalog_find(searchterm, urlfrag, notfind=False): """Just like Twill find, but issues a searchpage-search search""" global_dict, local_dict = namespaces.get_twill_glocals() # This will navigate us away from the place the Twill script is # sitting. Thus, stash away to the current URL, then navigate # back to that URL after searching. br = get_browser() start_url = br.get_url() esc_searchterm = urllib.quote(searchterm) url = "/searchresults.html?body=" + esc_searchterm commands.go(url) # Now do the test. With the fragment of the URL that was # provided, we can do a double-check, to make sure the # searchresults provide that. if notfind: commands.notfind(urlfrag) else: commands.find(urlfrag) # Finally, send them back to the original URL. commands.go(start_url)
def make_intranets(intranets_name): """ Make the offices root hierarchy, deleting if it exists""" global_dict, local_dict = namespaces.get_twill_glocals() global_dict['intranets_name'] = intranets_name # Check to see if we have that community, if so, delete it. commands.go('/' + intranets_name) br = get_browser() status = br.get_code() if status != 404: # The community shouldn't exist, and so we should get 404 # looking for it. If no 404, then it exists and we should # delete it. url = "/%s/delete.html?confirm=1" % intranets_name commands.go(url) # Now, make the community and make sure it exists commands.go("/add_community.html") commands.fv("save", "title", intranets_name) desc = "Test intranets root created for Twill test case named '%s'" commands.fv("save", "description", desc % test_name) commands.submit() commands.find("Add Existing")
def login(username): """Find user for given username and make the browser logged in""" global_dict, local_dict = namespaces.get_twill_glocals() # Set a globabl Twill variable to let Twill scripts now the name # of the test, e.g. the directory, as well as community name. #global_dict['test_name'] = test_name #global_dict['community_name'] = test_name + "-testcase" global_dict['cwd'] = os.getcwd() hn = global_dict['localhost_url'] # First logout logout() # Do a login au = global_dict['%s_user' % username] # Echo to screen dump("Logging into %s as %s" % (hn, au)) # Continue ap = global_dict['%s_password' % username] commands.go(hn + '/login.html') commands.fv("formLogin", "login", au) commands.fv("formLogin", "password", ap) commands.submit() # Make sure the login succeeded commands.show() commands.find("My Profile")
def test_restore_domain_not_found(self): tc.fv(2, 'restore_prev_state', True) self.blocking_mock.restorePreAdministrativeBlockStatesId.side_effect = Registry.Administrative.DOMAIN_ID_NOT_FOUND( what=[1]) tc.submit() tc.url(self.START_URL) tc.find(r'Domain\(s\) with id 1 not found\.')
def test_confirm_password_reset(self): """ create confirmation link as Django engine and test it for resetting password """ test_email = '*****@*****.**' go(SITE) code(200) follow('reset password') code(200) fv(2, 'email', test_email) submit() code(200) #create links from django.contrib.auth.tokens import default_token_generator from django.utils.http import int_to_base36 users = User.objects.filter(email__iexact=test_email) for user in users: link = "%s/accounts/password/reset_confirm/%s/%s/" % (SITE, int_to_base36(user.id), default_token_generator.make_token(user)) go(link) code(200) find('Password reset confirm') fv(2, 'new_password1', 'test') fv(2, 'new_password2', 'test') submit() code(200) find('Your password was successfully reseted') self.general_login_action(user.username, 'test', "Welcome, %s" % user.username)
def student_login(login, password): """ login student by username and password """ cmd.go('/py/student/login/') cmd.fv(1, 'login', login) cmd.fv(1, 'passwd', password) cmd.submit() cmd.find('Attempts/Cards')
def test_unblock_holder_not_exists(self): tc.fv(2, 'new_holder', 'KONTAKT') self.blocking_mock.unblockDomainsId.side_effect = Registry.Administrative.NEW_OWNER_DOES_NOT_EXISTS( what='KONTAKT') tc.submit() tc.url(self.START_URL) tc.find(r'New holder KONTAKT does not exists.')
def test_unblock_domain_not_found(self): tc.fv(2, 'new_holder', 'KONTAKT') self.blocking_mock.unblockDomainsId.side_effect = Registry.Administrative.DOMAIN_ID_NOT_FOUND( what=[1]) tc.submit() tc.url(self.START_URL) tc.find(r'Domain\(s\) with id 1 not found\.')
def test_success(self): tc.submit() tc.code(200) tc.find('successful') self.blocking_mock.blacklistAndDeleteDomainsId.assert_called_once_with( [1], None, self.REASON_TEXT, 0)
def logout(self): "Performs a logout" tc.go(testlib.PROJECT_LIST_URL) tc.code(200) tc.go("/logout/") tc.code(200) tc.find("You are not logged in")
def test_registration_user_exists(self): """ failed registration with existing username """ self.general_reg_action('user1', '*****@*****.**', 'password3', 'password3') find('This username is already taken. Please choose another.')
def test_file_missing_columns(self): tc.formfile( 2, 'domains_emails', os.path.join(os.path.dirname(__file__), 'data/domain_2016-09-16_missing_column_id.csv')) tc.submit() tc.find('Missing column "Id" on the row 2.')
def test_change_password(): """ Test user password change """ go(SITE + '/accounts/login/') code(200) show() formvalue(1, 'username', 'test') formvalue(1, 'password', '1') submit() code(200) go(SITE + '/accounts/password/change/') code(200) show() formvalue(1, 'old_password', '1') formvalue(1, 'new_password1', '2') formvalue(1, 'new_password2', '2') submit() code(200) find('Password change successful') go(SITE + '/accounts/login/') code(200) show() formvalue(1, 'username', 'test') formvalue(1, 'password', '2') submit() code(200) return
def test_login_auth(self): """ test login page """ self.general_login_action('user1', 'password1', 'Welcome, user1') go("%s/accounts/login/" % SITE) code(200) url('/accounts/profile/') find('Welcome, user1')
def send(self, msg, *send_to): """ @todo: make use of native vodafone multi-recipients functionality """ for contact in send_to: web.follow(self.SERVICE_URL) try: web.find("/myv/messaging/webtext/Challenge.shtml") except twill.errors.TwillAssertionError, e: pass else: web.go("/myv/messaging/webtext/Challenge.shtml") with tempfile.NamedTemporaryFile(suffix=".jpeg") as captcha: web.save_html(captcha.name) web.back() os.system("open %s " % captcha.name) web.formvalue("WebText", "jcaptcha_response", raw_input("Captcha: ")) web.formvalue("WebText", "message", msg) to = getattr(contact, "mobile", contact) web.formvalue("WebText", "recipient_0", to) web.sleep(2) web.submit() web.code(200) web.find("Message sent!")
def logout(self): "Performs a logout" tc.go( testlib.PROJECT_LIST_URL ) tc.code(200) tc.go("/logout/") tc.code(200) tc.find("You are not logged in")
def create_task(course_id, name, instructions, template='epf', **kwargs): """ create task and return through_id kwargs - additional parameters """ agroup_id = admin_find_course(id=course_id)['agroup_id'] cmd.go('/py/teacher/agroup/%s/course/%s/task/new/' % (agroup_id, course_id)) cmd.fv(1, 'task_name', name) cmd.fv(1, 'task_template', template) cmd.submit() through_id = cmd.url('.+/task/(?P<task_through_id>\d+)/edit/') cmd.fv(1, 'instructions', instructions) cmd.submit('save') errors = soup().findAll('ul', {'class': 'errorlist'}) if errors: raise AssertionError('Page errors: %s' % errors) cmd.find('Changes saved') return through_id
def main(): joker = SpawnKillerThread() try: SpawnDistributedCluster() print "Waiting for two JBoss instances to start up in cluster mode..." time.sleep(10) joker.start() #commands.debug('http', 1) #commands.debug('commands',1) b = get_browser() import socket myip = "http://" + socket.gethostbyname(socket.gethostname()) b.go(myip + "/session-basket") b.submit(5) wordBatch = listOfRandomWords() for idx, w in enumerate(wordBatch): print "Adding word %d: '%s' to the list..." % (idx, w) commands.formvalue("1", "newItem:j_idt11", w) b.submit(4) commands.code(200) commands.find(w) time.sleep(0.25) print wordBatch, len(wordBatch) b.submit(5) commands.code(200) commands.reload() for w in wordBatch: commands.find(w) finally: joker.stopKilling = True joker.join() KillJBoss(0) KillJBoss(1)
def test_edit_email_address(self): # Opt out of the periodic emails. This way, the only "checked" # checkbox is the one for if the user's email address gets shown. paulproteus = Person.objects.get() paulproteus.email_me_re_projects = False paulproteus.save() self.login_with_twill() _url = "http://openhatch.org/account/settings/contact-info/" url = make_twill_url(_url) email = "*****@*****.**" # Go to contact info form tc.go(url) # Let's first ensure that "*****@*****.**" doesn't appear on the page. # (We're about to add it.) tc.notfind('checked="checked"') tc.notfind(email) # Edit email tc.fv("a_settings_tab_form", "edit_email-email", email) tc.submit() # Form submission ought to redirect us back to the form. tc.url(url) # Was email successfully edited? tc.find(email) # And does the email address show up on the profile? tc.go(make_twill_url("http://openhatch.org/people/1")) tc.find(email)
def test_unblock_success(self): tc.fv(2, 'new_holder', 'KONTAKT') tc.submit() tc.code(200) tc.find('successful') self.blocking_mock.unblockDomainsId.assert_called_once_with( [1], 'KONTAKT', False, self.REASON_TEXT, 0)
def test_file_with_invalid_id(self): tc.formfile( 2, 'domains_emails', os.path.join(os.path.dirname(__file__), 'data/domain_2016-09-16_invalid_id.csv')) tc.submit() tc.find( 'Invalid value in column Id: "asdf9". It must be a whole number.')
def test_restore_holder_not_exists(self): tc.fv(2, 'restore_prev_state', True) tc.fv(2, 'new_holder', 'KONTAKT') self.blocking_mock.restorePreAdministrativeBlockStatesId.side_effect = Registry.Administrative.NEW_OWNER_DOES_NOT_EXISTS( what='KONTAKT') tc.submit() tc.url(self.START_URL) tc.find(r'New holder KONTAKT does not exists.')
def run_tool(self, tool_id, **kwd): tool_id = tool_id.replace(" ", "+") """Runs the tool 'tool_id' and pass it the key/values from the *kwd""" tc.go("%s/tool_runner/index?tool_id=%s" % (self.url, tool_id)) tc.code(200) tc.find('runtool_btn') self.submit_form(**kwd) tc.code(200)
def test_restore_error_when_use_remove_admin_contact(self): tc.fv(2, 'restore_prev_state', True) tc.fv(2, 'remove_admin_contacts', True) tc.submit() tc.code(200) tc.find( 'You cannot use "Remove admin. contacts" and "Restore prev. state" at the same time.' )
def test_restore_success(self): tc.fv(2, 'restore_prev_state', True) tc.submit() tc.code(200) tc.find('successful') self.blocking_mock.restorePreAdministrativeBlockStatesId.assert_called_once_with( [1], '', self.REASON_TEXT, 0)
def test_not_blocked_domain_detail_buttons(self): self._prepare_domain_detail(blocked=False) tc.go('http://localhost:8080/domain/detail/?id=1') tc.find(self.FILTER_BUTTON_XPATH % 'Block', 'x') tc.find(self.FILTER_BUTTON_XPATH % 'Blacklist and delete', 'x') tc.notfind(self.FILTER_BUTTON_XPATH % 'Change blocking', 'x') tc.notfind(self.FILTER_BUTTON_XPATH % 'Unblock', 'x')
def test_logout_web(self): self.test_login_web() url = "http://openhatch.org/search/" url = make_twill_url(url) tc.go(url) tc.notfind("log in") tc.follow("log out") tc.find("log in")
def test_logout_web(self): self.test_login_web() url = 'http://openhatch.org/search/' url = make_twill_url(url) tc.go(url) tc.notfind('log in') tc.follow('log out') tc.find('log in')
def _django_admin_delete_object(url): """ delete object with id from django admin by url """ admin_login() cmd.go(url) cmd.code(200) cmd.find('Are you sure?') cmd.submit() cmd.find('deleted successfully')
def login(self): from twill import commands as b b.go('/login') b.fv('login', 'login', 'chris') b.fv('login', 'password', 'chris') b.submit() b.find('You are logged in as chris.')
def run_tool(self, tool_id, **kwd): tool_id = tool_id.replace(" ", "+") """Runs the tool 'tool_id' and pass it the key/values from the *kwd""" tc.go("%s/tool_runner/index?tool_id=%s" % (self.url, tool_id) ) tc.code(200) tc.find('runtool_btn') self.submit_form(**kwd) tc.code(200)
def test_domain_already_blocked(self): self.blocking_mock.blockDomainsId.side_effect = Registry.Administrative.DOMAIN_ID_ALREADY_BLOCKED( what=[ Registry.Administrative.DomainIdHandle( domainId=1, domainHandle='test1.cz'), ]) tc.submit() tc.url(self.START_URL) tc.find('Domain\(s\) test1.cz are already blocked\.')
def delete_teacher(id): admin_login() cmd.go('/YP-admin/teachers/%s/delete/' % id) cmd.find('Delete teacher') cmd.submit() cmd.find('deleted successfully')
def general_login_action(self, username, password, message): """ login with given login/password and find given message on page """ go(SITE) code(200) fv(1, 'username', username) fv(1, 'password', password) submit() code(200) find(message)
def test_reserved_username(self): tc.go(make_twill_url("http://openhatch.org/account/signup/")) tc.notfind("That username is reserved.") tc.fv("signup", "username", "admin") tc.fv("signup", "email", "*****@*****.**") tc.fv("signup", "password1", "blahblahblah") tc.fv("signup", "password2", "blahblahblah") tc.submit() tc.find("That username is reserved.")
def test_usernames_case_insensitive(self): tc.go(make_twill_url("http://openhatch.org/account/signup/")) tc.notfind("already got a user in our database with that username") tc.fv("signup", "username", "PaulProteus") tc.fv("signup", "email", "*****@*****.**") tc.fv("signup", "password1", "blahblahblah") tc.fv("signup", "password2", "blahblahblah") tc.submit() tc.find("already got a user in our database with that username")
def edit_data(self, hid, check_patt=None, **kwd): """ Edits data and sets parameters accordig to the keyword arguments """ tc.go('./edit?hid=%d' % hid ) if check_patt: tc.find(check_patt) if kwd: self.submit_form(form=1, button="edit_genome_btn", **kwd)
def test_reserved_username(self): tc.go(make_twill_url('http://openhatch.org/account/signup/')) tc.notfind('That username is reserved.') tc.fv('signup', 'username', 'admin') tc.fv('signup', 'email', '*****@*****.**') tc.fv('signup', 'password1', 'blahblahblah') tc.fv('signup', 'password2', 'blahblahblah') tc.submit() tc.find('That username is reserved.')
def edit_data(self, hid, check_patt=None, **kwd): """ Edits data and sets parameters accordig to the keyword arguments """ tc.go('./edit?hid=%d' % hid) if check_patt: tc.find(check_patt) if kwd: self.submit_form(form=1, button="edit_genome_btn", **kwd)
def test_usernames_case_insensitive(self): tc.go(make_twill_url('http://openhatch.org/account/signup/')) tc.notfind('already got a user in our database with that username') tc.fv('signup', 'username', 'PaulProteus') tc.fv('signup', 'email', '*****@*****.**') tc.fv('signup', 'password1', 'blahblahblah') tc.fv('signup', 'password2', 'blahblahblah') tc.submit() tc.find('already got a user in our database with that username')
def test_unblock_remove_admin_contacts(self): tc.fv(2, 'new_holder', 'KONTAKT') tc.fv(2, 'remove_admin_contacts', True) tc.submit() tc.code(200) tc.find('successful') self.blocking_mock.unblockDomainsId.assert_called_once_with( [1], 'KONTAKT', True, self.REASON_TEXT, 0)
def test_submit_default_data(self): tc.submit() tc.code(200) tc.find('successful') self.blocking_mock.updateBlockDomainsId.assert_called_once_with([1], [ 'serverDeleteProhibited', 'serverTransferProhibited', 'serverUpdateProhibited' ], None, self.REASON_TEXT, 0)
def test_domain_not_blocked(self): self.blocking_mock.updateBlockDomainsId.side_effect = Registry.Administrative.DOMAIN_ID_NOT_BLOCKED( what=[ Registry.Administrative.DomainIdHandle( domainId=1, domainHandle='test1.cz'), ]) tc.submit() tc.url(self.START_URL) tc.find('Domain\(s\) test1.cz not blocked\.')
def test(self): # Create a project. project = Project.create_dummy() # Create two profiles, each with a PortfolioEntry linking it to the # project, each with descriptions. def create_pfe_with_description(username): return PortfolioEntry.create_dummy( project=project, person=Person.get_by_username(username), is_published=True) pfes = { 'uncheck_me': create_pfe_with_description('paulproteus'), 'keep_me_checked': create_pfe_with_description('barry') } # Get a list of PortfolioEntries that we use to get a random project # description for the project page. descriptions = project.get_pfentries_with_usable_descriptions() # Observe that the list contains both PortfolioEntries. for entry in pfes.values(): self.assert_(entry in descriptions) self.login_with_twill() # Go to the project page. url = urlparse.urljoin("http://openhatch.org", project.get_edit_page_url()) tc.go(better_make_twill_url(url)) # In preparation for the next set of assertions, make sure that the # entries don't have the same description. self.assertNotEqual(pfes['uncheck_me'].project_description, pfes['keep_me_checked'].project_description) # See a list of project descriptions on the page, which equals the # list of descriptions in the DB. for entry in pfes.values(): tc.find(entry.project_description) # Uncheck one of the checkboxes and submit the form name_of_checkbox_to_uncheck = "%s-use_my_description" % pfes[ 'uncheck_me'].pk tc.fv("2", name_of_checkbox_to_uncheck, False) tc.submit() # Get a list of the PortfolioEntries that we use to get a random # project description for the project page. good_pfentries = project.get_pfentries_with_usable_descriptions() # Observe that the list contains only the checked PortfolioEntry. self.assert_(pfes['uncheck_me'] not in good_pfentries) self.assert_(pfes['keep_me_checked'] in good_pfentries)
def test_form_sends_data_to_get(self): # This test will fail if a query that selects one project but doesn't # equal the project's name causes a redirect. relevant = mysite.search.models.Project.create_dummy(name='Twisted System') tc.go(better_make_twill_url('http://openhatch.org/+projects')) query = 'Twisted' tc.fv(1, 'search_q', query) tc.submit() tc.url('\?q=Twisted') # Assert that URL contains this substring. tc.find(query)
def send(self, msg, *send_to): for contact in send_to: web.follow(self.SERVICE_URL) web.follow("newsms") web.formvalue("sendSMS", "smsBody", msg) to = getattr(contact, "mobile", contact) web.formvalue("sendSMS", "smsTo", to) web.submit() web.code(200) web.find("newsms")
def test_unblock_domain_not_blocked(self): tc.fv(2, 'new_holder', 'KONTAKT') self.blocking_mock.unblockDomainsId.side_effect = Registry.Administrative.DOMAIN_ID_NOT_BLOCKED( what=[ Registry.Administrative.DomainIdHandle( domainId=1, domainHandle='test1.cz'), ]) tc.submit() tc.url(self.START_URL) tc.find(r'Domain\(s\) test1.cz not blocked\.')
def test_blacklist_to_date_ok(self): blacklist_to_date = datetime.date.today() + datetime.timedelta(1) tc.fv(2, 'blacklist_to_date', blacklist_to_date.isoformat()) tc.submit() tc.code(200) tc.find('successful') self.blocking_mock.blacklistAndDeleteDomainsId.assert_called_once_with( [1], Patched_IsoDate(blacklist_to_date.isoformat()), self.REASON_TEXT, 0)
def test_create_confirmation_link(self): """ filling and submitting form on create confirmation link page """ go(SITE) code(200) follow("reset password") code(200) fv(2, 'email', '*****@*****.**') submit() code(200) find('Please, check your e-mail')
def test_restore_domain_not_blocked(self): tc.fv(2, 'restore_prev_state', True) self.blocking_mock.restorePreAdministrativeBlockStatesId.side_effect = Registry.Administrative.DOMAIN_ID_NOT_BLOCKED( what=[ Registry.Administrative.DomainIdHandle( domainId=1, domainHandle='test1.cz'), ]) tc.submit() tc.url(self.START_URL) tc.find(r'Domain\(s\) test1.cz not blocked\.')
def test_login_success_no_profile(self): """ successfull login for user without profile """ user1 = User.objects.get(username__exact='user1') user1.get_profile().delete() self.general_login_action('user1', 'password1', 'Welcome, user1') follow('profile') code(200) find('Profile for this user not exists')
def test_unblockable_contact(self): tc.fv(2, 'owner_block_mode', '1') self.blocking_mock.blockDomainsId.side_effect = Registry.Administrative.CONTACT_BLOCK_PROHIBITED( what=[ Registry.Administrative.ContactIdHandle( contactId=1, contactHandle='I_R_MOJEID') ]) tc.submit() tc.url(self.START_URL) tc.find('Contact\(s\) I_R_MOJEID cannot be blocked')
def test(self): # Create a project. project = Project.create_dummy() # Create two profiles, each with a PortfolioEntry linking it to the # project, each with descriptions. def create_pfe_with_description(username): return PortfolioEntry.create_dummy(project=project, person=Person.get_by_username( username), is_published=True) pfes = {'uncheck_me': create_pfe_with_description('paulproteus'), 'keep_me_checked': create_pfe_with_description('barry')} # Get a list of PortfolioEntries that we use to get a random project # description for the project page. descriptions = project.get_pfentries_with_usable_descriptions() # Observe that the list contains both PortfolioEntries. for entry in pfes.values(): self.assert_(entry in descriptions) self.login_with_twill() # Go to the project page. url = urlparse.urljoin( "http://openhatch.org", project.get_edit_page_url()) tc.go(better_make_twill_url(url)) # In preparation for the next set of assertions, make sure that the # entries don't have the same description. self.assertNotEqual( pfes['uncheck_me'].project_description, pfes['keep_me_checked'].project_description) # See a list of project descriptions on the page, which equals the # list of descriptions in the DB. for entry in pfes.values(): tc.find(entry.project_description) # Uncheck one of the checkboxes and submit the form name_of_checkbox_to_uncheck = "%s-use_my_description" % pfes[ 'uncheck_me'].pk tc.fv("2", name_of_checkbox_to_uncheck, False) tc.submit() # Get a list of the PortfolioEntries that we use to get a random # project description for the project page. good_pfentries = project.get_pfentries_with_usable_descriptions() # Observe that the list contains only the checked PortfolioEntry. self.assert_(pfes['uncheck_me'] not in good_pfentries) self.assert_(pfes['keep_me_checked'] in good_pfentries)
def find(self,regex): """ By default Twill commands throw exceptions rather than failures when an assertion fails. Here we wrap the Twill find command and return the expected response along with a helpful message. """ try: tc.go(self.url) tc.find(regex) except TwillAssertionError: self.fail("No match to '%s' on %s" % (regex, self.url))
def logout(): """Visit the logout screen""" global_dict, local_dict = namespaces.get_twill_glocals() # Visit the logout URL hn = global_dict['localhost_url'] commands.go(hn + '/logout') # Make sure the login succeeded commands.find("Remember me")
def test_root_count(root): go("/") show() code(200) find("PyPI compatible package index serving 0 packages") showlinks() root.join("Twisted-11.0.0.tar.bz2").write("") reload() show() find("PyPI compatible package index serving 1 packages")
def delete_project(self, name): """ Deletes a project """ tc.follow("Delete") tc.find("You are removing") tc.fv("1", "delete", True) tc.submit() tc.code(200) tc.find("Project deletion complete") tc.notfind(name)