class UserEvents(Api): """ User related application events definition """ class Meta: """ User events meta definition """ name = 'user' user_created = Event(parameters=( Parameter('uaa_id', int), Parameter('username', str), )) user_deleted = Event(parameters=(Parameter('uaa_id', int), ))
class AuthApi(Api): user_registered = Event(parameters=[Parameter("username", str)]) class Meta: name = "auth" def check_password(self, username: str, password: str): return username == "admin" and password == "secret"
class TestApi(Api): my_event = Event([Parameter("field", bool)]) class Meta: name = "my.test_api" def my_proc(self, field: bool = True) -> str: pass
class DummyApi(Api): my_event = Event([Parameter("field", str)]) class Meta: name = "my.dummy" def my_proc(self, field) -> str: return "value: {}".format(field) def sudden_death(self, n): raise SuddenDeathException() def random_death(self, n, death_probability=0.5): if random() < float(death_probability): raise SuddenDeathException() return n def general_error(self): raise RuntimeError("Oh no, there was some kind of error")
class UserApi(Api): my_event = Event([Parameter("user", User)]) class Meta: name = "my.user_api"
class TestApi(Api): my_event = Event([Parameter("field", bool)]) class Meta: name = "my.test_api"