ctdo-trac/TracRendezVous/tracrendezvous/event/tests/model.py

55 lines
2.6 KiB
Python
Raw Permalink Normal View History

2012-03-31 15:45:24 +00:00
# -*- coding: utf-8 -*-
import unittest
from datetime import datetime, timedelta
from trac.util.datefmt import utc, to_timestamp
from trac.test import EnvironmentStub, Mock
from trac.search.api import *
from tracrendezvous.event.model import Event, EventModelProvider
from tracrendezvous.location.model import ItemLocation, LocationModelProvider
class EventTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True, enable=['trac.*', 'tracrendezvous.*'])
l = EventModelProvider(self.env).environment_created()
l2 = LocationModelProvider(self.env).environment_created()
loc1 = ItemLocation(self.env, 0, u"CTDO, Langer August", "N", 51, 31, 39.4, "E", 7, 27, 53.8, 51.527611, 7.464922)
loc1.commit()
self.created = datetime.now(utc)
self.created = self.created.replace(microsecond=0)
self.time_begin = datetime(2009, 3, 1, 17, 30, tzinfo=utc)
self.time_end = datetime(2009, 3, 1, 22, 30, tzinfo=utc)
loc1 = Event(self.env, 0, "name", self.created, self.created, self.time_begin, self.time_end, 1, initial_e_id=0, tags="a b c", attendees="a b c", is_periodic=True, wikipage="foobar")
loc1.commit()
def test_1_commit(self):
self.env.get_db_cnx().cursor().execute("select name from events;").fetchall()
def test_2_fetch_one(self):
event = Event.fetch_one(self.env, 1)
self.assertEqual(1, event.e_id)
self.assertEqual(u"name", event.name)
self.assertEqual(self.created, event.time_created)
self.assertEqual(self.created, event.time_modified)
self.assertEqual(self.time_begin, event.time_begin)
self.assertEqual(self.time_begin, event.time_begin)
self.assertEqual(self.time_end, event.time_end)
self.assertEqual(1, event.location_id)
self.assertEqual(0, event.initial_e_id)
self.assertEqual("a b c", event.tags)
self.assertEqual("a b c", event.attendees)
self.assertEqual(True, event.is_periodic)
self.assertEqual("foobar", event.wikipage)
def test_3_exists(self):
self.assertEqual(True, Event.exists(self.env, 1, self.time_begin, self.time_end))
self.assertEqual(False, Event.exists(self.env, 1, datetime(2009,4,1,17,20,tzinfo=utc), datetime(2009,3,1,17,20,tzinfo=utc)))
self.assertEqual(False, Event.exists(self.env, 1, datetime(2009,3,1,17,20,tzinfo=utc), datetime(2009,4,1,17,20,tzinfo=utc)))
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(EventTestCase, 'test'))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')