<commit_before># -*- coding: utf-8 -*-
##
## $Id$
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

# pylint: disable-msg=E1102

"""WebSession Regression Test Suite."""

__revision__ = \
    "$Id$"

import unittest

from mechanize import Browser

from invenio.dbquery import run_sql
from invenio.config import sweburl, adminemail
from invenio.testutils import make_test_suite, warn_user_about_tests_and_run, \
                              test_web_page_content, merge_error_messages

class WebSessionYourSettingsTest(unittest.TestCase):
    """Check WebSession web pages whether they are up or not."""

    def tearDown(self):
        run_sql('DELETE FROM user WHERE email="<EMAIL>"')
        run_sql('DELETE FROM user WHERE email="<EMAIL>"')

    def test_password_setting(self):
        """webuser - check password settings"""
        browser = Browser()
        browser.open(sweburl + "/youraccount/login")
        browser.select_form(nr=0)
        browser['p_un'] = 'admin'
        browser['p_pw'] = ''
        browser.submit()

        expected_response = "You are logged in as admin"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                      (expected_response, login_response_body))

        # Going to set new password from "" to "<PASSWORD>"
        browser.open(sweburl + "/youraccount/edit")
        browser.select_form(name="edit_password")
        browser['old_password'] = ""
        browser['password'] = "<PASSWORD>"
        browser['password2'] = "<PASSWORD>"
        browser.submit()
        expected_response = "Password successfully edited"
        change_password_body = browser.response().read()
        try:
            change_password_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                    (expected_response, change_password_body))

        # Going to set a wrong old password
        browser.open(sweburl + "/youraccount/edit")
        browser.select_form(name="edit_password")
        browser['old_password'] = "<PASSWORD>"
        browser['password'] = "<PASSWORD>"
        browser['password2'] = "<PASSWORD>"
        browser.submit()
        expected_response = "Wrong old password inserted"
        change_password_body = browser.response().read()
        try:
            change_password_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                    (expected_response, change_password_body))

        # Going to put different new passwords
        browser.open(sweburl + "/youraccount/edit")
        browser.select_form(name="edit_password")
        browser['old_password'] = "<PASSWORD>"
        browser['password'] = "<PASSWORD>"
        browser['password2'] = "<PASSWORD>"
        browser.submit()
        expected_response = "Both passwords must match"
        change_password_body = browser.response().read()
        try:
            change_password_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                    (expected_response, change_password_body))

        # Reset the situation
        browser.open(sweburl + "/youraccount/edit")
        browser.select_form(name="edit_password")
        browser['old_password'] = "<PASSWORD>"
        browser['password'] = ""
        browser['password2'] = ""
        browser.submit()
        expected_response = "Password successfully edited"
        change_password_body = browser.response().read()
        try:
            change_password_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                    (expected_response, change_password_body))

    def test_email_caseless(self):
        """webuser - check email caseless"""
        browser = Browser()
        browser.open(sweburl + "/youraccount/register")
        browser.select_form(nr=0)
        browser['p_email'] = '<EMAIL>'
        browser['p_nickname'] = 'foobar'
        browser['p_pw'] = ''
        browser['p_pw2'] = ''
        browser.submit()

        expected_response = "Account created"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                      (expected_response, login_response_body))


        browser = Browser()
        browser.open(sweburl + "/youraccount/register")
        browser.select_form(nr=0)
        browser['p_email'] = '<EMAIL>'
        browser['p_nickname'] = 'foobar2'
        browser['p_pw'] = ''
        browser['p_pw2'] = ''
        browser.submit()

        expected_response = "Registration failure"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                      (expected_response, login_response_body))

        browser = Browser()
        browser.open(sweburl + "/youraccount/register")
        browser.select_form(nr=0)
        browser['p_email'] = '<EMAIL>'
        browser['p_nickname'] = 'foobar2'
        browser['p_pw'] = ''
        browser['p_pw2'] = ''
        browser.submit()

        expected_response = "Registration failure"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                      (expected_response, login_response_body))

    def test_select_records_per_group(self):
        """webuser - test of user preferences setting"""

        # logging in as admin
        browser = Browser()
        browser.open(sweburl + "/youraccount/login")
        browser.select_form(nr=0)
        browser['p_un'] = 'admin'
        browser['p_pw'] = ''
        browser.submit()

        expected_response = "You are logged in as admin"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \<commit_msg>Changed test account "<EMAIL>" to a domain under our maintenance ("<EMAIL>") so that we won't bother anyone with test registration emails eventually.<commit_after># -*- coding: utf-8 -*-
##
## $Id$
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

# pylint: disable-msg=E1102

"""WebSession Regression Test Suite."""

