Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Jun 3, 2024
1 parent d456af3 commit 361b93d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
5 changes: 5 additions & 0 deletions htagweb/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def apps(self):
def session(self):
return dict(Session(self.uid))

def kill(self):
for app in self._apps:
app.kill()
Session(self.uid).clear()

def __str__(self):
return f"{self.uid}"

Expand Down
3 changes: 2 additions & 1 deletion htagweb/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def __init__(self,uid):
self._uid=uid
SharedMemoryDict.__init__(self,name=uid, size=10240)

def _save(self):
def _save(self): # for compatibility, see hrprocess after an interaction
pass


Session = ShmDict
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pytest-asyncio = "^0.21.1"
pytest-cov = "^4.1.0"
httpx = "0.24.0"
gunicorn = "^22.0.0"
beautifulsoup4 = "^4.12.3"

[build-system]
requires = ["poetry-core"]
Expand Down
25 changes: 25 additions & 0 deletions test_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,28 @@ async def test_manage():

finally:
await HrClient.clean()



@pytest.mark.asyncio
async def test_manage_kill_user():
assert manage.users() == []

try:
hr=HrClient("ut2","examples.simple.App")

assert manage.users() == []

htm=await hr.create("//js") # will create fifo/process

ll=manage.users()
assert len(ll) == 1

assert ll[0].uid == "ut2"

ll[0].kill()

assert manage.users() == []

finally:
await HrClient.clean()
34 changes: 34 additions & 0 deletions test_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from htag import Tag
from htagweb import Runner
import sys,json
from starlette.testclient import TestClient

import bs4

def test_runner_ws_mode():

def do_tests(client):
response = client.get('/')

# assert that get bootstrap page
assert response.status_code == 200
assert "<!DOCTYPE html>" in response.text


soup=bs4.BeautifulSoup(response.text,"html.parser")
id=soup.select("button")[-1].get("id")
datas={"id":int(id),"method":"__on__","args":["onclick-"+str(id)],"kargs":{},"event":{}}

with client.websocket_connect('/_/examples.simple.App') as websocket:

#following exchanges will be json <-> json
websocket.send_text( json.dumps(datas) )

dico = json.loads(websocket.receive_text())
assert "update" in dico

app=Runner("examples.simple.App")
with TestClient(app) as client:
do_tests(client)

0 comments on commit 361b93d

Please sign in to comment.