118 lines
4.6 KiB
Python
118 lines
4.6 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
import os.path
|
||
|
import shutil
|
||
|
import tempfile
|
||
|
import unittest
|
||
|
|
||
|
from trac.test import EnvironmentStub, Mock
|
||
|
from trac.search.api import *
|
||
|
|
||
|
from tracrendezvous.location.model import ItemLocation, LocationModelProvider
|
||
|
|
||
|
class ItemLocationTestCase(unittest.TestCase):
|
||
|
def setUp(self):
|
||
|
#self.basedir = os.path.realpath(tempfile.mkdtemp())
|
||
|
self.env = EnvironmentStub(default_data=True, enable=['trac.*', 'tracrendezvous.location.*'])
|
||
|
l = 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()
|
||
|
loc2 = ItemLocation(self.env, 0, u"WILA, Langer August", "N", 51, 31, 39.4, "E", 7, 27, 53.8, 51.527611, 7.464922)
|
||
|
loc2.commit()
|
||
|
|
||
|
def test_1_commit(self):
|
||
|
self.env.get_db_cnx().cursor().execute("select name from item_location;").fetchall()
|
||
|
|
||
|
def test_2_fetch_one(self):
|
||
|
loc1 = ItemLocation.fetch_one(self.env, 1)
|
||
|
self.assertEqual(1, loc1.location_id)
|
||
|
self.assertEqual(u"CTDO, Langer August", loc1.name)
|
||
|
self.assertEqual(u"N", loc1.lat_side)
|
||
|
self.assertEqual(51, loc1.lat_deg)
|
||
|
self.assertEqual(31, loc1.lat_min)
|
||
|
self.assertEqual(39.4, loc1.lat_sec)
|
||
|
self.assertEqual("E", loc1.lon_side)
|
||
|
self.assertEqual(7, loc1.lon_deg)
|
||
|
self.assertEqual(27, loc1.lon_min)
|
||
|
self.assertEqual(53.8, loc1.lon_sec)
|
||
|
self.assertEqual(51.527611, loc1.lat)
|
||
|
self.assertEqual(7.464922, loc1.lon)
|
||
|
|
||
|
def test_3_search_one(self):
|
||
|
loc2 = ItemLocation.search_one(self.env, u"WILA")
|
||
|
self.assertEqual(2, loc2.location_id)
|
||
|
self.assertEqual(u"WILA, Langer August", loc2.name)
|
||
|
self.assertEqual(u"N", loc2.lat_side)
|
||
|
self.assertEqual(51, loc2.lat_deg)
|
||
|
self.assertEqual(31, loc2.lat_min)
|
||
|
self.assertEqual(39.4, loc2.lat_sec)
|
||
|
self.assertEqual("E", loc2.lon_side)
|
||
|
self.assertEqual(7, loc2.lon_deg)
|
||
|
self.assertEqual(27, loc2.lon_min)
|
||
|
self.assertEqual(53.8, loc2.lon_sec)
|
||
|
self.assertEqual(51.527611, loc2.lat)
|
||
|
self.assertEqual(7.464922, loc2.lon)
|
||
|
|
||
|
def test_4_fetch_all(self):
|
||
|
locs = ItemLocation.fetch_all(self.env)
|
||
|
self.assertEqual(1, locs[0].location_id)
|
||
|
self.assertEqual(u"CTDO, Langer August", locs[0].name)
|
||
|
self.assertEqual(u"N", locs[0].lat_side)
|
||
|
self.assertEqual(51, locs[0].lat_deg)
|
||
|
self.assertEqual(31, locs[0].lat_min)
|
||
|
self.assertEqual(39.4, locs[0].lat_sec)
|
||
|
self.assertEqual("E", locs[0].lon_side)
|
||
|
self.assertEqual(7, locs[0].lon_deg)
|
||
|
self.assertEqual(27, locs[0].lon_min)
|
||
|
self.assertEqual(53.8, locs[0].lon_sec)
|
||
|
self.assertEqual(51.527611, locs[0].lat)
|
||
|
self.assertEqual(7.464922, locs[0].lon)
|
||
|
self.assertEqual(2, locs[1].location_id)
|
||
|
self.assertEqual(u"WILA, Langer August", locs[1].name)
|
||
|
self.assertEqual(u"N", locs[1].lat_side)
|
||
|
self.assertEqual(51, locs[1].lat_deg)
|
||
|
self.assertEqual(31, locs[1].lat_min)
|
||
|
self.assertEqual(39.4, locs[1].lat_sec)
|
||
|
self.assertEqual("E", locs[1].lon_side)
|
||
|
self.assertEqual(7, locs[1].lon_deg)
|
||
|
self.assertEqual(27, locs[1].lon_min)
|
||
|
self.assertEqual(53.8, locs[1].lon_sec)
|
||
|
self.assertEqual(51.527611, locs[1].lat)
|
||
|
self.assertEqual(7.464922, locs[1].lon)
|
||
|
|
||
|
def test_5_exists(self):
|
||
|
self.assertEqual(True, ItemLocation.exists(self.env, u"WILA, Langer August"))
|
||
|
self.assertEqual(False, ItemLocation.exists(self.env, u"WILA"))
|
||
|
|
||
|
def test_6_update(self):
|
||
|
loc = ItemLocation.fetch_one(self.env, 1)
|
||
|
loc.name = "foo"
|
||
|
loc.lat_side = "Q"
|
||
|
loc.lat_deg = 1
|
||
|
loc.lat_min = 1
|
||
|
loc.lat_sec = 1
|
||
|
loc.lon_side = "Q"
|
||
|
loc.lon_deg = 1
|
||
|
loc.lon_min = 1
|
||
|
loc.lon_sec = 1
|
||
|
loc.update()
|
||
|
self.assertEqual(loc.lat_side , "Q")
|
||
|
self.assertEqual(loc.lat_deg , 1)
|
||
|
self.assertEqual(loc.lat_min , 1)
|
||
|
self.assertEqual(loc.lat_sec , 1)
|
||
|
self.assertEqual(loc.lon_side , "Q")
|
||
|
self.assertEqual(loc.lon_deg , 1)
|
||
|
self.assertEqual(loc.lon_min , 1)
|
||
|
self.assertEqual(loc.lon_sec , 1)
|
||
|
|
||
|
def test_7_delete(self):
|
||
|
ItemLocation.delete(self.env, 1)
|
||
|
self.assertEqual(None, ItemLocation.fetch_one(self.env, 1))
|
||
|
|
||
|
def suite():
|
||
|
suite = unittest.TestSuite()
|
||
|
suite.addTest(unittest.makeSuite(ItemLocationTestCase, 'test'))
|
||
|
return suite
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main(defaultTest='suite')
|