SPB Git forge

spb/resto-ka

Public

Resto·Ka — tous les restaurants du Québec, menus complets et prix réels (famille ·Ka)

52commits 1branches 0releases
11.6 MBsize
maindefault branch
19 days agolast push
Python 69.3% TypeScript 16.7% CSS 7.9% JavaScript 4.7% HTML 1.4%
2.5 KB · 56 lines python
Raw Blame History
1# ==============================================================================2# Author: Simon-Pierre Boucher <contact@spboucher.ai>3# File:   tests/test_siteresto_platforms.py4# Desc:   site-resto, hub de découverte multi-plateformes — détection des5#         widgets GloriaFood (data-glf-*), ChowNow, Square Online et Clover6#         dans le HTML, consignation dans data/<plateforme>-discovered.json7#         avec l'uid du resto porteur (dédup par key).8# ==============================================================================9import json1011import restoka.connectors.siteresto as sr1213HTML = """14<html><body>15<span data-glf-cuid="a1b2c3d4-1111-2222-3333-444455556666"16      data-glf-ruid="f9e8d7c6-9999-8888-7777-666655554444"></span>17<a href="https://direct.chownow.com/order/2717/locations">Commander</a>18<a href="https://mon-resto.square.site/s/order">Menu</a>19<a href="https://www.clover.com/online-ordering/mon-resto-mtl">Clover</a>20</body></html>21"""222324def test_discover_platforms():25    c = sr.SiteRestoConnector()26    ps = {p["name"]: p for p in c._discover_platforms(HTML)}27    assert set(ps) == {"gloriafood", "chownow", "square", "clover"}28    assert ps["gloriafood"]["key"] == "f9e8d7c6-9999-8888-7777-666655554444"29    assert ps["gloriafood"]["cuid"] == "a1b2c3d4-1111-2222-3333-444455556666"30    assert ps["chownow"]["key"] == "2717"31    assert ps["square"]["key"] == "mon-resto.square.site"32    assert ps["clover"]["key"] == "mon-resto-mtl"33    assert c._discover_platforms("<html>rien</html>") == []343536def test_menu_platforms_couvertes_par_connecteurs():37    # les plateformes « bloquantes » ont toutes un connecteur dédié38    assert set(sr._MENU_PLATFORMS) == {"gloriafood", "chownow", "square"}394041def test_record_platform(tmp_path, monkeypatch):42    monkeypatch.setattr(sr, "DATA_DIR", tmp_path)43    c = sr.SiteRestoConnector()44    p = {"name": "gloriafood", "key": "ruid-1", "cuid": "cuid-1"}45    c._record_platform(p, "Chez Test", "cheztest.ca", "osm:123")46    c._record_platform(p, "Chez Test", "cheztest.ca", "osm:123")   # dédup47    c._record_platform({"name": "chownow", "key": "2717"},48                       "Autre", "autre.ca", "osm:456")49    gf = json.loads((tmp_path / "gloriafood-discovered.json").read_text())50    assert len(gf["integrations"]) == 151    integ = gf["integrations"][0]52    assert integ["key"] == "ruid-1" and integ["uid"] == "osm:123"53    assert integ["cuid"] == "cuid-1"54    cn = json.loads((tmp_path / "chownow-discovered.json").read_text())55    assert cn["integrations"][0]["key"] == "2717"56