Пример #1
0
    def cmfCreateNews(self, parent_url):
        # return the doc_url
        lipsum = Lipsum()
        doc_id = lipsum.getUniqWord().lower()
        params = [["type_name", "News Item"], ["id", doc_id], ["add", "Add"]]
        self.post("%s/folder_factories" % parent_url,
                  params,
                  description="Create an empty news")
        params = [["allow_discussion", "default"],
                  ["title", lipsum.getSubject()],
                  ["description:text",
                   lipsum.getParagraph()], ["subject:lines",
                                            lipsum.getWord()],
                  ["format", "text/plain"],
                  ["change_and_view", "Change and View"]]
        doc_url = "%s/%s" % (parent_url, doc_id)
        self.post("%s/metadata_edit_form" % doc_url,
                  params,
                  description="Set metadata")
        self.assert_('Metadata changed.' in self.getBody())

        params = [["text_format", "plain"],
                  ["description:text",
                   lipsum.getParagraph()], ["text:text",
                                            lipsum.getMessage()],
                  ["change_and_view", "Change and View"]]
        self.post("%s/newsitem_edit_form" % doc_url,
                  params,
                  description="Set news content")
        self.assert_('News Item changed.' in self.getBody())
        return doc_url
Пример #2
0
    def cmfCreateNews(self, parent_url):
        # return the doc_url
        lipsum = Lipsum()
        doc_id = lipsum.getUniqWord().lower()
        params = [["type_name", "News Item"],
                  ["id", doc_id],
                  ["add", "Add"]]
        self.post("%s/folder_factories" % parent_url, params,
                  description="Create an empty news")
        params = [["allow_discussion", "default"],
                  ["title", lipsum.getSubject()],
                  ["description:text", lipsum.getParagraph()],
                  ["subject:lines", lipsum.getWord()],
                  ["format", "text/plain"],
                  ["change_and_view", "Change and View"]]
        doc_url = "%s/%s" % (parent_url, doc_id)
        self.post("%s/metadata_edit_form" % doc_url, params,
                  description="Set metadata")
        self.assert_('Metadata changed.' in self.getBody())

        params = [["text_format", "plain"],
                  ["description:text", lipsum.getParagraph()],
                  ["text:text", lipsum.getMessage()],
                  ["change_and_view", "Change and View"]]
        self.post("%s/newsitem_edit_form" % doc_url, params,
                  description="Set news content")
        self.assert_('News Item changed.' in self.getBody())
        return doc_url
class VideoGranulateBench(FunkLoadTestCase):
    """This test use a configuration file Simple.conf."""

    def __init__(self, *args, **kwargs):
        FunkLoadTestCase.__init__(self, *args, **kwargs)
        """Setting up the benchmark cycle."""
        self.server_url = self.conf_get('main', 'url')
        self.sam = Restfulie.at('http://localhost:8888/').auth('test', 'test').as_('application/json')
        self.lipsum = Lipsum()
        self.uid_list = []
        self.video_file = b64encode(open(join(FOLDER_PATH, 'input', 'working_google.flv')).read())

    def test_granulate(self):
        server_url = self.server_url
        self.setBasicAuth('test', 'test')

        # The description should be set in the configuration file
        filename = self.lipsum.getUniqWord() + ".flv"

        body = dumps({'video': self.video_file, 'filename':filename})

        # begin of test ---------------------------------------------
        self.post(server_url, description='Send many videos with 5mb each.',
                  params=Data('application/json', body))
        response = loads(self.getBody())
        self.uid_list.extend(response.values())
        # end of test -----------------------------------------------

    def tearDown(self):
        for uid in self.uid_list:
            self.sam.delete(key=uid)
Пример #4
0
class Hipaa(FunkLoadTestCase):
    """This test use a configuration file Conf.conf."""
    def setUp(self):
        """Setting up test."""
        self.server_url = self.conf_get('main', 'url')
        self.lipsum = Lipsum()

    def login_as(self, username, password):
        # The description should be set in the configuration file
        server_url = self.server_url

        self.get(server_url + "/", description="Get /")
        reply = self.get(server_url + "/index", description="Get index")

        csrftoken = extract_token(self.getBody(),
                                  "name='csrfmiddlewaretoken' value='", "' />")
        self.post(server_url + "/accounts/login/?next=/",
                  params=[['csrfmiddlewaretoken', csrftoken],
                          ['redirect_to', '/index'], ['username', username],
                          ['password', password]],
                  description="Post /accounts/login/")

    def logout(self):
        self.get(self.server_url + "/accounts/logout/",
                 description="Get /accounts/logout/")

    def test_simple(self):
        # The description should be set in the configuration file
        server_url = self.server_url
        # begin of test ---------------------------------------------
        nb_time = self.conf_getInt('test_simple', 'nb_time')
        for i in range(nb_time):
            self.get(server_url, description='Get url')
        # end of test -----------------------------------------------

    def test_login(self):
        page = "/index"
        self.login_as("admin", "admin")
        reply = self.get(self.server_url + page, description="Get index")
        self.logout()
        """
        self.login_as("admin", "admin")
        self.logout()
        """

    def test_register(self):
        username = self.lipsum.getUniqWord()
        password = self.lipsum.getWord()
        name = self.lipsum.getWord() + " " + self.lipsum.getWord()
        email = self.lipsum.getWord() + "@example.org"

        server_url = self.server_url
        # self.get(server_url + "/register", description='Get url')

        csrftoken = extract_token(self.getBody(),
                                  "name='csrfmiddlewaretoken' value='", "' />")
        self.post(server_url + "/register",
                  params=[['csrfmiddlewaretoken', csrftoken],
                          ['username', username], ['password1', password],
                          ['password2', password], ['name', name],
                          ['email', email], ['profiletype', '1']],
                  description="Post /register")

    def test_credential(self):
        credential_host = self.conf_get('credential', 'host')
        credential_port = self.conf_getInt('credential', 'port')
        login, pwd = xmlrpc_get_credential(credential_host, credential_port,
                                           "group1")
        self.login_as(login, pwd)
        self.logout()

    def test_random_register(self):
        self.logout()

        username = self.lipsum.getUniqWord()
        password = self.lipsum.getUniqWord()

        server_url = self.server_url
        # self.get(server_url + "/register", description='Get url')

        csrftoken = extract_token(self.getBody(),
                                  "name='csrfmiddlewaretoken' value='", "' />")
        self.post(server_url + "/register",
                  params=[['csrfmiddlewaretoken', csrftoken],
                          ['username', username], ['password1', password],
                          ['password2', password], ['name', 'New User'],
                          ['email', '*****@*****.**'],
                          ['profiletype', '1']],
                  description="Post /register")

        # TODO: Check page after logging in.
        self.logout()
        self.login_as(username, password)
        self.logout()
Пример #5
0
class Hipaa(FunkLoadTestCase):
    """This test use a configuration file Conf.conf."""

    def setUp(self):
        """Setting up test."""
        self.server_url = self.conf_get('main', 'url')
        self.lipsum = Lipsum()

    def login_as(self, username, password, pageURL="/index", descr="Get index"):
        # The description should be set in the configuration file
        server_url = self.server_url

        reply = self.get(server_url + "/index",
            description="Get index")

        csrftoken = extract_token(self.getBody(), "name='csrfmiddlewaretoken' value='", "' />")
        self.post(server_url + "/accounts/login/?next=" + pageURL,
            params=[['csrfmiddlewaretoken', csrftoken],
            ['redirect_to', pageURL],
            ['username', username],
            ['password', password]],
            description="Post /accounts/login/")

    def logout(self):
        self.get(self.server_url + "/accounts/logout/",
                    description="Get /accounts/logout/")

    def test_simple(self):
        # The description should be set in the configuration file
        server_url = self.server_url
        # begin of test ---------------------------------------------
        nb_time = self.conf_getInt('test_simple', 'nb_time')
        for i in range(nb_time):
            self.get(server_url, description='Get url')
        # end of test -----------------------------------------------

    def test_login(self):
        page="/index"
        self.login_as("admin", "admin")
        reply = self.get(self.server_url + page, description="Get index")
        self.logout()

    def test_register(self):
        self.logout()

        num_users = self.conf_getInt('test_register', 'num_users')
        for i in range(num_users):
            username = self.lipsum.getUniqWord()
            password = self.lipsum.getWord()
            name = self.lipsum.getWord() + " " + self.lipsum.getWord()
            email = self.lipsum.getWord() + "@example.org"

            server_url = self.server_url

            csrftoken = extract_token(self.getBody(), "name='csrfmiddlewaretoken' value='", "' />")
            self.post(server_url + "/register",
                params=[ ['csrfmiddlewaretoken', csrftoken],
                ['username', username],
                ['password1', password],
                ['password2', password],
                ['name', name],
                ['email', email],
                ['profiletype', '1']],
                description="Post /register")

            self.assert_("index" in self.getLastUrl(), "Error in registration")
            self.logout()

    def test_credential(self):
        credential_host = self.conf_get('credential', 'host')
        credential_port = self.conf_getInt('credential', 'port')
        login, pwd = xmlrpc_get_credential(credential_host, credential_port
            , "group1")
        self.login_as(login, pwd)
        self.logout()

    def test_show_all_users(self):
        page = "/users"
        self.login_as("admin", "admin", page, "Get users")
        self.assert_(page == self.getLastUrl(), "Error in login")
        reply = self.get(self.server_url + page, description="Get users")
        self.logout()
