|
7 | 7 | from frost_sta_client.service.sensorthingsservice import SensorThingsService |
8 | 8 | from frost_sta_client.service.auth_handler import AuthHandler |
9 | 9 |
|
| 10 | +# Run code generation and install model wrappers before any tests start |
| 11 | +def pytest_sessionstart(session): |
| 12 | + # 1) Generate OData datamodel (falls back to metadata.xml if endpoint unavailable) |
| 13 | + try: |
| 14 | + from frost_sta_client.odata_codegen.generator import generate_from_url |
| 15 | + url = os.environ.get('FROST_STA_CLIENT_CODEGEN_URL', 'http://localhost:8080/FROST-Server') |
| 16 | + username = os.environ.get('FROST_STA_CLIENT_CODEGEN_USER') |
| 17 | + password = os.environ.get('FROST_STA_CLIENT_CODEGEN_PASS') |
| 18 | + auth = (username, (password or '')) if username is not None else None |
| 19 | + generate_from_url(url, 'frost_sta_client/generated/odata', 'datamodel', auth=auth) |
| 20 | + except Exception: |
| 21 | + # Non-fatal: generator handles fallback internally |
| 22 | + pass |
| 23 | + |
| 24 | + # 2) Generate model wrappers under frost_sta_client/model so imports like frost_sta_client.model.thing work |
| 25 | + try: |
| 26 | + from frost_sta_client.odata_codegen.install_model import ENTITY_FILE_MAP, ensure_dir as _ensure_dir, write_wrapper as _write_wrapper, write_model_init as _write_model_init |
| 27 | + model_dir = os.path.join('frost_sta_client', 'model') |
| 28 | + _ensure_dir(model_dir) |
| 29 | + from frost_sta_client.model.ext.entity_type import EntityTypes |
| 30 | + entities = [k for k in EntityTypes.keys() if ENTITY_FILE_MAP.get(k)] |
| 31 | + for singular in entities: |
| 32 | + relations = EntityTypes[singular].get('relations_list', []) |
| 33 | + _write_wrapper(model_dir, singular, relations) |
| 34 | + _write_model_init(model_dir, entities) |
| 35 | + except Exception: |
| 36 | + # Non-fatal: other unit tests can still proceed |
| 37 | + pass |
| 38 | + |
10 | 39 | @pytest.fixture(scope='session') |
11 | 40 | def frost_server(): |
12 | 41 | if os.environ.get('FROST_STA_CLIENT_RUN_INTEGRATION') != '1': |
|
0 commit comments