Esempio n. 1
0
    def test_image_processing_library_error(self):
        """
        If the image processing library errors while preparing a photo, report a
        helpful message to the user and log the error. The photo is not added
        to the user's profile.
        """
        # Get a copy of the error log.
        string_log = StringIO.StringIO()
        logger = logging.getLogger()
        my_log = logging.StreamHandler(string_log)
        logger.addHandler(my_log)
        logger.setLevel(logging.ERROR)

        self.login_with_twill()
        tc.go(make_twill_url('http://openhatch.org/people/paulproteus/'))
        tc.follow('photo')
        # This is a special image from issue166 that passes Django's image
        # validation tests but causes an exception during zlib decompression.
        tc.formfile('edit_photo', 'photo', photo('static/images/corrupted.png'))
        tc.submit()
        tc.code(200)

        self.assert_("Something went wrong while preparing this" in tc.show())
        p = Person.objects.get(user__username='******')
        self.assertFalse(p.photo.name)

        # an error message was logged during photo processing.
        self.assert_("zlib.error" in string_log.getvalue())
        logger.removeHandler(my_log)
Esempio n. 2
0
    def test_image_processing_library_error(self):
        """
        If the image processing library errors while preparing a photo, report a
        helpful message to the user and log the error. The photo is not added
        to the user's profile.
        """
        # Get a copy of the error log.
        string_log = StringIO.StringIO()
        logger = logging.getLogger()
        my_log = logging.StreamHandler(string_log)
        logger.addHandler(my_log)
        logger.setLevel(logging.ERROR)

        self.login_with_twill()
        tc.go(make_twill_url('http://openhatch.org/people/paulproteus/'))
        tc.follow('photo')
        # This is a special image from issue166 that passes Django's image
        # validation tests but causes an exception during zlib decompression.
        tc.formfile('edit_photo', 'photo',
                    photo('static/images/corrupted.png'))
        tc.submit()
        tc.code(200)

        self.assert_("Something went wrong while preparing this" in tc.show())
        p = Person.objects.get(user__username='******')
        self.assertFalse(p.photo.name)

        # an error message was logged during photo processing.
        self.assert_("zlib.error" in string_log.getvalue())
        logger.removeHandler(my_log)
Esempio n. 3
0
    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!")
Esempio n. 4
0
 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)
Esempio n. 5
0
    def test_project_actions(self):

        # main page
        tc.go(testlib.PROJECT_LIST_URL)
        tc.find("Logged in as")

        # default project list
        tc.find("Fly data 19")
        tc.find("Human HELA 16")
        tc.find("Mouse project HBB 1")

        # create a new project
        name = "Rainbow Connection - New Project"
        self.create_project(name=name)

        # visit this new project
        tc.follow(name)
        tc.code(200)
        tc.find("Project: %s" % name)

        # edit and rename project
        newname = "Iguana Garden - New Project"
        tc.follow("Edit")
        tc.find("Edit Project")
        tc.fv("1", "name", newname)
        tc.fv("1", "info", "Some other *markup* goes here")
        tc.submit()
        tc.code(200)
        tc.notfind(name)
        tc.find(newname)

        self.delete_project(name=newname)
Esempio n. 6
0
    def test_project_actions(self):
        
        # main page
        tc.go( testlib.PROJECT_LIST_URL )
        tc.find("Logged in as") 

        # default project list
        tc.find("Fly data 19") 
        tc.find("Human HELA 16") 
        tc.find("Mouse project HBB 1") 


        # create a new project
        name = "Rainbow Connection - New Project"
        self.create_project(name=name)

        # visit this new project
        tc.follow(name)
        tc.code(200)
        tc.find("Project: %s" % name)

        # edit and rename project
        newname = "Iguana Garden - New Project"
        tc.follow("Edit")
        tc.find("Edit Project")
        tc.fv("1", "name", newname )
        tc.fv("1", "info", "Some other *markup* goes here")
        tc.submit()
        tc.code(200)
        tc.notfind(name)
        tc.find(newname)

        self.delete_project(name=newname)
Esempio n. 7
0
    def test_set_avatar(self):
        self.login_with_twill()
        for image in [
                photo('static/sample-photo.png'),
                photo('static/sample-photo.jpg')
        ]:
            url = 'http://openhatch.org/people/paulproteus/'
            tc.go(make_twill_url(url))
            tc.follow('photo')
            tc.formfile('edit_photo', 'photo', image)
            tc.submit()
            # Now check that the photo == what we uploaded
            p = Person.objects.get(user__username='******')
            self.assert_(p.photo.read() == open(image).read())

            response = self.login_with_client().get(
                reverse(mysite.account.views.edit_photo))
            self.assertEqual(
                response.context[0]['photo_url'], p.photo.url,
                "Test that once you've uploaded a photo via the photo editor, "
                "the template's photo_url variable is correct.")
            self.assert_(p.photo_thumbnail)
            thumbnail_as_stored = mysite.base.depends.Image.open(
                p.photo_thumbnail.file)
            w, h = thumbnail_as_stored.size
            self.assertEqual(w, 40)
