Left: | ||
Right: |
LEFT | RIGHT |
---|---|
(no file at all) | |
1 # This file is part of trytond_backend_gis. The COPYRIGHT file at the top | |
ced
2017/09/20 17:28:20
wrong name
| |
2 # level of this repository contains the full copyright notices and license | |
3 # terms. | |
4 import unittest | |
5 from sql import Null | |
6 | |
7 from trytond.pool import Pool | |
8 from trytond.tests.test_tryton import activate_module, with_transaction | |
9 | |
10 | |
11 class TestGeographicFields(unittest.TestCase): | |
12 | |
13 @classmethod | |
14 def setUpClass(cls): | |
15 activate_module('tests') | |
16 | |
17 @with_transaction() | |
18 def test_create_save(self): | |
19 "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() | |
21 | |
22 GISPoint = pool.get('test.gis.point') | |
23 point_a = { | |
24 'meta': {'srid': '4326'}, | |
25 'type': 'Point', | |
26 'coordinates': [1.0, 2.0], | |
27 } | |
28 point, = GISPoint.create([{ | |
29 'point': point_a, | |
30 }]) | |
31 self.assertEqual(point.point, point_a) | |
32 | |
33 point_b = { | |
34 'meta': {'srid': '4326'}, | |
35 'type': 'Point', | |
36 'coordinates': [2.0, 1.0], | |
37 } | |
38 point.point = point_b | |
39 point.save() | |
40 | |
41 reload_point = GISPoint(point.id) | |
42 self.assertEqual(reload_point.point, point_b) | |
43 | |
44 point.point = Null | |
45 point.save() | |
46 | |
47 reload_point = GISPoint(point.id) | |
48 self.assertIsNone(reload_point.point) | |
49 | |
50 @with_transaction() | |
51 def test_search(self): | |
52 "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() | |
54 | |
55 GISPoint = pool.get('test.gis.point') | |
56 point_a = { | |
57 'meta': {'srid': '4326'}, | |
58 'type': 'Point', | |
59 'coordinates': [1.0, 2.0], | |
60 } | |
61 point_b = { | |
62 'meta': {'srid': '4326'}, | |
63 'type': 'Point', | |
64 'coordinates': [2.0, 1.0], | |
65 } | |
66 GISPoint.create([{ | |
67 'point': point_a, | |
68 }, { | |
69 'point': point_a, | |
70 }, { | |
71 'point': point_b, | |
72 }, { | |
73 }]) | |
74 | |
75 points = GISPoint.search([ | |
76 ('point', '=', point_a), | |
77 ]) | |
78 self.assertEqual(len(points), 2) | |
79 for point in points: | |
80 self.assertEqual(point.point, point_a) | |
81 | |
82 points = GISPoint.search([ | |
83 ('point', '!=', point_a), | |
84 ]) | |
85 # 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) | |
87 self.assertNotEqual(points[0].point, point_a) | |
88 | |
89 points = GISPoint.search([ | |
90 ('point', '=', Null), | |
91 ]) | |
92 self.assertEqual(len(points), 1) | |
93 self.assertIsNone(points[0].point) | |
94 | |
95 points = GISPoint.search([ | |
96 ('point', '!=', Null), | |
97 ]) | |
98 self.assertEqual(len(points), 3) | |
99 for point in points: | |
100 self.assertIsNotNone(point.point) | |
101 | |
102 | |
103 def suite(): | |
104 suite_ = unittest.TestSuite() | |
105 suite_.addTests(unittest.TestLoader().loadTestsFromTestCase( | |
106 TestGeographicFields)) | |
107 return suite_ | |
LEFT | RIGHT |