|
1 | 1 | import logging |
| 2 | +import re |
2 | 3 | import time |
3 | 4 |
|
4 | 5 | from django.contrib.auth import get_user_model |
|
18 | 19 | logger = logging.getLogger(__name__) |
19 | 20 |
|
20 | 21 |
|
| 22 | +def normalize_wkt(wkt_string): |
| 23 | + """Normalize WKT string by rounding floating point numbers to 10 decimal places. |
| 24 | +
|
| 25 | + This handles floating point precision differences that occur during |
| 26 | + database storage/retrieval. |
| 27 | + """ |
| 28 | + wkt = re.sub(r'(\d+\.\d+)', lambda m: str(round(float(m.group(1)), 10)), wkt_string) |
| 29 | + # Canonicalize spacing so POLYGON ((.. becomes POLYGON((.. and commas have single spaces |
| 30 | + wkt = re.sub(r'([A-Z]+)\s+\(', r'\1(', wkt) |
| 31 | + wkt = re.sub(r'\(\s+', '(', wkt) |
| 32 | + wkt = re.sub(r'\s+\)', ')', wkt) |
| 33 | + wkt = re.sub(r',\s*', ', ', wkt) |
| 34 | + wkt = re.sub(r'\s+', ' ', wkt) |
| 35 | + return wkt.strip() |
| 36 | + |
| 37 | + |
21 | 38 | class AdminBaseTestCase(TestCase): |
22 | 39 |
|
23 | 40 | def setUp(self): |
@@ -175,7 +192,17 @@ def _create_item(self, collection, with_link=False, extra=None, data=None): |
175 | 192 | elif key.startswith('links-'): |
176 | 193 | continue |
177 | 194 | else: |
178 | | - self.assertEqual(getattr(item, key), value, msg=f"Item field {key} value missmatch") |
| 195 | + if key == 'geometry': |
| 196 | + geom_obj = getattr(item, key) |
| 197 | + actual_wkt = normalize_wkt(str(geom_obj)) |
| 198 | + expected_wkt = normalize_wkt(value) |
| 199 | + self.assertEqual( |
| 200 | + actual_wkt, expected_wkt, msg=f"Item field {key} value missmatch" |
| 201 | + ) |
| 202 | + else: |
| 203 | + self.assertEqual( |
| 204 | + getattr(item, key), value, msg=f"Item field {key} value missmatch" |
| 205 | + ) |
179 | 206 |
|
180 | 207 | return item, data, link |
181 | 208 |
|
|
0 commit comments