Esempio n. 8
0
 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')
Esempio n. 9
0
 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')
Esempio n. 10
0
 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")
Esempio n. 11
0
    def test_project_stress(self):
        names = ['STRESS-NAME-%010d' % step for step in range(11)]
        for name in names:
            self.create_project(name)

        for name in names:
            tc.go(testlib.PROJECT_LIST_URL)
            tc.follow(name)
            self.delete_project(name)
Esempio n. 12
0
 def test_project_stress(self):
     names = [ 'STRESS-NAME-%010d' % step for step in range(11) ]
     for name in names:
         self.create_project(name)
     
     for name in names:
         tc.go( testlib.PROJECT_LIST_URL )
         tc.follow(name)
         self.delete_project(name)
Esempio n. 13
0
 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')
Esempio n. 14
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')
Esempio n. 15
0
 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")
Esempio n. 16
0
def push_item(projectname, summary, comment, status, label):
    go('http://code.google.com/p/%s/issues/list' % (projectname, ))
    follow('New Issue')
    fv('3', 'summary', summary)
    fv('3', 'comment', wraptext(comment))
    fv('3', 'status', status)
    fv("3", "labelenter0", label)
    fv("3", "labelenter1", "")

    submit('submit')
    notfind("Letters did not match")
Esempio n. 17
0
def sendNetcom(opts, msg):
    tc.go("https://www.netcom.no")
    tc.follow("» Logg inn på Min side")
    tc.fv('2', 'username', opts["netcom_user"])
    tc.fv('2', 'password', opts["netcom_pass"])
    tc.submit()
    tc.follow("Send 25 gratis SMS")
    tc.fv('2', 'gsmnumber', opts["netcom_user"])
    tc.submit('submitChooseContact')
    tc.fv('2', 'message', msg)
    tc.submit('submitSendsms')
Esempio n. 18
0
 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)
Esempio n. 19
0
def sendNetcom(opts, msg):
    tc.go("https://www.netcom.no")
    tc.follow("» Logg inn på Min side")
    tc.fv('2', 'username', opts["netcom_user"])
    tc.fv('2', 'password', opts["netcom_pass"])
    tc.submit()
    tc.follow("Send 25 gratis SMS")
    tc.fv('2', 'gsmnumber', opts["netcom_user"])
    tc.submit('submitChooseContact')
    tc.fv('2', 'message', msg)
    tc.submit('submitSendsms')
Esempio n. 20
0
def push_item(projectname, summary, comment, status, label):
    go("http://code.google.com/p/%s/issues/list" % (projectname,))
    follow("New Issue")
    fv("3", "summary", summary)
    fv("3", "comment", wraptext(comment))
    fv("3", "status", status)
    fv("3", "labelenter0", label)
    fv("3", "labelenter1", "")

    submit("submit")
    notfind("Letters did not match")
Esempio n. 21
0
def push_item(projectname, summary, comment, status, label):
    go('http://code.google.com/p/%s/issues/list' % (projectname, ))
    follow('New Issue')
    fv('3', 'summary', summary)
    fv('3', 'comment', wraptext(comment))
    fv('3', 'status', status)
    fv("3", "labelenter0", label)
    fv("3", "labelenter1", "")

    submit('submit')
    notfind("Letters did not match")
Esempio n. 22
0
 def test_set_avatar(self):
     self.login_with_twill()
     for image in (photo("static/sample-photo.png"), photo("static/sample-photo.jpg")):
         url = "http://openhatch.org/people/1/"
         tc.go(make_twill_url(url))
         tc.follow("photo")
         tc.formfile("edit_photo", "photo", image)
         tc.submit()
         # Now check that the photo == what we uploaded
         p = Person.objects.get(user__username="******")
         self.assert_(p.photo.read() == open(image).read())
Esempio n. 23
0
 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)
Esempio n. 24
0
 def test_reg_user_exists(self):
     """ failed registration with existing username """
     go(SITE)
     code(200)
     follow('registration')
     code(200)
     fv(2, 'username', 'user1')
     fv(2, 'password1', 'password3')
     fv(2, 'password2', 'password3')
     submit()
     code(200)
     find('A user with that username already exists')
 def test1(self):
     url = "http://www.yourwebsite.com/signup/"
     twill_quiet()
     tc.go('ubuntu')
     tc.find('Registro Brasileiro')
     tc.follow('register')
     tc.url()
     # Fill in the form
     tc.fv('1', 'username', 'test123')
     tc.fv('1', 'email', '*****@*****.**')
     tc.submit()
     tc.find('click the activation link')
Esempio n. 26
0
 def test_set_avatar(self):
     self.login_with_twill()
     for image in (photo('static/sample-photo.png'),
                   photo('static/sample-photo.jpg')):
         url = 'http://openhatch.org/people/paulproteus/'
         tc.go(make_twill_url(url))
         tc.follow('photo')
         tc.formfile('edit_photo', 'photo', image)
         tc.submit()
         # Now check that the photo == what we uploaded
         p = Person.objects.get(user__username='******')
         self.assert_(p.photo.read() == open(image).read())