Пример #6
0
class ConfRegistration(FunkLoadTestCase):
    """This test use a configuration file Conf.conf."""
    def setUp(self):
        """Setting up test."""
        self.server_url = self.conf_get('main', 'url')

        credential_host = self.conf_get('credential', 'host')
        credential_port = self.conf_getInt('credential', 'port')
        self.username, self.pwd = xmlrpc_get_credential(
            credential_host, credential_port, "group1")

        self.lipsum = Lipsum()

    def tearDown(self):
        self.logout()

    def login(self, page="/index"):
        # The description should be set in the configuration file
        server_url = self.server_url

        reply = self.get(server_url + page, description="Get page")

        csrftoken = extract_token(self.getBody(),
                                  "name='csrfmiddlewaretoken' value='", "' />")
        self.post(server_url + "/accounts/login/?next=" + page,
                  params=[['csrfmiddlewaretoken', csrftoken],
                          ['redirect_to', page], ['username', self.username],
                          ['password', self.pwd]],
                  description="Post /accounts/login/")

    def logout(self):
        self.get(self.server_url + "/accounts/logout/",
                 description="Get /accounts/logout/")

    def test_simple(self):
        # The description should be set in the configuration file
        server_url = self.server_url
        # begin of test ---------------------------------------------
        nb_time = self.conf_getInt('test_simple', 'nb_time')
        for i in range(nb_time):
            self.get(server_url, description='Get url')
        # end of test -----------------------------------------------

    def test_register(self):
        self.logout()

        num_users = self.conf_getInt('test_register', 'num_users')
        for i in range(num_users):
            username = self.lipsum.getUniqWord()
            password = self.lipsum.getWord()
            name = self.lipsum.getWord() + " " + self.lipsum.getWord()
            email = self.lipsum.getWord() + "@example.org"

            server_url = self.server_url

            csrftoken = extract_token(self.getBody(),
                                      "name='csrfmiddlewaretoken' value='",
                                      "' />")
            self.post(server_url + "/register",
                      params=[['csrfmiddlewaretoken', csrftoken],
                              ['username', username], ['password1', password],
                              ['password2', password], ['name', name],
                              ['email', email], ['affiliation', 'MIT']],
                      description="Post /register")

            self.assert_("index" in self.getLastUrl(), "Error in registration")
            self.logout()

    def test_show_all_users(self):
        """
        To show all users n times:
            fl-run-test test_ConfRegistration.py \
            ConfRegistration.test_show_all_users -l 2 -n 20
        """
        page = "/users"
        self.login(page)

        reply = self.get(self.server_url + page, description="Get users")

        self.assert_(page == self.getLastUrl(), "Error in login")
        self.logout()

    def test_view_profile(self):
        page = "/accounts/profile/"
        self.login(page)
        self.assert_(page == self.getLastUrl(), "Error in login")
        reply = self.get(self.server_url + page, description="Get profile")
        self.logout()
