def test_app(): app = App("testkey",session="sync") assert app.id == "self" app.read() assert app.id!="self" app.description = "hello worldd" assert app["description"] == "hello worldd" assert app["owner"]["username"]=="test" assert app.owner["username"]=="test"
def test_app_keychange(): # This test has to happen last, because once the app key is changed, # there is no more logging in from other tests. app = App("testkey",session="sync") result = app.update(name="My Test App") assert not "access_token" in result result = app.update(access_token=True) with pytest.raises(HeedyException): app.read() assert result["access_token"]!="testkey" newapp = App(result["access_token"],url=app.session.url) assert newapp.name == "My Test App"
def test_objects(): app = App("testkey") assert len(app.objects())==0 obj = app.objects.create("My Timeseries", type="timeseries", meta={"schema":{"type":"number"}}, tags="myts mydata", key="myts") objs = app.objects() assert len(objs) == 1 assert objs[0] == obj assert objs[0].id==obj.id assert objs[0].meta == obj.meta assert objs[0]["name"] == "My Timeseries" assert objs[0]["type"] == "timeseries" assert obj.name == "My Timeseries" # Reading and Updating properties # Reads the key property from the server assert obj.key == "myts" # Uses the previously read cached data, avoiding a server query assert obj["key"] == "myts" obj.read() assert obj["key"]=="myts" obj.description = "My description" assert obj.description == "My description" obj.update(description="My description2") assert obj["description"] == "My description2" obj["description"] = "My description3" assert obj.description == "My description3" assert obj.meta == {"schema": {"type": "number"}} assert obj.meta() == {"schema": {"type": "number"}} obj.meta.schema = {"type": "string"} assert obj.meta == {"schema": {"type": "string"}} assert obj.meta() == {"schema": {"type": "string"}} obj.meta["schema"] = {"type": "boolean"} assert obj.meta == {"schema": {"type": "boolean"}} del obj.meta.schema assert obj.meta() == {"schema": {}} assert app.objects(key="myts")[0] == obj with pytest.raises(Exception): assert obj["app"]==app with pytest.raises(Exception): assert obj.app == app app.read() assert obj["app"]==app assert obj.app == app obj.delete() assert len(app.objects())==0