Esempio n. 27
0
 def test_reg_passwords_not_equal(self):
     """ failed registration with entering not equal passwords """
     go(SITE)
     code(200)
     follow('registration')
     code(200)
     fv(2, 'username', 'user3')
     fv(2, 'password1', 'password3')
     fv(2, 'password2', 'password')
     submit()
     code(200)
     find("The two password fields didn't match")
Esempio n. 28
0
 def test_set_avatar(self):
     self.login_with_twill()
     for image in (photo('static/sample-photo.png'),
                   photo('static/sample-photo.jpg')):
         url = 'http://openhatch.org/people/paulproteus/'
         tc.go(make_twill_url(url))
         tc.follow('photo')
         tc.formfile('edit_photo', 'photo', image)
         tc.submit()
         # Now check that the photo == what we uploaded
         p = Person.objects.get(user__username='******')
         self.assert_(p.photo.read() ==
                 open(image).read())
Esempio n. 29
0
 def login(self, name='admin', passwd='1'):
     "Performs a login"
     tc.go( testlib.BASE_URL )
     tc.follow('Log in now')
     tc.find("Please log in") 
     tc.code(200)
     
     # logs in on every test
     tc.fv("1", "email", name)
     tc.fv("1", "password", passwd)
     tc.submit('0')
     tc.code(200)
     tc.find("Logged in as") 
Esempio n. 30
0
 def test_reg_success(self):
     """ successfull registration """
     go(SITE)
     code(200)
     follow('registration')
     code(200)
     fv(2, 'username', 'user3')
     fv(2, 'password1', 'password3')
     fv(2, 'password2', 'password3')
     submit()
     code(200)
     find('New account successfully created')
     self.general_login_action('user3', 'password3', 'Welcome, user3')
Esempio n. 31
0
 def test_set_avatar_too_wide(self):
     self.login_with_twill()
     for image in [photo("static/images/too-wide.jpg"), photo("static/images/too-wide.png")]:
         url = "http://openhatch.org/people/1/"
         tc.go(make_twill_url(url))
         tc.follow("photo")
         tc.formfile("edit_photo", "photo", image)
         tc.submit()
         # Now check that the photo is 200px wide
         p = Person.objects.get(user__username="******")
         image_as_stored = mysite.base.depends.Image.open(p.photo.file)
         w, h = image_as_stored.size
         self.assertEqual(w, 260)
Esempio n. 32
0
    def login(self, name='admin', passwd='1'):
        "Performs a login"
        tc.go(testlib.BASE_URL)
        tc.follow('Log in now')
        tc.find("Please log in")
        tc.code(200)

        # logs in on every test
        tc.fv("1", "email", name)
        tc.fv("1", "password", passwd)
        tc.submit('0')
        tc.code(200)
        tc.find("Logged in as")
Esempio n. 33
0
    def test_project_manager_sharing(self):
        # test sharing as a manager

        # main page
        tc.go(testlib.PROJECT_LIST_URL)
        tc.find("Logged in as")

        # default project list
        tc.find("Yeast mutant RAV 17")
        tc.follow("Yeast mutant RAV 17")
        tc.follow("Sharing")
        tc.find("Current members")
        tc.find("Add access")

        # search for then add Demo User to this project
        tc.fv("1", "text", "demo")
        tc.submit()
        tc.code(200)
        tc.find("Demo User")
        tc.follow("add as member")
        tc.find("Demo User")

        # back to the project view
        tc.follow("<< return to project")
        tc.find("Yeast mutant RAV 17")
Esempio n. 34
0
 def general_reg_action(self, username, email, password1, password2):
     """
     registration with given username/password/email
     """
     go(SITE)
     code(200)
     follow('registration')
     code(200)
     fv(2, 'id_username', username)
     fv(2, 'id_email', email)
     fv(2, 'id_password1', password1)
     fv(2, 'id_password2', password2)
     submit()
     code(200)
Esempio n. 35
0
 def test_set_avatar_too_wide(self):
     self.login_with_twill()
     for image in [photo('static/images/too-wide.jpg'),
                   photo('static/images/too-wide.png')]:
         url = 'http://openhatch.org/people/paulproteus/'
         tc.go(make_twill_url(url))
         tc.follow('photo')
         tc.formfile('edit_photo', 'photo', image)
         tc.submit()
         # Now check that the photo is 200px wide
         p = Person.objects.get(user__username='******')
         image_as_stored = Image.open(p.photo.file)
         w, h = image_as_stored.size
         self.assertEqual(w, 200)
Esempio n. 36
0
 def general_login_action(self, username, password, message):
     """
     login with given username/password and find given message on page
     """
     clear_extra_headers()
     go(SITE)
     code(200)
     follow('common login')
     code(200)
     fv(1, 'username', username)
     fv(1, 'password', password)
     submit()
     code(200)
     find(message)
