Permalink
Browse files

First try with travis

  • Loading branch information...
1 parent 9564bec commit 865a72dad2524e3aa2554028d33a9edb803b3a22 @nkuttler nkuttler committed Feb 16, 2013
View
@@ -0,0 +1,21 @@
+language: python
+php:
+- 2.7
+env:
+ # Dev test server
+ global:
+ - secure: "mG++xOmt9mj6JpYpdRPZR88ATsoRt7JaQE7osVu5pjiay3EwBIOPN6OToh7Q\nDq7hYpFJBPRTtJCl7NmbeaZcqZdJy6pnQU9C3UoU8OwK+NMv62opb+8gk3k8\nBzp22uK6ZEZazl2Lo5Quilsb3slSrsjG/HpnEYqqeL5yJpIqKB0="
+ - secure: "Ym8QVYhOoPqbERE5p8sw6UYpi6EyOc9DdF8t/ez2iEHPXjOOijxk0GjWAJcM\n7/QnXXGbUjOdCvY7XicF83Reu3EgibwYnGaQa9kLD6wppsWaD9nOKDAYj/ez\nTsCrWVscOwujAhmsCJrrTetJbLwBHKHkARU8Ni+uRP5assX9d+Y="
+ - secure: "KxjYYynxnUYfFZizglKs4IqTkVN3rQEujcwFUF71Vf4BnoFtnIw3sKmTW1e5\npq3VyU9GuxpW63L36uTT401DmkOdtdaEUYSH6Yra1362CGbSXHQwzVyjDwT9\n2q+3zXgHDOn+oaTRrN7z5wiVwzlyMuhCi2H1Tle2TWU+5Oaa8oI="
+ - secure: "d63KPgn5i10RMJOODfGMKKpk9xeqJPUFO9504CQFKgcdGIHEvlHAWQMc7sNe\nvdrARzgi8QpDiu9QQsCezBBUvWfqo+BPSib6LePvKx7wyjXWhj24ukjGeLDG\nGJtETOk3Wd3ucjrX2RLAs5pW5RyP2qui6g+7GfpU0I/UvvC+CXQ="
+script: make test
+notifications:
+ irc:
+ skip_join: true
+ on_success: change
+ on_failure: change
+ channels:
+ - irc.freenode.org##nkuttler
+ email:
+ on_success: never
+ on_failure: change
View
@@ -8,7 +8,7 @@ If you want to work on the tracking code you should have a look at the original
To run the unit tests you need to:
- Create a new Piwik site
-- Create a settings module
+- Configure your environment
- Enable tracker debugging
Creating a new site
@@ -17,17 +17,26 @@ Creating a new site
You want to create a **new site** specifically for running the unit tests as to
not pollute a real site with test data.
-Creating the settings module
+Configuring your environment
----------------------------
-You must create a ``settings`` **module** somewhere in your Python path that
-contains a ``Settings`` class like this:
+The tests assume that the following variables are set in your environment:
-.. autoclass:: piwikapi.tests.settings_sample.Settings
- :members:
+PIWIK_SITE_ID = '<ID of your test site>'
+PIWIK_TRACKING_API_URL = '<Your Piwik tracker API URL>'
+PIWIK_ANALYTICS_API_URL = '<Your Piwik API URL>'
+PIWIK_TOKEN_AUTH = '<Your Piwik auth token>'
+PIWIK_GOAL_ID = None
-If you create the settings module in the test source directory it is also
-ignored by ``git`` for your convenience.
+``PIWIK_TRACKING_API_URL`` must contain the URL to your Piwik install's
+/piwik.php, something like 'http://example.com/piwik.php'.
+``PIWIK_TRACKING_API_URL`` must contain the URL to your Piwik install's root.
+
+The auth token must have admin access for the site defined in
+``PIWIK_SITE_ID``. The ``goal id`` doesn't have to be set, the goal can be
+autogenerated by the tests.
+
+Please let me know if you need a different way of defining those settings.
Enabling tracker debugging
--------------------------
View
@@ -1,14 +0,0 @@
-import unittest
-
-from analytics import AnalyticsClassTestCase
-from analytics import AnalyticsTestCase
-from analytics import AnalyticsLiveTestCase
-from ecommerce import TrackerEcommerceVerifyTestCase
-from goals import GoalsTestCase
-from tracking import TrackerClassTestCase
-from tracking import TrackerVerifyDebugTestCase
-from tracking import TrackerVerifyTestCase
-
-
-if __name__ == '__main__':
- unittest.main()
@@ -15,8 +15,8 @@ def setUp(self):
"""
super(AnalyticsBaseTestCase, self).setUp()
self.a = PiwikAnalytics()
- self.a.set_api_url(self.settings.PIWIK_ANALYTICS_API_URL)
- self.a.set_id_site(self.settings.PIWIK_SITE_ID)
+ self.a.set_api_url(self.settings['PIWIK_ANALYTICS_API_URL'])
+ self.a.set_id_site(self.settings['PIWIK_SITE_ID'])
self.a.set_format('json')
self.a.set_period('day')
self.a.set_date('today')
@@ -53,7 +53,7 @@ def test_get_imagegraph(self):
self.a.set_method('ImageGraph.get')
self.a.set_parameter('apiModule', 'UserCountry')
self.a.set_parameter('apiAction', 'getCountry')
- self.a.set_parameter('token_auth', self.settings.PIWIK_TOKEN_AUTH)
+ self.a.set_parameter('token_auth', self.settings['PIWIK_TOKEN_AUTH'])
r = self.a.send_request()
try:
im = Image.open(StringIO(r))
View
@@ -7,20 +7,6 @@
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
-try:
- import settings
-except ImportError:
- sys.stderr.write("You haven't created the necessary settings module, please check the documentation.")
- if not on_rtd:
- raise
-
-try:
- mysettings = settings.Settings()
-except NameError:
- sys.stderr.write("You haven't created the necessary Settings class, please check the documentation.")
- if not on_rtd:
- raise
-
class PiwikAPITestCase(unittest.TestCase):
"""
@@ -29,7 +15,19 @@ class PiwikAPITestCase(unittest.TestCase):
Provides a fake request, PiwikTracker and PiwikTrackerEcommerce instances.
"""
def setUp(self):
- self.settings = settings.Settings()
+ try:
+ keys = (
+ 'PIWIK_TRACKING_API_URL',
+ 'PIWIK_ANALYTICS_API_URL',
+ 'PIWIK_TOKEN_AUTH',
+ 'PIWIK_SITE_ID',
+ )
+ self.settings = {}
+ for key in keys:
+ self.settings[key] = os.environ.get(key)
+ self.settings['PIWIK_GOAL_ID'] = os.environ.get('PIWIK_GOAL_ID', None)
+ except:
+ raise
def debug(self, value):
"""
@@ -45,11 +45,11 @@ def setUp(self):
super(TrackerEcommerceBaseTestCase, self).setUp()
# Set different IP for each test run
# TODO also randomize referers etc...
- self.pte = PiwikTrackerEcommerce(self.settings.PIWIK_SITE_ID,
+ self.pte = PiwikTrackerEcommerce(self.settings['PIWIK_SITE_ID'],
self.request)
- self.pte.set_api_url(self.settings.PIWIK_TRACKING_API_URL)
+ self.pte.set_api_url(self.settings['PIWIK_TRACKING_API_URL'])
self.pte.set_ip(self.get_random_ip())
- self.pte.set_token_auth(self.settings.PIWIK_TOKEN_AUTH)
+ self.pte.set_token_auth(self.settings['PIWIK_TOKEN_AUTH'])
self.pte.set_custom_variable(
5,
'testsegment',
View
@@ -11,36 +11,36 @@ def setUp(self):
"""
super(GoalsTestCase, self).setUp()
- self.pg = PiwikGoals(self.settings.PIWIK_ANALYTICS_API_URL)
+ self.pg = PiwikGoals(self.settings['PIWIK_ANALYTICS_API_URL'])
self.pg.set_format('json')
- if self.settings.PIWIK_GOAL_ID is None:
+ if self.settings['PIWIK_GOAL_ID'] is None:
# Create a test goal
r = self.pg.add_goal(
- self.settings.PIWIK_SITE_ID,
+ self.settings['PIWIK_SITE_ID'],
'Auto Goal %s' % self.get_unique_string(),
'manually',
'nononono-nevermatchanyting-pattern-this-sucks',
'contains',
- self.settings.PIWIK_TOKEN_AUTH,
+ self.settings['PIWIK_TOKEN_AUTH'],
)
data = json.loads(r)
self.goal_id = int(data['value'])
else:
- self.goal_id = self.settings.PIWIK_GOAL_ID
+ self.goal_id = self.settings['PIWIK_GOAL_ID']
def tearDown(self):
- if self.settings.PIWIK_GOAL_ID is None:
+ if self.settings['PIWIK_GOAL_ID'] is None:
# Delete the test goal
r = self.pg.delete_goal(
- self.settings.PIWIK_SITE_ID,
+ self.settings['PIWIK_SITE_ID'],
self.goal_id,
)
def test_track_goal_conversion(self):
"""
Make sure goal conversions are logged
"""
- #self.pte.set_token_auth(self.settings.PIWIK_TOKEN_AUTH)
+ #self.pte.set_token_auth(self.settings['PIWIK_TOKEN_AUTH'])
r = self.pte.do_track_goal(self.goal_id)
self.assertEqual(
1,
@@ -52,7 +52,7 @@ def test_track_goal_conversion(self):
#for i in (181, ):
# print i,
# print self.pg.delete_goal(
- # self.settings.PIWIK_SITE_ID,
+ # self.settings['PIWIK_SITE_ID'],
# i,
# )
@@ -61,12 +61,12 @@ def test_create_goal(self):
This is superfluous when we create a goal on the fly
"""
r = self.pg.add_goal(
- self.settings.PIWIK_SITE_ID,
+ self.settings['PIWIK_SITE_ID'],
'Auto Goal %s' % self.get_unique_string(),
'manually',
'nononono-nevermatchanyting-pattern-this-sucks',
'contains',
- self.settings.PIWIK_TOKEN_AUTH,
+ self.settings['PIWIK_TOKEN_AUTH'],
)
data = json.loads(r)
goal_id = int(data['value'])
@@ -76,7 +76,7 @@ def test_create_goal(self):
)
r = self.pg.delete_goal(
- self.settings.PIWIK_SITE_ID,
+ self.settings['PIWIK_SITE_ID'],
goal_id,
)
data = json.loads(r)
@@ -1,21 +0,0 @@
-class Settings:
- """
- This class contains settings for the unit tests
- """
- #: The ID of the site you want to send the test tracking requests to
- PIWIK_SITE_ID = 1
-
- #: This must contain the URL to your Piwik install's /piwik.php, something
- #: like 'http://example.com/piwik.php'
- PIWIK_TRACKING_API_URL = '<Your Piwik tracker API URL>'
-
- #: This must contain the URL to your Piwik install's root
- PIWIK_ANALYTICS_API_URL = '<Your Piwik API URL>'
-
- #: The auth token of an admin user for the site defined in PIWIK_SITE_ID
- PIWIK_TOKEN_AUTH = '<Your Piwik auth token>'
-
- #: The ID of the goal that will be used for unit tests.
- #: If set to ``None`` a goal will be created automatically for each goal
- #: test and deleted after the test has completed successfully.
- PIWIK_GOAL_ID = None
View
@@ -39,8 +39,8 @@ def setUp(self):
'HTTPS': '',
}
self.request = FakeRequest(headers)
- self.pt = PiwikTracker(self.settings.PIWIK_SITE_ID, self.request)
- self.pt.set_api_url(self.settings.PIWIK_TRACKING_API_URL)
+ self.pt = PiwikTracker(self.settings['PIWIK_SITE_ID'], self.request)
+ self.pt.set_api_url(self.settings['PIWIK_TRACKING_API_URL'])
self.pt.set_custom_variable(
1,
'testrun',
@@ -280,7 +280,7 @@ def test_get_custom_variable_scope_exception(self):
def test_missing_api_url(self):
try:
- pt = PiwikTracker(self.settings.PIWIK_SITE_ID, self.request)
+ pt = PiwikTracker(self.settings['PIWIK_SITE_ID'], self.request)
pt.do_track_page_view('fake title')
invalid_config = True
except ConfigurationError:
@@ -361,7 +361,7 @@ def test_default_repeat_visits_recognized(self):
)
def test_token_auth_succeeds(self):
- self.pt.set_token_auth(self.settings.PIWIK_TOKEN_AUTH)
+ self.pt.set_token_auth(self.settings['PIWIK_TOKEN_AUTH'])
r = self.pt.do_track_page_view(
self.get_title('test title auth test')
)
@@ -379,7 +379,7 @@ def test_ip_not_changed_after_auth(self):
"""
ip = self.request.META['REMOTE_ADDR']
title = self.get_title('test ip (auth) %s' % ip)
- self.pt.set_token_auth(self.settings.PIWIK_TOKEN_AUTH)
+ self.pt.set_token_auth(self.settings['PIWIK_TOKEN_AUTH'])
r = self.pt.do_track_page_view(title)
self.assertNotRegexpMatches(
@@ -401,7 +401,7 @@ def test_setting_ip_works_for_authed_user_only(self):
"a random error..."
)
- self.pt.set_token_auth(self.settings.PIWIK_TOKEN_AUTH)
+ self.pt.set_token_auth(self.settings['PIWIK_TOKEN_AUTH'])
r = self.pt.do_track_page_view(title)
self.assertRegexpMatches(
r,
@@ -426,7 +426,7 @@ def test_set_visitor_id(self):
id = self.pt.get_random_visitor_id()
self.pt.set_visitor_id(id)
- self.pt.set_token_auth(self.settings.PIWIK_TOKEN_AUTH)
+ self.pt.set_token_auth(self.settings['PIWIK_TOKEN_AUTH'])
r = self.pt.do_track_page_view(self.get_title('visitor id with auth'))
self.assertRegexpMatches(
r,
@@ -452,7 +452,7 @@ def setUp(self):
'testsegment',
self.segment,
)
- self.pt.set_token_auth(self.settings.PIWIK_TOKEN_AUTH) # verify hack
+ self.pt.set_token_auth(self.settings['PIWIK_TOKEN_AUTH']) # verify hack
self.pt.set_ip(self.get_random_ip())
# Set up the analytics query
@@ -468,7 +468,7 @@ def get_v(self, key):
Get a variable from the last visit
"""
try:
- self.a.set_parameter('token_auth', self.settings.PIWIK_TOKEN_AUTH)
+ self.a.set_parameter('token_auth', self.settings['PIWIK_TOKEN_AUTH'])
data = json.loads(self.a.send_request())
data = data[-1]
except IndexError:
@@ -489,7 +489,7 @@ def get_av(self, key):
Get an action variable from the last visit
"""
try:
- self.a.set_parameter('token_auth', self.settings.PIWIK_TOKEN_AUTH)
+ self.a.set_parameter('token_auth', self.settings['PIWIK_TOKEN_AUTH'])
data = json.loads(self.a.send_request())[-1]['actionDetails'][0]
except IndexError:
print "Request apparently not logged!"
@@ -551,7 +551,7 @@ def test_action_link(self):
"""
url = 'http://out.example.com/out/15'
r = self.pt.do_track_action(url, 'link')
- self.a.set_parameter('token_auth', self.settings.PIWIK_TOKEN_AUTH)
+ self.a.set_parameter('token_auth', self.settings['PIWIK_TOKEN_AUTH'])
data = json.loads(self.a.send_request())[0]
self.assertEqual(
url,
View
@@ -582,7 +582,7 @@ def _send_request(self, url):
:raises: ConfigurationError if the API URL was not set
:rtype: str
"""
- if self.api_url == '':
+ if not self.api_url:
raise ConfigurationError('API URL not set')
parsed = urlparse.urlparse(self.api_url)
url = "%s://%s%s?%s" % (parsed.scheme, parsed.netloc, parsed.path, url)

0 comments on commit 865a72d

Please sign in to comment.