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), ))
Esempio n. 2
0
class ProductsApi(Api):
    created = Event(arguments=['name', 'uuid'])
    updated = Event(arguments=['name', 'uuid'])
    deleted = Event(arguments=['uuid'])

    class Meta:
        # The name below defines how this api will be accessed,
        # eg: bus.products.all()
        name = 'products'

    def all(self):
        """Get all products"""

        # The database returns OrderdDict objects, convert them into
        # regular dicts so they can be easily serialised.
        return [dict(product) for product in db['products'].all()]
Esempio n. 3
0
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"
Esempio n. 4
0
class AuthApi(Api):
    user_registered = Event(arguments=[NewType('username', str)])

    class Meta:
        name = 'my_company.auth'

    def check_password(self, username: str, password: str) -> bool:
        return username == 'admin' and password == 'secret'
Esempio n. 5
0
    class TestApi(Api):
        my_event = Event([Parameter("field", bool)])

        class Meta:
            name = "my.test_api"

        def my_proc(self, field: bool = True) -> str:
            pass
Esempio n. 6
0
class AuthApi(Api):
    user_registered = Event(arguments=['username'])

    class Meta:
        name = 'my_company.auth'

    def check_password(self, username, password):
        return username == 'admin' and password == 'secret'
Esempio n. 7
0
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")
Esempio n. 8
0
    class TestApi(Api):
        _my_event = Event(["field"])

        class Meta:
            name = "my.test_api"
Esempio n. 9
0
    class TestApi2(Api):
        my_event_a = Event(["field"])

        class Meta:
            name = "my.test_api2"
Esempio n. 10
0
    class UserApi(Api):
        my_event = Event([Parameter("user", User)])

        class Meta:
            name = "my.user_api"
Esempio n. 11
0
    class TestApi(Api):
        my_event = Event([Parameter("field", bool)])

        class Meta:
            name = "my.test_api"
Esempio n. 12
0
def test_pass_string_as_event_params():
    # Check we cannot accidentally pass a string to Event in the
    # case that we omit a ',' when specifying a parameters tuple
    with pytest.raises(InvalidApiEventConfiguration):
        Event(parameters=("foo"))