Esempio n. 37
0
def sendTelenor(opts, msg):
    # Login
    tc.go("https://telenormobil.no/norm/telenor/sms/send.do")
    tc.fv("loginForm", "phonenumber", opts["telenor_user"])
    tc.fv("loginForm", "password", opts["telenor_pass"])
    tc.submit()

    # Send
    tc.fv("smsSendSmsForm", "toAddress", opts["telenor_user"])
    tc.fv("smsSendSmsForm", "message", msg)
    tc.submit()

    # Logout
    tc.follow("Logg ut")
Esempio n. 38
0
 def create_project(self, name, info='no info'):
     """
     Creates a new project
     """
     tc.go( testlib.PROJECT_LIST_URL )
     tc.find("Logged in as") 
     tc.follow('New Project')
     tc.code(200)
     tc.find("Create New Project")
     tc.fv("1", "name", name )
     tc.fv("1", "info", info)
     tc.submit()
     tc.code(200)
     tc.find(name)
Esempio n. 39
0
def sendTelenor(opts, msg):
    # Login
    tc.go("https://telenormobil.no/norm/telenor/sms/send.do")
    tc.fv("loginForm", "phonenumber", opts["telenor_user"])
    tc.fv("loginForm", "password", opts["telenor_pass"])
    tc.submit()

    # Send
    tc.fv("smsSendSmsForm", "toAddress", opts["telenor_user"])
    tc.fv("smsSendSmsForm", "message", msg)
    tc.submit()

    # Logout
    tc.follow("Logg ut")
Esempio n. 40
0
 def create_project(self, name, info='no info'):
     """
     Creates a new project
     """
     tc.go(testlib.PROJECT_LIST_URL)
     tc.find("Logged in as")
     tc.follow('New Project')
     tc.code(200)
     tc.find("Create New Project")
     tc.fv("1", "name", name)
     tc.fv("1", "info", info)
     tc.submit()
     tc.code(200)
     tc.find(name)
Esempio n. 41
0
    def test_project_manager_sharing(self):
        # test sharing as a manager

        # main page
        tc.go( testlib.PROJECT_LIST_URL )
        tc.find("Logged in as") 
        
        # default project list
        tc.find("Yeast mutant RAV 17") 
        tc.follow("Yeast mutant RAV 17")
        tc.follow("Sharing")
        tc.find("Current members")
        tc.find("Add access")

        # search for then add Demo User to this project
        tc.fv("1", "text", "demo" )
        tc.submit()
        tc.code(200)
        tc.find("Demo User")
        tc.follow("add as member")
        tc.find("Demo User")

        # back to the project view
        tc.follow("<< return to project")
        tc.find("Yeast mutant RAV 17") 
Esempio n. 42
0
 def test_set_avatar_too_wide(self):
     self.login_with_twill()
     for image in [
             photo('static/images/too-wide.jpg'),
             photo('static/images/too-wide.png')
     ]:
         url = 'http://openhatch.org/people/paulproteus/'
         tc.go(make_twill_url(url))
         tc.follow('photo')
         tc.formfile('edit_photo', 'photo', image)
         tc.submit()
         # Now check that the photo is 200px wide
         p = Person.objects.get(user__username='******')
         image_as_stored = mysite.base.depends.Image.open(p.photo.file)
         w, h = image_as_stored.size
         self.assertEqual(w, 200)
Esempio n. 43
0
File: ygd.py Progetto: tuxdna/ygd
def start(args):
    parser = OptionParser(version=VERSION)
    parser.add_option("-p", "--password", help="account password")
    parser.add_option("-u", "--username", help="account user name")
    parser.add_option("-g", "--groupname", help="group name")

    (options, args) = parser.parse_args(args)
    password = options.password
    username = options.username
    yahoo_group = options.groupname
    if not (username and yahoo_group):
        parser.print_help()
        sys.exit(1)

    if not password:
        password = getpass.getpass()

    if not password:
        parser.print_help()
        sys.exit(1)

    yg_url = "%s/%s/"%(YG_BASE_URL, yahoo_group)

    tc.go(yg_url)
    tc.follow("Sign In")
    tc.formvalue(1, 'login', username)
    tc.formvalue(1, 'passwd', password)
    tc.submit()
    tc.follow("Messages")

    b = tc.get_browser()
    browser_title =  b.get_title()
    m = re.search(r'Messages : (\d+)-(\d+) of (\d+)', browser_title)

    if not m:
        print "regular expression failed"
        sys.exit(1)

    start, end, total_messages = m.groups()

    for i in range(int(total_messages)):
        message_id = i + 1
        message_path = '%s/%s'%(yahoo_group, message_id)
        download_message(message_id, message_path, yahoo_group)
