Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Remove webtrends #953

Merged
merged 2 commits into from Mar 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 0 additions & 24 deletions apps/dashboards/cron.py

This file was deleted.

40 changes: 0 additions & 40 deletions apps/dashboards/models.py
Expand Up @@ -30,22 +30,6 @@ class StatsIOError(IOError):
"""An error communicating with WebTrends"""


def period_dates():
"""Return when each period begins and ends, relative to now.

Return values are in the format WebTrends likes: "2010m01d30" or
"current_day-7".

"""
# WebTrends' server apparently runs in UTC, FWIW.
yesterday = 'current_day-1' # Start at yesterday so we get a full week of
# data.
return {THIS_WEEK: ('current_day-7',
yesterday),
ALL_TIME: (settings.WEBTRENDS_EPOCH.strftime('%Ym%md%d'),
yesterday)}


class WikiDocumentVisits(ModelBase):
"""Web stats for Knowledge Base Documents"""

Expand Down Expand Up @@ -116,27 +100,3 @@ def _visit_counts(cls, json_data):
'document: %s' % url)
counts[doc.pk] = visits
return counts

@classmethod
def json_for(cls, period):
"""Return the JSON-formatted WebTrends stats for the given period.

Make one attempt to fetch and reload the data. If something fails, it's
the caller's responsibility to retry.

"""
auth_handler = HTTPBasicAuthHandler()
auth_handler.add_password(realm=settings.WEBTRENDS_REALM,
uri=settings.WEBTRENDS_WIKI_REPORT_URL,
user=settings.WEBTRENDS_USER,
passwd=settings.WEBTRENDS_PASSWORD)
opener = build_opener(auth_handler)
start, end = period_dates()[period]
url = (settings.WEBTRENDS_WIKI_REPORT_URL +
'&start_period=%s&end_period=%s' % (start, end))
try:
# TODO: A wrong username or password results in a recursion depth
# error.
return opener.open(url).read()
except IOError, e:
raise StatsIOError(*e.args)
13 changes: 0 additions & 13 deletions apps/dashboards/tests/test_models.py
Expand Up @@ -107,16 +107,3 @@ def test_good_visit_count(self):
'"measures":{"Visits":213817.0,"Views":595329.0,"Average Time '
'Viewed":25.0},"SubRows":null}}}}}'
% ((settings.LANGUAGE_CODE,) * 2)))

@patch_object(settings._wrapped, 'WEBTRENDS_WIKI_REPORT_URL',
'https://localhost:123654/nonexistent')
def test_networking_failure(self):
"""Assert a StatsIOError is thrown when networking fails."""
self.assertRaises(StatsIOError, WikiDocumentVisits.json_for, THIS_WEEK)

# This takes 14 seconds and hits the WebTrends server, for which you might
# not have credentials. If you have credentials and want to test the
# networking, uncomment this.
# def test_networking(self):
# WikiDocumentVisits.reload_period_from_json(
# THIS_WEEK, WikiDocumentVisits.json_for(THIS_WEEK))