|
| 1 | +"""Small database fixtures for mobile-device endpoint tests.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from datetime import date |
| 6 | + |
| 7 | +from sqlmodel import Session, select |
| 8 | + |
| 9 | +from app.database import engine |
| 10 | +from app.models.brand import Brand |
| 11 | +from app.models.mobile_device import PDA, Tablet, Watch |
| 12 | + |
| 13 | + |
| 14 | +def _brand_id(session: Session, slug: str, name: str, country: str) -> int: |
| 15 | + brand = session.exec(select(Brand).where(Brand.slug == slug)).first() |
| 16 | + if brand is None: |
| 17 | + brand = Brand(slug=slug, name=name, country=country, source_urls=["https://example.com"]) |
| 18 | + session.add(brand) |
| 19 | + session.commit() |
| 20 | + session.refresh(brand) |
| 21 | + assert brand.id is not None |
| 22 | + return brand.id |
| 23 | + |
| 24 | + |
| 25 | +def ensure_mobile_device_fixtures() -> None: |
| 26 | + """Insert compact tablet, watch, and PDA records when the data checkout lacks them.""" |
| 27 | + |
| 28 | + with Session(engine) as session: |
| 29 | + apple_id = _brand_id(session, "apple", "Apple", "US") |
| 30 | + samsung_id = _brand_id(session, "samsung", "Samsung", "KR") |
| 31 | + hp_id = _brand_id(session, "hp", "HP", "US") |
| 32 | + |
| 33 | + tablet = session.exec( |
| 34 | + select(Tablet).where(Tablet.slug == "ipad-pro-11-m4-wifi-8gb-256gb") |
| 35 | + ).first() |
| 36 | + if tablet is None: |
| 37 | + session.add( |
| 38 | + Tablet( |
| 39 | + slug="ipad-pro-11-m4-wifi-8gb-256gb", |
| 40 | + base_model_slug="ipad-pro-11-m4", |
| 41 | + name="Apple iPad Pro 11-inch (M4, Wi-Fi, 256GB)", |
| 42 | + brand_id=apple_id, |
| 43 | + release_date=date(2024, 5, 15), |
| 44 | + msrp_usd=999, |
| 45 | + ram_gb=8, |
| 46 | + storage_options_gb=[256], |
| 47 | + variant={ |
| 48 | + "region": "global", |
| 49 | + "memory": {"ram_gb": 8, "storage_gb": 256}, |
| 50 | + "network": {"cellular": "Wi-Fi", "carrier": "none"}, |
| 51 | + }, |
| 52 | + display={"size_inch": 11.0, "refresh_hz": 120}, |
| 53 | + cameras=[{"type": "wide", "mp": 12}], |
| 54 | + battery_mah=8160, |
| 55 | + weight_g=444, |
| 56 | + os="iPadOS", |
| 57 | + verified=False, |
| 58 | + source_urls=["https://support.apple.com/"], |
| 59 | + ) |
| 60 | + ) |
| 61 | + |
| 62 | + watch = session.exec( |
| 63 | + select(Watch).where(Watch.slug == "galaxy-watch-global-bluetooth-42mm") |
| 64 | + ).first() |
| 65 | + if watch is None: |
| 66 | + session.add( |
| 67 | + Watch( |
| 68 | + slug="galaxy-watch-global-bluetooth-42mm", |
| 69 | + base_model_slug="galaxy-watch", |
| 70 | + name="Samsung Galaxy Watch 42mm Bluetooth", |
| 71 | + brand_id=samsung_id, |
| 72 | + release_date=date(2018, 8, 24), |
| 73 | + msrp_usd=329, |
| 74 | + ram_gb=0.75, |
| 75 | + storage_options_gb=[4], |
| 76 | + variant={"region": "global", "network": {"cellular": "none"}}, |
| 77 | + display={"size_inch": 1.2}, |
| 78 | + cameras=[], |
| 79 | + battery_mah=270, |
| 80 | + weight_g=49, |
| 81 | + os="Tizen", |
| 82 | + verified=False, |
| 83 | + source_urls=["https://www.samsung.com/"], |
| 84 | + ) |
| 85 | + ) |
| 86 | + |
| 87 | + if session.exec(select(PDA).where(PDA.slug == "ipaq-h3600-base")).first() is None: |
| 88 | + session.add( |
| 89 | + PDA( |
| 90 | + slug="ipaq-h3600-base", |
| 91 | + base_model_slug="ipaq-h3600", |
| 92 | + name="HP iPAQ H3600", |
| 93 | + brand_id=hp_id, |
| 94 | + release_date=date(2000, 4, 1), |
| 95 | + ram_gb=0.032, |
| 96 | + storage_options_gb=[], |
| 97 | + variant={"region": "global"}, |
| 98 | + display={"size_inch": 3.8}, |
| 99 | + cameras=[], |
| 100 | + battery_mah=1500, |
| 101 | + weight_g=178, |
| 102 | + os="Pocket PC", |
| 103 | + verified=False, |
| 104 | + source_urls=["https://en.wikipedia.org/wiki/IPAQ"], |
| 105 | + ) |
| 106 | + ) |
| 107 | + |
| 108 | + session.commit() |
0 commit comments