Esempio n. 44
0
    def test_404(self):
        # testing 404 errors
        tc.go(testlib.BASE_URL)
        tc.go("./nosuchurl")
        tc.code(404)

        tc.go(testlib.BASE_URL)
        tc.follow('Log in now')
        tc.find("Please log in")
        tc.code(200)

        # logs in on every test
        tc.fv("1", "email", 'admin')
        tc.fv("1", "password", '1')
        tc.submit('0')
        #print tc.show()

        tc.code(200)
        tc.find("Logged in as")
Esempio n. 45
0
    def test_404(self):
        # testing 404 errors
        tc.go( testlib.BASE_URL )
        tc.go( "./nosuchurl" )
        tc.code(404)

        tc.go( testlib.BASE_URL )
        tc.follow('Log in now')
        tc.find("Please log in") 
        tc.code(200)
        
        # logs in on every test
        tc.fv("1", "email", 'admin')
        tc.fv("1", "password", '1')
        tc.submit('0')
        #print tc.show()

        tc.code(200)
        tc.find("Logged in as")
Esempio n. 46
0
    def change_password(self, old_pass, new_pass, should_succeed=True):
        tc.go(make_twill_url('http://openhatch.org/people/paulproteus'))
        tc.follow('settings')
        tc.follow('Password')
        tc.url('/account/settings/password')

        tc.fv('a_settings_tab_form', 'old_password', old_pass)
        tc.fv('a_settings_tab_form', 'new_password1', new_pass)
        tc.fv('a_settings_tab_form', 'new_password2', new_pass)
        tc.submit()

        # Try to log in with the new password now
        client = Client()
        username = '******'
        success = client.login(username=username, password=new_pass)
        if should_succeed:
            success = success
        else:
            success = not success
        self.assert_(success)
Esempio n. 47
0
def create_teacher(forename, surname, institution, email, country, title=''):
    """ create teacher and return {id, login} info dict """
    cmd.go('/py/teacher/login/')
    cmd.find('logging into Yacapaca')

    cmd.follow('here')  # for signup click here

    cmd.find('Sign up - step 1/2')
    cmd.fv(2, 'forename', forename)
    cmd.fv(2, 'surname', surname)
    cmd.fv(2, 'institution', institution)
    cmd.fv(2, 'agree', 'on')
    cmd.submit()

    cmd.find('Sign up - step 2/2')
    cmd.fv(2, 'title', title)
    cmd.fv(2, 'email', email)
    cmd.fv(2, 'country', country)
    capture = get_teacher_capture()
    cmd.fv(2, 'confirm', capture)
    cmd.submit()

    cmd.find('Registration has been completed')

    r = re.compile('Login: (?P<login>[\w]+)')
    login_text = soup().find(text=r)
    login = r.search(login_text).groupdict()['login']

    admin_login()
    teacher_list_url = '/YP-admin/teachers/list/?' + \
                       urllib.urlencode({'action': 'start_search',
                                         'table': 'admintable',
                                         'login:varchar(32):eq': login})

    cmd.go(teacher_list_url)
    cmd.find('Teachers List')
    id = soup().find('td', {'class': 'selchk'}).nextSibling.nextSibling.string

    return dict(login=login, id=id)
Esempio n. 48
0
    def test_invalid_photo(self):
        """
        If the uploaded image is detected as being invalid, report a helpful
        message to the user. The photo is not added to the user's profile.
        """
        bad_image = tempfile.NamedTemporaryFile(delete=False)
        self.login_with_twill()

        try:
            bad_image.write("garbage")
            bad_image.close()

            tc.go(make_twill_url('http://openhatch.org/people/paulproteus/'))
            tc.follow('photo')
            tc.formfile('edit_photo', 'photo', bad_image.name)
            tc.submit()
            tc.code(200)
            self.assert_("The file you uploaded was either not an image or a "
                         "corrupted image" in tc.show())

            p = Person.objects.get(user__username='******')
            self.assertFalse(p.photo.name)
        finally:
            os.unlink(bad_image.name)
Esempio n. 49
0
def getResults(opts):
    # Twill prints a lot of shit, we don't want that.
    twill.set_output(StringIO.StringIO())

    # Log into studweb
    tc.go(
        "https://studweb.uio.no/as/WebObjects/studentweb2.woa/3/wa/default?inst=UiO"
    )
    tc.fv("2", "fodselsnr", opts["fnr"])
    tc.fv("2", "pinkode", opts["pin"])
    tc.submit()

    # Navigating to grades. Bad localization for NN users. No loc. for EN :(
    try:
        tc.follow('Se opplysninger om deg')
    except te.TwillAssertionError:
        try:
            # Note: wildcard in linkname.
            # Problems with special NO chars (æøå).
            tc.follow('Sj. opplysningar om deg')
        except te.TwillAssertionError:
            print "Error: Unknown language on site?"
            sys.exit(1)
    tc.follow('Resultater')

    # Storing HTML in var.
    data = tc.show()

    tc.follow('Logg ut')

    # Pulling coursecode and grade out of HTML, converting flunking to
    # 'F', and putting it in an array.
    # Ex. result: [["INF1000", "B"], ["INF1040", "E"]]
    res = re.findall('<tr class="pysj\d">(.*?)</tr>', data)
    ans = {}
    for i in res:
        if not re.search("Ikkje møtt|Ikke møtt", i):
            tmp = re.findall("<td.*?>(.*?)</td>", i)
            if not re.search("[A-E]", tmp[7]):
                tmp[7] = "F"
            if (not ans.has_key(tmp[1])) or (ans.has_key(tmp[1])
                                             and ans[tmp[1]] == "F"):
                ans[tmp[1]] = tmp[7]
    return reduce(lambda x, y: x + [[y, ans[y]]], ans, [])
