示例#1
0
    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)
示例#2
0
    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)
        # Show email
        tc.fv("a_settings_tab_form", 'show_email-show_email', '1') # [1]
        tc.submit()

        # Form submission ought to redirect us back to the form.
        tc.url(url)

        # Was email successfully edited? 
        tc.find(email)

        # Was email visibility successfully edited? [2]
        tc.find('checked="checked"')

        # And does the email address show up on the profile?
        tc.go(make_twill_url(
                'http://openhatch.org/people/paulproteus'))
        tc.find(email)

        # 2. And when we uncheck, does it go away?
        
        # 2.1. Go to contact info form
        tc.go(url)

        # 2.2. Don't show email
        tc.fv("a_settings_tab_form", 'show_email-show_email', '0') # [1]
        tc.submit()

        # 2.3. Verify it's not on profile anymore
        tc.go(make_twill_url(
                'http://openhatch.org/people/paulproteus'))
        tc.notfind(email)
示例#3
0
    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)
        # Show email
        tc.fv("a_settings_tab_form", 'show_email-show_email', '1')  # [1]
        tc.submit()

        # Form submission ought to redirect us back to the form.
        tc.url(url)

        # Was email successfully edited?
        tc.find(email)

        # Was email visibility successfully edited? [2]
        tc.find('checked="checked"')

        # And does the email address show up on the profile?
        tc.go(make_twill_url('http://openhatch.org/people/paulproteus'))
        tc.find(email)

        # 2. And when we uncheck, does it go away?

        # 2.1. Go to contact info form
        tc.go(url)

        # 2.2. Don't show email
        tc.fv("a_settings_tab_form", 'show_email-show_email', '0')  # [1]
        tc.submit()

        # 2.3. Verify it's not on profile anymore
        tc.go(make_twill_url('http://openhatch.org/people/paulproteus'))
        tc.notfind(email)
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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')
示例#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")
示例#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')
示例#10
0
 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.')
示例#11
0
文件: tests.py 项目: reik/oh-mainline
 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")
示例#12
0
 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')
示例#13
0
 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.')
示例#14
0
 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')
示例#15
0
文件: tests.py 项目: reik/oh-mainline
 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.")
示例#16
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())
示例#17
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())
示例#18
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)
示例#19
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())
示例#20
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)
示例#21
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)
示例#22
0
    def change_password(self, old_pass, new_pass, should_succeed=True):
        tc.go(make_twill_url("http://openhatch.org/people/1"))
        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)
示例#23
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)
示例#24
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)
示例#25
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)
示例#26
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/1/"))
            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)
示例#27
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)