This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import json, os, sqlite3, threading, unittest
|
||||
from unittest.mock import patch
|
||||
from http.client import HTTPConnection
|
||||
from tempfile import TemporaryDirectory
|
||||
from app.main import ORGANIZATION_ID, connect, create_server
|
||||
from app.sources import CsvSource, ManualSource, available_adapters
|
||||
from app.sources import ApprovedDirectorySource, CsvSource, ManualSource, available_adapters
|
||||
|
||||
class SourceAdapterTests(unittest.TestCase):
|
||||
def test_adapter_catalog_exposes_ready_and_gated_sources(self):
|
||||
@@ -31,6 +32,19 @@ class SourceAdapterTests(unittest.TestCase):
|
||||
self.assertFalse(result.valid)
|
||||
self.assertIn('secret', result.errors[0].lower())
|
||||
|
||||
def test_openstreetmap_uses_provider_side_service_tag_query(self):
|
||||
class Response:
|
||||
def read(self, _): return b'{"elements":[{"tags":{"name":"Cape Plumber","craft":"plumber"}}]}'
|
||||
def __enter__(self): return self
|
||||
def __exit__(self, *_): return False
|
||||
config={'provider':'openstreetmap','query':'plumbers','location':'Cape Town','approved':True,'public_access':True,'terms_accepted':True,'rate_limit':1}
|
||||
with patch('app.sources.urlopen',return_value=Response()) as request:
|
||||
page=ApprovedDirectorySource().discover(config)
|
||||
query=request.call_args.args[0].data.decode()
|
||||
self.assertIn('"craft"~"plumber|plumbers",i]',query)
|
||||
self.assertIn('"shop"~"plumber|plumbers",i]',query)
|
||||
self.assertEqual(page.records[0]['name'],'Cape Plumber')
|
||||
|
||||
def test_legacy_source_kind_constraint_is_migrated(self):
|
||||
with TemporaryDirectory() as tmp:
|
||||
path=os.path.join(tmp,'legacy.db')
|
||||
|
||||
Reference in New Issue
Block a user