Esempio n. 50
0
    def test_project_member_sharing(self):

        # tests sharing as a member
        tc.go(testlib.PROJECT_LIST_URL)
        tc.find("Logged in as")

        # a project list with member access
        tc.find("Fly data 19")
        tc.follow("Fly data 19")
        tc.follow("Sharing")
        tc.find("Current members")

        # members may not add access
        tc.notfind("Add access")
        tc.follow("<< return to project")
        tc.find("Project: Fly data 19")
Esempio n. 51
0
    def test_data_uploads(self):
        # data upload test
        name = 'Upload-test-name'
        self.create_project(name)

        tc.follow(name)

        # find the project id
        url = tc.follow('Edit')
        pid = url.split("/")[-2]
        tc.go("/data/upload/simple/%s/" % pid)

        # search for then add Demo User to this project
        tc.formfile("1", "File1", conf.testdata('short-data.bed'))
        tc.formfile("1", "File2", conf.testdata('short-good-input.gtrack'))
        tc.formfile("1", "File3", conf.testdata('readcounts.png'))
        tc.submit()

        # verify uploads
        tc.find("short-data.bed")
        tc.find("short-good-input.gtrack")
        tc.find("readcounts.png")

        # visit the dataset
        tc.follow("short-good-input.gtrack")
        tc.find("waiting")

        # edit the dataset
        tc.follow("Edit")
        tc.fv("1", "name", "short-good-input.gtrack")
        tc.fv("1", "info", "extra-info")
        tc.submit()
        tc.find("extra-info")

        # upload two results for it
        tc.follow("Add results")
        tc.formfile("1", "content", conf.testdata('short-data.bed'))
        tc.formfile("1", "image", conf.testdata('readcounts.png'))
        tc.submit()
        tc.follow("short-data.bed")
        tc.back()

        # upload one image
        tc.follow("Add results")
        tc.formfile("1", "image", conf.testdata('shift.png'))
        tc.submit()
        tc.follow("shift.png")
        tc.back()

        # back to project view
        tc.follow("Project view")
        self.delete_project(name)
Esempio n. 52
0
def test_links_parsing():
    commands.config('use_tidy', '0')
    commands.go('/broken_linktext')
    commands.follow('some text')
    commands.config('use_tidy', '1')
Esempio n. 53
0
def test():
    url = twilltestlib.get_url()

    # capture output
    fp = StringIO()
    twill.set_output(fp)

    twill.parse.execute_string('code 200', initial_url=url)

    # from file
    twilltestlib.execute_twill_script('test-go.twill', initial_url=url)

    twill.set_output(None)
    assert fp.getvalue()

    ###

    # from stdin
    filename = os.path.join(twilltestlib.testdir, 'test-go.twill')
    old_in, sys.stdin = sys.stdin, open(filename)
    try:
        twilltestlib.execute_twill_script('-', initial_url=url)
    finally:
        sys.stdin = old_in

    # from parse.execute_file
    twill.parse.execute_file('test-go-exit.twill', initial_url=url)

    # also test some failures.

    old_err, sys.stderr = sys.stderr, StringIO()
    try:
        twill.set_errout(sys.stderr)
        #
        # failed assert in a script
        #
        try:
            twill.parse.execute_file('test-go-fail.twill', initial_url=url)
            assert 0
        except TwillAssertionError:
            pass

        commands.go(url)
        try:
            commands.code(400)
            assert 0
        except TwillAssertionError:
            pass

        #
        # no such command (NameError)
        #

        try:
            twill.parse.execute_file('test-go-fail2.twill', initial_url=url)
            assert 0
        except TwillNameError, e:
            pass
    finally:
        sys.stderr = old_err

    namespaces.new_local_dict()
    gd, ld = namespaces.get_twill_glocals()

    commands.go(url)
    try:
        twill.parse.execute_command('url', ('not this', ), gd, ld, "anony")
        assert 0, "shouldn't get here"
    except TwillAssertionError:
        pass

    try:
        commands.follow('no such link')
        assert 0, "shouldn't get here"
    except TwillAssertionError:
        pass

    try:
        commands.find('no such link')
        assert 0, "shouldn't get here"
    except TwillAssertionError:
        pass

    try:
        commands.notfind('Hello')
        assert 0, "shouldn't get here"
    except TwillAssertionError:
        pass

    try:
        twill.parse.execute_command('exit', ('0', ), gd, ld, "anony")
        assert 0, "shouldn't get here"
    except SystemExit:
        pass
