oct.core package

oct.core.exceptions module

exception oct.core.exceptions.FormNotFoundException

Bases: exceptions.Exception

Raised in case of FormNotFound with browser

exception oct.core.exceptions.LinkNotFound

Bases: exceptions.Exception

Raised in case of link not found in current html document

exception oct.core.exceptions.NoFormWaiting

Bases: exceptions.Exception

Raised in case of action required form if no form selected

exception oct.core.exceptions.NoUrlOpen

Bases: exceptions.Exception

Raised in case of no url open but requested inside browser class

exception oct.core.exceptions.OctGenericException

Bases: exceptions.Exception

Provide generic exception for reports

oct.core.generic module

class oct.core.generic.GenericTransaction(handle_robots, pathtoini, **kwargs)

Bases: object

Base class for Transaction, this class provides tools for simpler test writing

Parameters:
  • handle_robots (bool) – set if robots are handle or not
  • pathtoini (str) – the path to the ini file
  • threads (int) – number of threads for static files
  • timeout – the timeout in second for static files requests
auth(auth_url, data, use_form=True, **kwargs)

Authenticate yourself in the website with the provided data

Data must be of the form:

{
    'login_field_name': 'login',
    'password_filed_name': 'password'
}
Parameters:
  • auth_url (str) – the url of the page for authentication
  • selector (str) – the css selector for the form
  • nr (int) – the position of the form inside the page
Returns:

the response object from the submission

static csv_to_list(csv_file)

Take a csv file as parameter and read it. Return a list containing all lines

Parameters:csv_file (str) – the csv file to read
Returns:A list containing the lines
Return type:list
fill_form(form_data)

Fill the form selected in self.br with form_data dict

The data dict must be of the form:

{
    'field_name': 'field_value',
    'field2': 'field_value'
}
Parameters:form_data (dict) – dict containing the data
get_form(**kwargs)

This method help you for getting a form in a given response object The form will be set inside the br property of the class

Parameters:
  • selector (str) – the css selector for getting the form
  • nr (int) – the position of the form inside the page, default to 0
Returns:

None

static get_random_csv(csv_list)

Simply return a random element from csv_list param

Parameters:csv_list – a list
Returns:random element from the csv_list
get_statics(response, timer_name, include=None)

Get all static files for given response object. It will exclude all files in the exclude list

Parameters:
  • response (MechanizeResponse) – The response object from browser
  • timer_name (str) – The timer name to increment
  • include (tuple) – The list of statics to exclude
Returns:

None

multi_process_statics()

Multi threading static getter. This function will be call inside a Thread by the get_statics method

Returns:None
open_url(url, data=None)

Open an url with the Browser object

Parameters:
  • url (str) – the url to open
  • data (dict) – the data to pass to url
run()

Run method will be call by multi-mechanize run function You must implement it

run_generic_test(timer_name, url, test_func, *args)

Play the test_func param with *args parameters This function will call the browser on the url param for you You can pass existing or custom functions, but if you want to create custom test function, it must at least take a response object as first parameter

Example of testing function and calling it:

def my_test(response, other_param):
    assert(other_param not in response.html)

# In Transaction run() method
self.run_generic_test('my_timer', url, my_test, other_param)
Parameters:
  • timer_name (str) – the name of the timer
  • url (str) – the url to test
  • test_func (function) – pointer on a testing function
  • args – the parameters of the test function
Returns:

The response object from Mechanize.Browser()

oct.core.browser module

class oct.core.browser.Browser(session=None, base_url='')

Bases: object

This class represent a minimal browser. Build on top of lxml awesome library it let you write script for accessing or testing website with python scripts

Parameters:
  • session – The session object to use. If set to None will use requests.Session
  • base_url – The base url for the website, will append it for every link without a full url
back()

Go to the previous url in the history property

Returns:the Response object
clean_session()

This function is called by the core of multi-mechanize. It cleans the session for avoiding cache or cookies errors, or giving false results based on cache

Returns:None

Will access the first link found with the selector

Raise:
oct.core.exceptions.LinkNotFound
Parameters:
  • selector – a string representing a css selector
  • url_regex – regex for finding the url, can represent the href attribute or the link content
Returns:

Response object

get_form(selector=None, nr=0, at_base=False)

Get the form selected by the selector and / or the nr param

Raise:
  • oct.core.exceptions.FormNotFoundException
  • oct.core.exceptions.NoUrlOpen
Parameters:
  • selector – A css-like selector for finding the form
  • nr – the index of the form, if selector is set to None, it will search on the hole page
  • at_base – must be set to true in case of form action is on the base_url page
Returns:

None

get_select_values()

Get the available values of all select and select multiple fields in form

Returns:a dict containing all values for each fields
history

Return the actual history

Returns:the _history property
Return type:list
static open_in_browser(response)

Provide a simple interface for lxml.html.open_in_browser function. Be careful, use this function only for debug purpose

Parameters:response
Returns:
open_url(url, data=None, back=False, **kwargs)

Open the given url

Parameters:
  • url – The url to access
  • data – Data to send. If data is set, the browser will make a POST request
  • back – tell if we actually accessing a page of the history
Returns:

The Response object from requests call

submit_form()

Submit the form filled with form_data property dict

Raise:
oct.core.exceptions.NoFormWaiting
Returns:Response object after the submit