class SeamBooking(FunkLoadTestCase):
    """Simple test to register a new user and book an hotel.

    This test uses the configuration file SeamBooking.conf.
    """

    jsf_tag_tree = '<input type="hidden" name="jsf_tree_64" id="jsf_tree_64" value="'
    jsf_tag_state = '<input type="hidden" name="jsf_state_64" id="jsf_state_64" value="'

    hotel_names = ["Tower", "Ritz", "Sea", "Hotel"]
    nb_letters = 3        # number of letter to type when searching an hotel
    password = "******" # password used for users

    def jsfParams(self, params):
        """Helper to extarct jsf states from the last page and add them to the params."""
        html = self.getBody()
        tag = self.jsf_tag_tree
        start = html.find(tag) + len(tag)
        end = html.find('"', start)
        if start < 0 or end < 0:
            raise ValueError('No Jsf STATE TREE found in the previous page.')
        state = html[start:end]
        params.insert(0, ["jsf_tree_64", state])
        tag = self.jsf_tag_state
        start = html.find(tag) + len(tag)
        end = html.find('"', start)
        if start < 0 or end < 0:
            raise ValueError('No Jsf STATE STATE found in the previous page.')
        state = html[start:end]
        params.insert(1, ["jsf_state_64", state])
        return params


    def setUp(self):
        """Setting up test."""
        self.logd("setUp")
        self.server_url = self.conf_get('main', 'url')
        self.lipsum = Lipsum()


    def test_seam_booking(self):
        # The description should be set in the configuration file
        server_url = self.server_url

        self.get(server_url + "/seam-booking/home.seam",
            description="Booking home page")
        register_link = self.listHref(content_pattern="Register New User")
        self.assert_(len(register_link), "Register link not found")
        register_link = register_link[0]

        self.get(server_url + register_link,
                 description="Register new User")
        self.assert_("register_SUBMIT" in self.getBody(),
                     "Failing to view Registration page.")

        username = self.lipsum.getUniqWord()
        realname = username + " " + self.lipsum.getUniqWord()
        password = self.password

        self.post(server_url + "/seam-booking/register.seam", self.jsfParams(params=[
            ['register:username', username],
            ['register:name', realname],
            ['register:password', password],
            ['register:verify', password],
            ['register:register', 'Register'],
            ['register_SUBMIT', '1'],
            ['register:_link_hidden_', ''],
            ['jsf_viewid', '/register.xhtml']]),
            description="Submit register form")
        self.assert_("Successfully registered as" in self.getBody(),
                     "Failing register new user.")
        params = self.jsfParams(params=[
            ['login:username', username],
            ['login:password', password],
            ['login:login', 'Account Login'],
            ['login_SUBMIT', '1'],
            ['login:_link_hidden_', ''],
            ['jsf_viewid', '/home.xhtml']])
        self.post(server_url + "/seam-booking/home.seam", params,
            description="Submit account login")
        self.assert_(username in self.getBody(),
                     "Failing login new user %s:%s" % (username, password) + str(params))
        self.assert_("No Bookings Found" in self.getBody(),
                     "Weird there should be no booking for new user %s:%s" %
                     (username, password))

        # Simulate ajax search for an hotel by typing nb_letters
        nb_letters = self.nb_letters
        hotel_query = random.choice(self.hotel_names)
        for i in range(1, nb_letters + 1):
            self.post(server_url + "/seam-booking/main.seam", self.jsfParams(params=[
            ['AJAXREQUEST', '_viewRoot'],
            ['main:searchString', hotel_query[:i]],
            ['main:pageSize', '10'],
            ['main_SUBMIT', '1'],
            ['jsf_viewid', '/main.xhtml'],
            ['main:findHotels', 'main:findHotels']]),
            description="Ajax search %i letter" % i)
            self.assert_("View Hotel" in self.getBody(),
                         "No match for search hotel.")

        # Extract the list of link to hotel and choose a random one
        hotel_links = self.listHref(content_pattern="View Hotel")
        self.get(server_url + random.choice(hotel_links),
                 description="View a random hotel in the result list")
        self.assert_("hotel_SUBMIT" in self.getBody())

        self.post(server_url + "/seam-booking/hotel.seam", self.jsfParams(params=[
            ['hotel:bookHotel', 'Book Hotel'],
            ['hotel_SUBMIT', '1'],
            ['hotel:_link_hidden_', ''],
            ['jsf_viewid', '/hotel.xhtml']]),
            description="Book hotel")
        self.assert_("booking_SUBMIT" in self.getBody())

        self.post(server_url + "/seam-booking/book.seam", self.jsfParams(params=[
            ['booking:checkinDate', '11/07/2008'],
            ['booking:checkoutDate', '11/08/2008'],
            ['booking:beds', '1'],
            ['booking:smoking', 'false'],
            ['booking:creditCard', '1234567890123456'],
            ['booking:creditCardName', realname],
            ['booking:creditCardExpiryMonth', '1'],
            ['booking:creditCardExpiryYear', '2009'],
            ['booking:proceed', 'Proceed'],
            ['booking_SUBMIT', '1'],
            ['booking:_link_hidden_', ''],
            ['jsf_viewid', '/book.xhtml']]),
            description="Proceed booking")
        self.assert_("confirm_SUBMIT" in self.getBody())

        self.post(server_url + "/seam-booking/confirm.seam", self.jsfParams(params=[
            ['confirm:confirm', 'Confirm'],
            ['confirm_SUBMIT', '1'],
            ['confirm:_link_hidden_', ''],
            ['jsf_viewid', '/confirm.xhtml']]),
            description="Confirm booking")
        self.assert_("No Bookings Found" not in self.getBody(),
                     "Booking is not taken in account.")

        # Logout
        logout_link = self.listHref(content_pattern="Logout")
        self.assert_(len(logout_link), "Logout link not found")
        logout_link = logout_link[0]
        self.get(server_url + logout_link,
            description="Logout")
        self.assert_("login_SUBMIT" in self.getBody())

        # end of test -----------------------------------------------

    def tearDown(self):
        """Setting up test."""
        self.logd("tearDown.\n")