Esempio n. 54
0
def click(link):
    follow(link)
Esempio n. 55
0
def pobierzPlan(user, password):
    tablicaHTMLow = []
    commands.add_extra_header(
        'User-agent',
        'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6')
    commands.clear_cookies()  # Czyszczenie ciastek
    commands.reset_browser()  #restart przegladarki
    commands.reset_output()
    #commands.config('use_BeautifulSoup', '0')
    commands.go("https://edukacja.pwr.wroc.pl/EdukacjaWeb/studia.do"
                )  # Przechodzimy do edukacji

    commands.showlinks()  # DO USUNIECIA! Pokazuje linki

    commands.formclear('1')  # Czysci formularz logowania
    commands.formvalue('1', 'login', user)  # Podaje login
    commands.formvalue('1', 'password', password)  # Podaje hasło
    commands.submit('0')  # Klika zaloguj

    print("Linki po submit")  # DO USUNIECIA! Pokazuje informacje
    commands.showlinks()  # DO USUNIECIA! Pokazuje linki

    czyBledneLogowanie = sprawdzCzyBledneLogowanie(
        commands.show())  # Sprawdza czy na stronie wystapil blad
    czyLogowanieWInnejSesji = sprawdzCzyLogowanieWInnejSesji(commands.show())
    if (czyBledneLogowanie == True):
        return "Bledne dane logowania"
    if (czyLogowanieWInnejSesji == True):
        return "zalogowany w innej sesji"
    commands.follow("zapisy.do")  # Przechodzi linkiem na stronę zapisów

    # DO USUNIECIA! Pokazuje stronę po kliknięciu zapisy!
    print("Co po kliknieciu Zapisy")
    #commands.show()
    commands.showlinks()
    print "Forms:"
    formsy = commands.showforms()

    links = commands.showlinks()  # Pobiera linki z danej strony
    control = None
    values = None
    select_options = None
    try:
        control = commands.browser.get_form("1").find_control('ineSluId',
                                                              type="select")
    except:
        print("Nie ma selecta.")
    #control = commands.browser.get_form("1").find_control('ineSluId', type="select")

    if (control != None):  # Jesli na stronie jest select
        values = pobierzElementySelect(
            commands.show())  # Pobieram parserem wartosci selecta
        select_options = utworzTabeleSelect(
            values)  # Tworze nowy select podmieniajac stary
        select_attrs = {'id': 'some_id'}  # Tworze atrybuty nowego selecta
        for v in values:  # Lece petla po wartosciach selecta
            form = commands.get_browser().get_form("1")  # Pobieram formularz
            ct = commands.browser.get_form("1").find_control(
                'ineSluId', type="select")  # Pobieram kontrolke z selectem
            add_select_to_form(form, 'ineSluId', select_attrs,
                               select_options)  # Tworze nowego selecta
            form.fixup(
            )  # Sprawdzam czy cos nowego nie zostało dodanego do form
            commands.showforms()

            commands.formvalue("1", ct.name,
                               v.strip())  # Podaje wartosc dla selecta
            commands.submit('0')  # Klikam submit
            html = pobierzZajecia(commands)  # Pobieram zajecia
            commands.follow("zapisy.do")  # Wracam do strony zapisów

            #commands.sleep(6)
            if (
                    html != "skreslony z kierunku"
            ):  # Jesli funkcja zwrocila ze jest ktos skreslony to nie dodaje htmlu
                tablicaHTMLow.append(
                    html
                )  # Jeli nie zwrocila takiego komunikatu to dodajemy ten html do tablicy
    else:
        html = pobierzZajecia(
            commands
        )  # Jesli nie ma selecta to pobieramy zajeci z tego kierunku i juz :D
        if (html != "skreslony z kierunku"):
            tablicaHTMLow.append(html)

    #print control.name, control.value, control.type
    #item = control.get("172748")
    #print item.name, item.selected, item.id, item.attrs

    #new_options
    #commands.formclear('1')
    #
    #
    #form = commands.get_browser().get_form("1")
    #
    #print('TO JEST TEN FORM:')
    #print(form)
    #print(len(form.controls))
    #
    #notIsSelect = True

    #for ct in form.controls:
    #    #print(ct)
    #    if ct.name == 'ineSluId':
    #        notIsSelect = False
    #        print('JESTEM')
    #        commands.sleep(3)
    #
    #        select_attrs = {'id': 'some_id'}
    #        values = pobierzElementySelect(commands.show())
    #        select_options = utworzTabeleSelect(values)
    #        print(values)
    #        print(select_options)
    #
    #
    #        for v in values:
    #            #form.fixup()
    #            add_select_to_form(form, 'ineSluId', select_attrs, select_options)
    #            form.fixup()
    #            #ct.get(v).selected = True
    #            print(ct)
    #            print(form)
    #            print(v)
    #            commands.showforms()
    #
    #            commands.formvalue("1", ct.name, v.strip())            # Podaje login
    #            print("JEEDEFE")
    #            commands.submit('0')
    #            html = pobierzZajecia(commands)
    #            commands.follow("zapisy.do")
    #            print("JEEEEEEEEESSSSSTTTTTEEEEEMMM")
    #
    #            commands.sleep(6)
    #            if (html != "skreslony z kierunku"):
    #                tablicaHTMLow.append(html)
    #ct.get(v).selected = False

    #for ct2 in form.controls:
    #    if ct2.type == 'submit':                                             # szukam wsrod niej tej co ma typ submit
    #        commands.get_browser().clicked(form, ct2.attrs['name'])      # klikam na ten przycisk
    #        commands.get_browser().submit()

    #links = commands.showlinks()
    #commands.back()
    #commands.showforms()

    #return "no"

    #if (notIsSelect == True):
    #    html = pobierzZajecia(commands)
    #    if (html != "skreslony z kierunku"):
    #        tablicaHTMLow.append(html)

    wyloguj(commands)
    commands.browser.clear_cookies()  #usuwanie ciasteczek
    commands.reset_browser()  #restart przegladarki
    commands.reset_output()

    return tablicaHTMLow
Esempio n. 56
0
def annotate(params, proteins, \
             force=False):
    """
    DEPRECATED: The TMB-HUNT server appears to be permanently offline.

    Uses the TMB-HUNT web service
    (http://bmbpcu36.leeds.ac.uk/~andy/betaBarrel/AACompPred/aaTMB_Hunt.cgi) to
    predict if proteins are outer membrane beta-barrels.

    NOTE: In my limited testing, TMB-HUNT tends to perform very poorly in
          terms of false positives and false negetives. I'd suggest using only
          BOMP.
    """
    # TODO: automatically split large sets into multiple jobs
    #       TMB-HUNT will only take 10000 seqs at a time
    if len(proteins) >= 10000:
        log_stderr(
            "# ERROR: TMB-HUNT(web): can't take more than 10,000 sequences.")
        return

    # set the user-agent so web services can block us if they want ... :/
    python_version = sys.version.split()[0]
    agent("Python-urllib/%s (twill; inmembrane)" % python_version)

    out = 'tmbhunt.out'
    log_stderr("# TMB-HUNT(web) %s > %s" % (params['fasta'], out))

    if not force and os.path.isfile(out):
        log_stderr("# -> skipped: %s already exists" % out)
        return parse_tmbhunt(proteins, out)

    # dump extraneous output into this blackhole so we don't see it
    if not __DEBUG__: twill.set_output(StringIO.StringIO())

    go("http://bmbpcu36.leeds.ac.uk/~andy/betaBarrel/AACompPred/aaTMB_Hunt.cgi"
       )
    if __DEBUG__: showforms()

    # read up the FASTA format seqs
    fh = open(params['fasta'], 'r')
    fasta_seqs = fh.read()
    fh.close()

    # fill out the form
    fv("1", "sequences", fasta_seqs)

    submit()
    if __DEBUG__: showlinks()

    # small jobs will lead us straight to the results, big jobs
    # go via a 'waiting' page which we skip past if we get it
    job_id = None
    try:
        # we see this with big jobs
        result_table_url = follow(
            "http://www.bioinformatics.leeds.ac.uk/~andy/betaBarrel/AACompPred/tmp/tmp_output.*.html"
        )
        job_id = result_table_url.split('tmp_output')[-1:][0].split('.')[0]
    except:
        # small jobs take us straight to the html results table
        pass

    # parse the job_id from the url, since due to a bug in
    # TMB-HUNT the link on the results page from large jobs is wrong
    if not job_id:        job_id = \
follow("Full results").split('/')[-1:][0].split('.')[0]
    log_stderr(
        "# TMB-HUNT(web) job_id is: %s <http://www.bioinformatics.leeds.ac.uk/~andy/betaBarrel/AACompPred/tmp/tmp_output%s.html>"
        % (job_id, job_id))

    # polling until TMB-HUNT finishes
    # TMB-HUNT advises that 4000 sequences take ~10 mins
    # we poll a little faster than that
    polltime = (len(proteins) * 0.1) + 2
    while True:
        log_stderr("# TMB-HUNT(web): waiting another %i sec ..." % (polltime))
        time.sleep(polltime)
        try:
            go("http://bmbpcu36.leeds.ac.uk/~andy/betaBarrel/AACompPred/tmp/%s.txt"
               % (job_id))
            break
        except:
            polltime = polltime * 2

        if polltime >= 7200:  # 2 hours
            log_stderr("# TMB-HUNT error: Taking too long.")
            return

    txt_out = show()

    # write raw TMB-HUNT results
    fh = open(out, 'w')
    fh.write(txt_out)
    fh.close()

    return parse_tmbhunt(proteins, out)