Fix to date fetching
[ckanext-ga-report.git] / ckanext / ga_report / tests / test_api.py
blob:a/ckanext/ga_report/tests/test_api.py -> blob:b/ckanext/ga_report/tests/test_api.py
import os import os
import datetime import datetime
from nose.tools import assert_equal from nose.tools import assert_equal
from ckanext.ga_report.download_analytics import DownloadAnalytics from ckanext.ga_report.download_analytics import DownloadAnalytics
from ckanext.ga_report.ga_auth import (init_service, get_profile_id) from ckanext.ga_report.ga_auth import (init_service, get_profile_id)
from ckanext.ga_report.ga_model import init_tables from ckanext.ga_report.ga_model import init_tables
   
class TestAPI: class TestAPI:
   
@classmethod @classmethod
def setup_class(cls): def setup_class(cls):
if not os.path.exists("token.dat") or not os.path.exists("credentials.json"): if not os.path.exists("token.dat") or not os.path.exists("credentials.json"):
print '*' * 60 print '*' * 60
print "Tests may not run without first having run the auth process" print "Tests may not run without first having run the auth process"
print '*' * 60 print '*' * 60
init_tables() init_tables()
   
@classmethod @classmethod
def teardown_class(cls): def teardown_class(cls):
pass pass
   
def test_latest(self): def test_latest(self):
svc = init_service("token.dat", "credentials.json") svc = init_service("token.dat", "credentials.json")
try: try:
downloader = DownloadAnalytics(svc, profile_id=get_profile_id(svc)) downloader = DownloadAnalytics(svc, profile_id=get_profile_id(svc))
downloader.latest() downloader.latest()
except Exception as e: except Exception as e:
assert False, e assert False, e
   
   
def test_since(self): def test_since(self):
svc = init_service("token.dat", "credentials.json") svc = init_service("token.dat", "credentials.json")
downloader = DownloadAnalytics(svc, profile_id=get_profile_id(svc)) downloader = DownloadAnalytics(svc, profile_id=get_profile_id(svc))
try: try:
downloader.since_date(datetime.datetime.now() - datetime.timedelta(days=-30)) downloader.for_date(datetime.datetime.now() - datetime.timedelta(days=-30))
except Exception as e: except Exception as e:
assert False, e assert False, e