Пример #8
0
class SeamBooking(FunkLoadTestCase):
    """Simple test to register a new user and book an hotel.

    This test uses the configuration file SeamBooking.conf.
    """

    jsf_tag_tree = '<input type="hidden" name="jsf_tree_64" id="jsf_tree_64" value="'
    jsf_tag_state = '<input type="hidden" name="jsf_state_64" id="jsf_state_64" value="'

    hotel_names = ["Tower", "Ritz", "Sea", "Hotel"]
    nb_letters = 3  # number of letter to type when searching an hotel
    password = "******"  # password used for users

    def jsfParams(self, params):
        """Helper to extarct jsf states from the last page and add them to the params."""
        html = self.getBody()
        tag = self.jsf_tag_tree
        start = html.find(tag) + len(tag)
        end = html.find('"', start)
        if start < 0 or end < 0:
            raise ValueError('No Jsf STATE TREE found in the previous page.')
        state = html[start:end]
        params.insert(0, ["jsf_tree_64", state])
        tag = self.jsf_tag_state
        start = html.find(tag) + len(tag)
        end = html.find('"', start)
        if start < 0 or end < 0:
            raise ValueError('No Jsf STATE STATE found in the previous page.')
        state = html[start:end]
        params.insert(1, ["jsf_state_64", state])
        return params

    def setUp(self):
        """Setting up test."""
        self.logd("setUp")
        self.server_url = self.conf_get('main', 'url')
        self.lipsum = Lipsum()

    def test_seam_booking(self):
        # The description should be set in the configuration file
        server_url = self.server_url

        self.get(server_url + "/seam-booking/home.seam",
                 description="Booking home page")
        register_link = self.listHref(content_pattern="Register New User")
        self.assert_(len(register_link), "Register link not found")
        register_link = register_link[0]

        self.get(server_url + register_link, description="Register new User")
        self.assert_("register_SUBMIT" in self.getBody(),
                     "Failing to view Registration page.")

        username = self.lipsum.getUniqWord()
        realname = username + " " + self.lipsum.getUniqWord()
        password = self.password

        self.post(
            server_url + "/seam-booking/register.seam",
            self.jsfParams(params=[
                ['register:username', username], ['register:name', realname],
                ['register:password', password], ['register:verify', password],
                ['register:register', 'Register'], ['register_SUBMIT', '1'],
                ['register:_link_hidden_', ''],
                ['jsf_viewid', '/register.xhtml']
            ]),
            description="Submit register form")
        self.assert_("Successfully registered as" in self.getBody(),
                     "Failing register new user.")
        params = self.jsfParams(
            params=[['login:username', username], ['login:password', password],
                    ['login:login', 'Account Login'], ['login_SUBMIT', '1'],
                    ['login:_link_hidden_', ''], ['jsf_viewid', '/home.xhtml']
                    ])
        self.post(server_url + "/seam-booking/home.seam",
                  params,
                  description="Submit account login")
        self.assert_(
            username in self.getBody(), "Failing login new user %s:%s" %
            (username, password) + str(params))
        self.assert_(
            "No Bookings Found" in self.getBody(),
            "Weird there should be no booking for new user %s:%s" %
            (username, password))

        # Simulate ajax search for an hotel by typing nb_letters
        nb_letters = self.nb_letters
        hotel_query = random.choice(self.hotel_names)
        for i in range(1, nb_letters + 1):
            self.post(
                server_url + "/seam-booking/main.seam",
                self.jsfParams(
                    params=[['AJAXREQUEST', '_viewRoot'],
                            ['main:searchString', hotel_query[:i]],
                            ['main:pageSize', '10'], ['main_SUBMIT', '1'],
                            ['jsf_viewid', '/main.xhtml'],
                            ['main:findHotels', 'main:findHotels']]),
                description="Ajax search %i letter" % i)
            self.assert_("View Hotel" in self.getBody(),
                         "No match for search hotel.")

        # Extract the list of link to hotel and choose a random one
        hotel_links = self.listHref(content_pattern="View Hotel")
        self.get(server_url + random.choice(hotel_links),
                 description="View a random hotel in the result list")
        self.assert_("hotel_SUBMIT" in self.getBody())

        self.post(
            server_url + "/seam-booking/hotel.seam",
            self.jsfParams(
                params=[['hotel:bookHotel', 'Book Hotel'],
                        ['hotel_SUBMIT', '1'], ['hotel:_link_hidden_', ''],
                        ['jsf_viewid', '/hotel.xhtml']]),
            description="Book hotel")
        self.assert_("booking_SUBMIT" in self.getBody())

        self.post(
            server_url + "/seam-booking/book.seam",
            self.jsfParams(
                params=[['booking:checkinDate', '11/07/2008'],
                        ['booking:checkoutDate', '11/08/2008'],
                        ['booking:beds', '1'], ['booking:smoking', 'false'],
                        ['booking:creditCard', '1234567890123456'],
                        ['booking:creditCardName', realname],
                        ['booking:creditCardExpiryMonth', '1'],
                        ['booking:creditCardExpiryYear', '2009'],
                        ['booking:proceed', 'Proceed'],
                        ['booking_SUBMIT', '1'], ['booking:_link_hidden_', ''],
                        ['jsf_viewid', '/book.xhtml']]),
            description="Proceed booking")
        self.assert_("confirm_SUBMIT" in self.getBody())

        self.post(
            server_url + "/seam-booking/confirm.seam",
            self.jsfParams(
                params=[['confirm:confirm', 'Confirm'],
                        ['confirm_SUBMIT', '1'], ['confirm:_link_hidden_', ''],
                        ['jsf_viewid', '/confirm.xhtml']]),
            description="Confirm booking")
        self.assert_("No Bookings Found" not in self.getBody(),
                     "Booking is not taken in account.")

        # Logout
        logout_link = self.listHref(content_pattern="Logout")
        self.assert_(len(logout_link), "Logout link not found")
        logout_link = logout_link[0]
        self.get(server_url + logout_link, description="Logout")
        self.assert_("login_SUBMIT" in self.getBody())

        # end of test -----------------------------------------------

    def tearDown(self):
        """Setting up test."""
        self.logd("tearDown.\n")
