Test classes reference

The unit tests verify that data sent through the API was received by Piwik, either by parsing the debug output or by querying the analytics API.

Analytics API tests

These are just some very simple tests. The real testing happens in the tracking API tests, where the analytics API is used to verify the submitted data.

class piwikapi.tests.analytics.AnalyticsTestCase(methodName='runTest')

Generic analytics API tests

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_get_imagegraph()

Just a basic test to see if we can get an image

test_remove_parameter()
class piwikapi.tests.analytics.AnalyticsLiveTestCase(methodName='runTest')

Useless for now

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Tracking API tests

class piwikapi.tests.tracking.TrackerBaseTestCase(methodName='runTest')

This sets up a more or less random visitor

In every test run all tests get the same testrun custom variable.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

setUp()

Set up a PiwikTracker instance

get_title(title)

Adds a timestamp to the action title”

Parameters:title (str) – Action
Return type:str
get_random_ip()

Returns an IP out of the test networks, see RFC 5735. Seemed to make sense to use such addresses for unit tests.

Return type:str
get_random(choices)
get_random_ua()

Returns a random user agent string

Only return Desktop UAs as Piwik doesn’t like big resolutions on devices it thinks are mobile.

Return type:string
get_random_language()

Return a random language code

class piwikapi.tests.tracking.TrackerClassTestCase(methodName='runTest')

PiwikTracker tests, without Piwik interaction

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_set_visitor_id()

This is a little sloppy, we should probably create a custom exception

test_set_debug_string_append()
test_incorrect_custom_variables_invalid()
test_set_custom_variables()
test_set_user_agent()
test_set_visitor_id_exception()
test_do_track_action_exception()

Should probably also test that valid parameters pass

test_set_custom_variable_exception()
test_set_custom_variable_scope_exception()
test_get_custom_variable_exception()
test_get_custom_variable_scope_exception()
test_missing_api_url()
test_unknown_set_plugins()
class piwikapi.tests.tracking.TrackerVerifyDebugTestCase(methodName='runTest')

These tests make sure that the tracking info we send is recognized by checking the debug output of Piwik.

TODO: Use the analytics API to verify the tests.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_default_action_title_is_correct()
test_default_user_is_not_authenticated()
test_default_action_url_is_correct()
test_default_ip_is_not_changed()

This test can’t fail, we use IPs from testing networks

test_default_repeat_visits_recognized()
test_token_auth_succeeds()
test_ip_not_changed_after_auth()

I think there was a bug in my earlier code. The IP should not be set or overridden just because we authenticated, Piwik should log the IP of the host that made the tracking request.

test_setting_ip_works_for_authed_user_only()
test_set_visitor_id()
class piwikapi.tests.tracking.TrackerVerifyBaseTestCase(methodName='runTest')

The base class for tests that use the analytics API to verify

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

setUp()

To be able to verify against the analytics API each test gets a random custom variable. Segmentation is then used to query the submitted data.

get_v(key)

Get a variable from the last visit

get_av(key)

Get an action variable from the last visit

class piwikapi.tests.tracking.TrackerVerifyTestCase(methodName='runTest')

Here are test we don’t verify programmatically yet.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_set_visitor_feature_resolution()
test_set_visitor_feature_single_plugin()
test_set_visitor_feature_plugins()

Test out action

test_action_click()

Test download action

test_set_user_agent()

Piwik doesn’t save the UA string but processes it.

class piwikapi.tests.ecommerce.TrackerEcommerceBaseTestCase(methodName='runTest')

Base class for the ecommerce tests

Contains test products.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

products = {'car': {'sku': '2', 'category': ('car category', 'cars'), 'price': 525, 'name': 'Car', 'quantity': 3}, 'book': {'sku': '1', 'category': ('book category', 'books'), 'price': 999, 'name': 'Book', 'quantity': 3}, 'ball': {'sku': '3', 'category': ('ball category', 'balls'), 'price': 739, 'name': 'Ball', 'quantity': 7}}
setUp()

Set up a PiwikTrackerEcommerce instance

get_cv(number)

Get a custom variable from the last visit

class piwikapi.tests.ecommerce.TrackerEcommerceVerifyTestCase(methodName='runTest')

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_ecommerce_view()
test_add_ecommerce_item_do_track_ecommerce_cart_update()

Test add_ecommerce_item() together with do_track_ecommerce_cart_update(). Also make sure that an abandoned cart was logged.

test_track_ecommerce_order()

TODO We could test that each product was added, not only the sums

Plugin tests

class piwikapi.tests.goals.GoalsTestCase(methodName='runTest')

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

setUp()

Create a goal unless one was defined in the settings

tearDown()
test_track_goal_conversion()

Make sure goal conversions are logged

test_create_goal()

This is superfluous when we create a goal on the fly