Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # This file is part of trytond_backend_gis. The COPYRIGHT file at the top | 1 # This file is part of trytond_gis. The COPYRIGHT file at the top level of |
ced
2017/09/20 17:28:20
wrong name
| |
2 # level of this repository contains the full copyright notices and license | 2 # this repository contains the full copyright notices and license terms. |
3 # terms. | |
4 import unittest | 3 import unittest |
5 from sql import Null | 4 from sql import Null |
6 | 5 |
7 from trytond.pool import Pool | 6 from trytond.pool import Pool |
8 from trytond.tests.test_tryton import activate_module, with_transaction | 7 from trytond.tests.test_tryton import activate_module, with_transaction |
9 | 8 |
10 | 9 |
11 class TestGeographicFields(unittest.TestCase): | 10 class TestGeographicFields(unittest.TestCase): |
12 | 11 |
13 @classmethod | 12 @classmethod |
14 def setUpClass(cls): | 13 def setUpClass(cls): |
15 activate_module('tests') | 14 activate_module('tests') |
16 | 15 |
17 @with_transaction() | 16 @with_transaction() |
18 def test_create_save(self): | 17 def test_create_save(self): |
19 "Testing create/write with GIS types" | 18 "Testing create/write with GIS types" |
ced
2017/09/20 17:28:20
It would be better to have a test for each one.
| |
20 pool = Pool() | 19 pool = Pool() |
21 | 20 |
22 GISPoint = pool.get('test.gis.point') | 21 GISPoint = pool.get('test.gis.point') |
23 point_a = { | 22 point_a = { |
24 'meta': {'srid': '4326'}, | 23 'meta': {'srid': '4326'}, |
25 'type': 'Point', | 24 'type': 'Point', |
26 'coordinates': [1.0, 2.0], | 25 'coordinates': [1.0, 2.0], |
27 } | 26 } |
28 point, = GISPoint.create([{ | 27 point, = GISPoint.create([{ |
29 'point': point_a, | 28 'point': point_a, |
(...skipping 12 matching lines...) Expand all Loading... | |
42 self.assertEqual(reload_point.point, point_b) | 41 self.assertEqual(reload_point.point, point_b) |
43 | 42 |
44 point.point = Null | 43 point.point = Null |
45 point.save() | 44 point.save() |
46 | 45 |
47 reload_point = GISPoint(point.id) | 46 reload_point = GISPoint(point.id) |
48 self.assertIsNone(reload_point.point) | 47 self.assertIsNone(reload_point.point) |
49 | 48 |
50 @with_transaction() | 49 @with_transaction() |
51 def test_search(self): | 50 def test_search(self): |
52 "Testing search with GIS types" | 51 "Testing search with GIS types" |
ced
2017/09/20 17:28:21
I think it is better to have one test per search.
| |
53 pool = Pool() | 52 pool = Pool() |
54 | 53 |
55 GISPoint = pool.get('test.gis.point') | 54 GISPoint = pool.get('test.gis.point') |
56 point_a = { | 55 point_a = { |
57 'meta': {'srid': '4326'}, | 56 'meta': {'srid': '4326'}, |
58 'type': 'Point', | 57 'type': 'Point', |
59 'coordinates': [1.0, 2.0], | 58 'coordinates': [1.0, 2.0], |
60 } | 59 } |
61 point_b = { | 60 point_b = { |
62 'meta': {'srid': '4326'}, | 61 'meta': {'srid': '4326'}, |
(...skipping 12 matching lines...) Expand all Loading... | |
75 points = GISPoint.search([ | 74 points = GISPoint.search([ |
76 ('point', '=', point_a), | 75 ('point', '=', point_a), |
77 ]) | 76 ]) |
78 self.assertEqual(len(points), 2) | 77 self.assertEqual(len(points), 2) |
79 for point in points: | 78 for point in points: |
80 self.assertEqual(point.point, point_a) | 79 self.assertEqual(point.point, point_a) |
81 | 80 |
82 points = GISPoint.search([ | 81 points = GISPoint.search([ |
83 ('point', '!=', point_a), | 82 ('point', '!=', point_a), |
84 ]) | 83 ]) |
85 # For some reasons NULL are not taken into account | 84 # For some reasons NULL are not taken into account |
ced
2017/09/20 17:28:21
It is not some reason, it is because NULL in any o
| |
86 self.assertEqual(len(points), 1) | 85 self.assertEqual(len(points), 1) |
87 self.assertNotEqual(points[0].point, point_a) | 86 self.assertNotEqual(points[0].point, point_a) |
88 | 87 |
89 points = GISPoint.search([ | 88 points = GISPoint.search([ |
90 ('point', '=', Null), | 89 ('point', '=', Null), |
91 ]) | 90 ]) |
92 self.assertEqual(len(points), 1) | 91 self.assertEqual(len(points), 1) |
93 self.assertIsNone(points[0].point) | 92 self.assertIsNone(points[0].point) |
94 | 93 |
95 points = GISPoint.search([ | 94 points = GISPoint.search([ |
96 ('point', '!=', Null), | 95 ('point', '!=', Null), |
97 ]) | 96 ]) |
98 self.assertEqual(len(points), 3) | 97 self.assertEqual(len(points), 3) |
99 for point in points: | 98 for point in points: |
100 self.assertIsNotNone(point.point) | 99 self.assertIsNotNone(point.point) |
101 | 100 |
102 | 101 |
103 def suite(): | 102 def suite(): |
104 suite_ = unittest.TestSuite() | 103 suite_ = unittest.TestSuite() |
105 suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( | 104 suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( |
106 TestGeographicFields)) | 105 TestGeographicFields)) |
107 return suite_ | 106 return suite_ |
LEFT | RIGHT |