Commit 76384679 authored by Arthur Lutz's avatar Arthur Lutz
Browse files

added test (wip)

parent 5fdeded5e213
from cubicweb.devtools.testlib import CubicWebTC
from logilab.common import date
from datetime import datetime, timedelta
import random
from cubes.awstats.utils import compress_old_hits
#TODO fake schema addition with stats_about
class CompressTest(CubicWebTC):
# def setUp(self):
# super(CompressTest, self).setUp()
# self.schema.add_entity_type(EntityType('Content'))
# self.schema.add_relation_type(RelationType('stats_about'))
# self.schema.add_relation_def(RelationDefinition('Hits', 'stats_about', 'Content'))
def test_compress(self):
req = self.request()
content = req.create_entity('TestContent', title=u'test')
for day in date.date_range(datetime.now()-timedelta(200), datetime.now()):
stp = req.create_entity('StatPeriod', start=day, stop=day+timedelta(1))
hit = req.create_entity('Hits', hit_type=u'normal',
count=random.choice(range(2000)),
period=stp, stats_about=content)
self.assertEqual(len(req.execute('Any X WHERE X is Hits')), 200)
self.assertEqual(len(req.execute('Any P WHERE P is StatPeriod, P start S, P stop E HAVING E-S >= 27')), 0)
compress(req)
#SQLITE bug self.assertEqual(len(req.execute('Any P WHERE P is StatPeriod, P start S, P stop E HAVING E-S >= 27')), 9)
self.assertNotEquals(len(req.execute('Any X WHERE X is Hits')), 200)
if __name__ == '__main__':
from logilab.common.testlib import unittest_main
unittest_main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment