LEFT | RIGHT |
(no file at all) | |
| 1 # This file is part of trytond_backend_gis. The COPYRIGHT file at the top |
| 2 # level of this repository contains the full copyright notices and license |
| 3 # terms. |
| 4 import os |
| 5 import unittest |
| 6 |
| 7 from dbgis import Point |
| 8 |
| 9 from trytond import backend |
| 10 from trytond.pool import Pool |
| 11 from trytond.transaction import Transaction |
| 12 from trytond.tests.test_tryton import (create_db, activate_module, |
| 13 with_transaction) |
| 14 |
| 15 |
| 16 def setUpModule(): |
| 17 import pkg_resources |
| 18 from trytond.modules import MODULES, EGG_MODULES |
| 19 from trytond_backend_gis.tests.test_gis import register |
| 20 |
| 21 # This is necessary because EGG_MODULES populates the module list returned |
| 22 # by get_module_list |
| 23 entry_points = pkg_resources.iter_entry_points('trytond.test_modules') |
| 24 for test_entry_point in entry_points: |
| 25 if test_entry_point.name == 'test_gis': |
| 26 EGG_MODULES['test_gis'] = test_entry_point |
| 27 break |
| 28 |
| 29 register() |
| 30 MODULES.append('test_gis') |
| 31 |
| 32 |
| 33 class TestGeographicFields: |
| 34 |
| 35 @classmethod |
| 36 def setUpClass(cls): |
| 37 activate_module('test_gis') |
| 38 |
| 39 @with_transaction() |
| 40 def test_point(self): |
| 41 pool = Pool() |
| 42 |
| 43 GISPoint = pool.get('gis.point') |
| 44 point1, = GISPoint.create([{ |
| 45 'point': Point(1, 2, srid=4326), |
| 46 }]) |
| 47 self.assert_(point1) |
| 48 self.assertEqual(point1.point.x, 1) |
| 49 self.assertEqual(point1.point.y, 2) |
| 50 self.assertEqual(point1.point.srid, 4326) |
| 51 |
| 52 |
| 53 @unittest.skipUnless(backend.name() == 'postgis', "requires PostGIS") |
| 54 class PostGISTestCase(TestGeographicFields, unittest.TestCase): |
| 55 "Test PostGIS Geographic Fields" |
| 56 |
| 57 @classmethod |
| 58 def setUpClass(cls): |
| 59 DB_NAME = os.environ['DB_NAME'] |
| 60 create_db(DB_NAME) |
| 61 with Transaction().start(DB_NAME, 1) as transaction: |
| 62 cursor = transaction.connection.cursor() |
| 63 cursor.execute("CREATE EXTENSION postgis") |
| 64 super(PostGISTestCase, cls).setUpClass() |
| 65 |
| 66 |
| 67 def suite(): |
| 68 suite_ = unittest.TestSuite() |
| 69 suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( |
| 70 PostGISTestCase)) |
| 71 return suite_ |
LEFT | RIGHT |