__revision__ = \
    "$Id$"

import unittest

from mechanize import Browser

from invenio.dbquery import run_sql
from invenio.config import sweburl, adminemail
from invenio.testutils import make_test_suite, warn_user_about_tests_and_run, \
                              test_web_page_content, merge_error_messages

class WebSessionYourSettingsTest(unittest.TestCase):
    """Check WebSession web pages whether they are up or not."""

    def tearDown(self):
        run_sql('DELETE FROM user WHERE email="<EMAIL>"')
        run_sql('DELETE FROM user WHERE email="<EMAIL>"')

    def test_password_setting(self):
        """webuser - check password settings"""
        browser = Browser()
        browser.open(sweburl + "/youraccount/login")
        browser.select_form(nr=0)
        browser['p_un'] = 'admin'
        browser['p_pw'] = ''
        browser.submit()

        expected_response = "You are logged in as admin"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                      (expected_response, login_response_body))

        # Going to set new password from "" to "<PASSWORD>"
        browser.open(sweburl + "/youraccount/edit")
        browser.select_form(name="edit_password")
        browser['old_password'] = ""
        browser['password'] = "<PASSWORD>"
        browser['password2'] = "<PASSWORD>"
        browser.submit()
        expected_response = "Password successfully edited"
        change_password_body = browser.response().read()
        try:
            change_password_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                    (expected_response, change_password_body))

        # Going to set a wrong old password
        browser.open(sweburl + "/youraccount/edit")
        browser.select_form(name="edit_password")
        browser['old_password'] = "<PASSWORD>"
        browser['password'] = "<PASSWORD>"
        browser['password2'] = "<PASSWORD>"
        browser.submit()
        expected_response = "Wrong old password inserted"
        change_password_body = browser.response().read()
        try:
            change_password_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                    (expected_response, change_password_body))

        # Going to put different new passwords
        browser.open(sweburl + "/youraccount/edit")
        browser.select_form(name="edit_password")
        browser['old_password'] = "<PASSWORD>"
        browser['password'] = "<PASSWORD>"
        browser['password2'] = "<PASSWORD>"
        browser.submit()
        expected_response = "Both passwords must match"
        change_password_body = browser.response().read()
        try:
            change_password_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                    (expected_response, change_password_body))

        # Reset the situation
        browser.open(sweburl + "/youraccount/edit")
        browser.select_form(name="edit_password")
        browser['old_password'] = "<PASSWORD>"
        browser['password'] = ""
        browser['password2'] = ""
        browser.submit()
        expected_response = "Password successfully edited"
        change_password_body = browser.response().read()
        try:
            change_password_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                    (expected_response, change_password_body))

    def test_email_caseless(self):
        """webuser - check email caseless"""
        browser = Browser()
        browser.open(sweburl + "/youraccount/register")
        browser.select_form(nr=0)
        browser['p_email'] = '<EMAIL>'
        browser['p_nickname'] = 'foobar'
        browser['p_pw'] = ''
        browser['p_pw2'] = ''
        browser.submit()

        expected_response = "Account created"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                      (expected_response, login_response_body))


        browser = Browser()
        browser.open(sweburl + "/youraccount/register")
        browser.select_form(nr=0)
        browser['p_email'] = '<EMAIL>'
        browser['p_nickname'] = 'foobar2'
        browser['p_pw'] = ''
        browser['p_pw2'] = ''
        browser.submit()

        expected_response = "Registration failure"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                      (expected_response, login_response_body))

        browser = Browser()
        browser.open(sweburl + "/youraccount/register")
        browser.select_form(nr=0)
        browser['p_email'] = '<EMAIL>'
        browser['p_nickname'] = 'foobar2'
        browser['p_pw'] = ''
        browser['p_pw2'] = ''
        browser.submit()

        expected_response = "Registration failure"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
                      (expected_response, login_response_body))

    def test_select_records_per_group(self):
        """webuser - test of user preferences setting"""

        # logging in as admin
        browser = Browser()
        browser.open(sweburl + "/youraccount/login")
        browser.select_form(nr=0)
        browser['p_un'] = 'admin'
        browser['p_pw'] = ''
        browser.submit()

        expected_response = "You are logged in as admin"
        login_response_body = browser.response().read()
        try:
            login_response_body.index(expected_response)
        except ValueError:
            self.fail("Expected to see %s, got %s." % \
{'fraction_non_alphanumeric': 0.11356728378004974, 'fraction_numerical': 0.00801326333241227, 'mean_word_length': 2.5129822858529485, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6251520', 'n_tokens_mistral': 4015, 'n_tokens_neox': 3881, 'n_words': 1003}