oct.core package

oct.core.exceptions module

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
  • use_cookies – default to True, set to False if you don’t want cookies with browser object
auth(auth_url, data, use_form=True, **kwargs)

Authenticate yourself in the website with the provided data

Data must have this form :

data {
‘login_field_name’: ‘login’, ‘password_filed_name’: ‘password’

}

Parameters:
  • auth_url (str) – the url of the page for authentication
  • form_name (str) – the name attribute of the form
  • form_id (str) – the id attribute of the form
  • form_class (str) – the class attribute of 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

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:
  • form_name (str) – the name attribute of the form
  • form_id (str) – the id attribute of the form
  • form_class (str) – the class attribute of the form
  • nr (int) – the position of the form inside the page
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

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

Will access the first link found with the selector

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)

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

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
Returns:

None

history

Return the actual history

Returns:the _history property
Return type:list
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

Returns:Response object after the submit