Пример #9
0
class whitelist(FunkLoadTestCase):
    """This test uses whitelist.conf.
    
    Note I am assuming that there are no proxy exclusions (ie all requests are sent through the proxy).
    This is bad if you are using browser exclusion lists to serve your stylesheets off internal servers...
    
    """
    def setUp(self):
        """Setting up whitelist test."""
        self.title = self.conf_get('main', 'title')
        self.logd("Setting up test: %s\n" % self.title)
        self.lipsum = Lipsum()

    def test_viewwebpages(self):

        nb_time = self.conf_getInt('test_viewwebpages', 'nb_time')
        urls = self.conf_getList('test_viewwebpages', 'urls')
        for i in range(nb_time):
            self.logd('Try %i' % i)
            for url in urls:
                response = self.get("http://" + url,
                                    description='Get %s' % url)
                self.assert_(
                    response.body.find("<img") >= 0,
                    "URL: %s returned with no <img> tags.  Probably means the request failed."
                    % url)

    def testGetFormNonHTTP(self):
        """Test we are blocking the blocked domain to avoid returning forms that are
        not requests for renderable HTML - e.g. *.jpg"""

        url_404 = self.conf_get('test_404_for_blocked_nonhtml', 'url_404')
        response = self.get(url_404)
        self.assertEquals(response.code, 404,
                          "Got %s, should have been 404" % response.code)

        response = self.client.get("https://blockedwhitetrash/empty")
        self.failUnlessEqual(response.status_code, 200)

    def test_viewwhitelist(self):
        """This test is pretty CPU intensive as it parses the whole page each time looking for a /table tag (which is at the very end) to make sure we got a complete page.
        Might be a better way to do this...."""

        nb_time = self.conf_getInt('test_viewwhitelist', 'nb_time')
        whitelist_url = self.conf_get('test_viewwhitelist', 'whitelist_url')

        #Add a refresh header to really test the server and proxy caching
        self.addHeader("Cache-Control", "max-age=0")

        response = self.get(self.conf_get('test_viewwhitelist',
                                          'not_whitelist_url'),
                            description='Get whitelist')
        self.assertEquals(
            response.getDOM().getByName('title')[0][0],
            "Whitetrash: *Not* Whitelist Report",
            "Expected 'Whitetrash: *NOT* Whitelist Report' in HTML title'")
        self.assert_(
            response.body.find("</table>"),
            "Page returned with no closing </table>.  We may have got an incomplete table."
        )

        first_timestamp = ""
        for i in range(nb_time):
            self.logd('Try %i' % i)
            #The next step is very slow for large tables, not sure why.  Is fine when using Firefox.
            response = self.get(whitelist_url, description='Get whitelist')
            self.assertEquals(
                response.getDOM().getByName('title')[0][0],
                "Whitetrash Whitelist Report",
                "Expected 'Whitetrash Whitelist Report' in HTML title'")
            #Check page is being cached
            timestamp = response.getDOM().getByName('p')[0][0]
            if not first_timestamp:
                first_timestamp = timestamp
            self.assertEquals(
                timestamp, first_timestamp,
                "Caching check failed.  Page should not have regenerated.  Timestamp should be %s, but got %s"
                % (first_timestamp, timestamp))

    def add_pages(self, protocol="HTTP"):

        num_pages = self.conf_getInt('test_addto%swhitelist' % protocol,
                                     'num_pages')
        prefix = self.conf_get('test_addto%swhitelist' % protocol, 'prefix')
        suffix = self.conf_get('test_addto%swhitelist' % protocol, 'suffix')

        for i in range(num_pages):
            self.addHeader(
                "Accept",
                "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
            )
            self.addHeader("Accept-Language", "en-us,en;q=0.5")
            self.addHeader("Accept-Encoding", "gzip,deflate")
            self.addHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
            self.addHeader("Keep-Alive", "300")
            self.addHeader("Proxy-Connection", "keep-alive")

            page = self.lipsum.getUniqWord(length_min=5, length_max=40)
            self.setHeader("Host", "www.%s.com" % page)

            if protocol == "HTTP":
                url = "http://www." + page + ".com"
            elif protocol == "SSL":
                #Funkload picks up that this is SSL by the https identifier, we don't need to tell it explicitly.
                url = "https://www." + page + ".com"

            self.logd('Requesting %s page %i: %s' % (protocol, i, url))
            response = self.get(url, description='Get %s' % url)
            self.assertEquals(
                response.getDOM().getByName('title')[0][0],
                "Internet Access Request Form",
                "Expected 'Internet Access Request Form' in HTML title'")

            if protocol == "HTTP":
                postparams = [['domain', 'www.' + page + '.com'],
                              [
                                  'comment',
                                  urllib.quote_plus(self.lipsum.getSentence())
                              ], ['url', urllib.quote_plus(url)],
                              ['protocol', protocol]]

                self.logd('Adding %s page %i: %s' % (protocol, i, postparams))
                response = self.post("http://whitetrash/addentry?",
                                     params=postparams,
                                     description='Post params:%s' % postparams)

            elif protocol == "SSL":
                #Emulate the actual process here by submitting user=ssl.
                self.logd('Adding %s page %i' % (protocol, i))
                response = self.post("https://whitetrash/addentry?",
                                     params=None)

            self.assertEquals(response.getDOM().getByName('title')[0][0],
                              "Access Granted",
                              "Expected 'Access Granted' in HTML title'")
            self.assert_(
                response.body.find(urllib.quote_plus(url)) >= 0,
                "URL %s expected but not found in response" %
                urllib.quote_plus(url))
            self.assert_(
                response.body.find(self.user) >= 0,
                "Username %s expected but not found in response" % self.user)

    def test_addtoHTTPwhitelist(self):
        self.add_pages(protocol="HTTP")

    def test_addtoSSLwhitelist(self):
        #self.add_pages(protocol="SSL")
        pass