|
24 | 24 | google_json_db_get_categories, |
25 | 25 | google_json_db_get_category_data, |
26 | 26 | google_json_db_get_data, |
| 27 | + google_json_db_get_initial_view, |
27 | 28 | google_json_db_get_location_obligatory_fields, |
28 | 29 | google_json_db_get_locations_paginated, |
29 | 30 | google_json_db_get_marker_styles, |
|
38 | 39 | json_db_get_categories, |
39 | 40 | json_db_get_category_data, |
40 | 41 | json_db_get_data, |
| 42 | + json_db_get_initial_view, |
41 | 43 | json_db_get_location_obligatory_fields, |
42 | 44 | json_db_get_locations, |
43 | 45 | json_db_get_report, |
|
57 | 59 | json_file_db_get_categories, |
58 | 60 | json_file_db_get_category_data, |
59 | 61 | json_file_db_get_data, |
| 62 | + json_file_db_get_initial_view, |
60 | 63 | json_file_db_get_location_obligatory_fields, |
61 | 64 | json_file_db_get_locations, |
62 | 65 | json_file_db_get_locations_paginated, |
|
81 | 84 | mongodb_db_get_categories, |
82 | 85 | mongodb_db_get_category_data, |
83 | 86 | mongodb_db_get_data, |
| 87 | + mongodb_db_get_initial_view, |
84 | 88 | mongodb_db_get_location, |
85 | 89 | mongodb_db_get_location_obligatory_fields, |
86 | 90 | mongodb_db_get_locations, |
@@ -340,6 +344,91 @@ def test_json_file_db_get_marker_styles_empty(): |
340 | 344 | assert result == {} |
341 | 345 |
|
342 | 346 |
|
| 347 | +# ------------------------------------------------ |
| 348 | +# get_initial_view |
| 349 | +# |
| 350 | +# Every backend returns the raw config untouched; resolve_initial_view fills the blanks in, |
| 351 | +# so "declared nothing" has to reach it as {} rather than as a backend's own guess at a view. |
| 352 | + |
| 353 | + |
| 354 | +@mock.patch( |
| 355 | + "builtins.open", |
| 356 | + mock.mock_open( |
| 357 | + read_data=json.dumps({"map": {"initial_view": {"center": [53.37, 22.89], "zoom": 8}}}) |
| 358 | + ), |
| 359 | +) |
| 360 | +def test_json_file_db_get_initial_view(): |
| 361 | + db = JsonFile("/fake/path/data.json") |
| 362 | + assert json_file_db_get_initial_view(db) == {"center": [53.37, 22.89], "zoom": 8} |
| 363 | + |
| 364 | + |
| 365 | +@mock.patch("builtins.open", mock.mock_open(read_data=json.dumps({"map": {}}))) |
| 366 | +def test_json_file_db_get_initial_view_empty(): |
| 367 | + db = JsonFile("/fake/path/data.json") |
| 368 | + assert json_file_db_get_initial_view(db) == {} |
| 369 | + |
| 370 | + |
| 371 | +def test_json_db_get_initial_view(): |
| 372 | + db = in_memory_json_db({"initial_view": {"center": [10.0, 20.0], "zoom": 3, "max_zoom": 12}}) |
| 373 | + assert json_db_get_initial_view(db) == {"center": [10.0, 20.0], "zoom": 3, "max_zoom": 12} |
| 374 | + |
| 375 | + |
| 376 | +def test_json_db_get_initial_view_empty(): |
| 377 | + assert json_db_get_initial_view(in_memory_json_db({})) == {} |
| 378 | + |
| 379 | + |
| 380 | +@mock.patch("platzky.db.google_json_db.Client") |
| 381 | +def test_google_json_db_get_initial_view(mock_cli): |
| 382 | + blob = mock_cli.return_value.bucket.return_value.blob.return_value |
| 383 | + blob.download_as_text.return_value = json.dumps( |
| 384 | + {"map": {"initial_view": {"center": [53.37, 22.89], "max_zoom": 17}}} |
| 385 | + ) |
| 386 | + db = GoogleJsonDb("bucket", "blob") |
| 387 | + assert google_json_db_get_initial_view(db) == {"center": [53.37, 22.89], "max_zoom": 17} |
| 388 | + |
| 389 | + |
| 390 | +@mock.patch("platzky.db.google_json_db.Client") |
| 391 | +def test_google_json_db_get_initial_view_empty(mock_cli): |
| 392 | + mock_cli.return_value.bucket.return_value.blob.return_value.download_as_text.return_value = ( |
| 393 | + json.dumps({"map": {}}) |
| 394 | + ) |
| 395 | + db = GoogleJsonDb("bucket", "blob") |
| 396 | + assert google_json_db_get_initial_view(db) == {} |
| 397 | + |
| 398 | + |
| 399 | +@mock.patch("platzky.db.mongodb_db.MongoClient") |
| 400 | +def test_mongodb_db_get_initial_view(mock_client): |
| 401 | + mock_db = mock.Mock() |
| 402 | + mock_client.return_value.__getitem__.return_value = mock_db |
| 403 | + mock_db.config.find_one.return_value = { |
| 404 | + "_id": "map_config", |
| 405 | + "initial_view": {"center": [53.37, 22.89], "zoom": 8}, |
| 406 | + } |
| 407 | + |
| 408 | + db = MongoDB("mongodb://localhost:27017", "test_db") |
| 409 | + assert mongodb_db_get_initial_view(db) == {"center": [53.37, 22.89], "zoom": 8} |
| 410 | + |
| 411 | + |
| 412 | +@mock.patch("platzky.db.mongodb_db.MongoClient") |
| 413 | +def test_mongodb_db_get_initial_view_empty(mock_client): |
| 414 | + mock_db = mock.Mock() |
| 415 | + mock_client.return_value.__getitem__.return_value = mock_db |
| 416 | + mock_db.config.find_one.return_value = {"_id": "map_config"} |
| 417 | + |
| 418 | + db = MongoDB("mongodb://localhost:27017", "test_db") |
| 419 | + assert mongodb_db_get_initial_view(db) == {} |
| 420 | + |
| 421 | + |
| 422 | +@mock.patch("platzky.db.mongodb_db.MongoClient") |
| 423 | +def test_mongodb_db_get_initial_view_no_config(mock_client): |
| 424 | + mock_db = mock.Mock() |
| 425 | + mock_client.return_value.__getitem__.return_value = mock_db |
| 426 | + mock_db.config.find_one.return_value = None |
| 427 | + |
| 428 | + db = MongoDB("mongodb://localhost:27017", "test_db") |
| 429 | + assert mongodb_db_get_initial_view(db) == {} |
| 430 | + |
| 431 | + |
343 | 432 | # Test get_visible_data and get_meta_data for google_json_db |
344 | 433 | @mock.patch("platzky.db.google_json_db.Client") |
345 | 434 | def test_google_json_db_get_visible_data(mock_cli): |
|
0 commit comments