Exemplo n.º 1
0
class Report:
    """Station reception report."""

    id: s.uuid(description="Identifies the reception report.")
    task_id: s.uuid(description="Identifies the task that reception report is for.")
    station_id: s.uuid(
        description="Identifies the station filing the reception report."
    )
    time: s.datetime(description="Date and time that the signal was received.")
    frequency: s.int(description="Frequency of received signal, in hertz.")
    modulation: ks.modulation(description="Modulation of received signal.")
    location: roax.geo.Point(
        description="Location of the receiving station at the time of reception."
    )
    bearing: ks.bearing(description="Bearing toward received signal, in degrees true.")
    duration: s.int(
        description="Duration of received signal, in seconds rounded-up.", min=1
    )
    strength: s.int(description="Strength of the received signal, in dBm.")
    nmea: s.str(
        description="$GPRMC NMEA sentence received from GPS at the time the signal was detected."
    )

    _required = (
        "task_id station_id time frequency modulation location bearing duration strength nmea",
    )
Exemplo n.º 2
0
class DC:
    id: s.uuid()
    str: s.str(nullable=True)
    dict: s.dict({"a": s.int()}, nullable=True)
    list: s.list(s.int(), nullable=True)
    _set: s.set(s.str(), nullable=True)
    int: s.int(nullable=True)
    float: s.float(nullable=True)
    bool: s.bool(nullable=True)
    bytes: s.bytes(format="byte", nullable=True)
    date: s.date(nullable=True)
    datetime: s.datetime(nullable=True)
Exemplo n.º 3
0
class Signal:
    """Detected signal, computed from station reception reports."""

    id: s.uuid(description="Identifies signal.")
    task_id: s.uuid(description="Identifies task that signal is for.")
    report_ids: s.set(description="Station receiption reports of signal.",
                      items=s.uuid())
    time: s.datetime(description="Date and time of signal.")
    duration: s.int(description="Duration of signal, in seconds.", min=1)
    location: roax.geo.Point(
        description="Computed location of transmitting station.")
    cep: s.int(description="Circle error probable of location, in metres.")

    _required = "task_id report_ids time duration location cep"
Exemplo n.º 4
0
 def test_one_of_json_codec(self):
     for value in [
             123, UUID("06b959d0-65e0-11e7-866d-6be08781d5cb"), False
     ]:
         schema = s.one_of([s.int(), s.uuid(), s.bool()])
         self.assertEqual(schema.json_decode(schema.json_encode(value)),
                          value)
Exemplo n.º 5
0
def test_read_schemaerror():
    with TemporaryDirectory() as dir:
        fr = FileResource(dir, schema=s.int(), extension=".int")
        fr.create("1", 1)
        with open("{}/1.int".format(dir), "w") as f:
            f.write("a")
        with pytest.raises(InternalServerError):
            fr.read("1")
Exemplo n.º 6
0
def test_all_of_nullable_outer():
    s.all_of(
        (
            s.dict({"a": s.str()}, additional=True),
            s.dict({"b": s.int()}, additional=True),
        ),
        nullable=True,
    ).validate(None)
Exemplo n.º 7
0
 def test_dict_json_encode_success(self):
     self._equal(
         s.dict({
             "eja": s.str(),
             "ejb": s.int()
         }, {"eja", "ejb"}).json_encode, {
             "eja": "foo",
             "ejb": 123
         })
Exemplo n.º 8
0
class Task:
    """Monitoring task."""

    id: s.uuid(description="Identifies the monitoring task.")
    team_id: s.uuid(
        description=
        "Identifies the organization the monitoring task managed under.")
    start_time: s.datetime(
        description=
        "Date and time (inclusive) that the task is scheduled to begin.")
    end_time: s.datetime(
        description=
        "Date and time (inclusive) that the task is scheduled to end.")
    frequency: s.int(description="Dial frequency to monitor, in hertz.")
    modulation: ks.modulation(
        description="Modulation of signals to be processed.")
    bandwidth: s.int(description="Monitoring bandwidth, in hertz.")

    _required = "team_id start_time end_time frequency modulation bandwidth"
Exemplo n.º 9
0
 def __init__(self, **kwargs):
     super().__init__(
         python_type=geojson.Feature,
         props={
             "geometry": Geometry(nullable=True).schema,
             "properties": s.dict(props={}, additional=True, nullable=True),
             "id": s.one_of({s.str(), s.int(), s.float()}),
         },
         required={"geometry", "properties"},
         **kwargs,
     )
Exemplo n.º 10
0
class TestResource(Resource):

    @operation(params={"_body": s.bytes(format="binary")}, returns=s.dict({"id": s.str()}))
    def create(self, _body):
        if _body != b"hello_body":
            raise BadRequest("_body not hello_body")
        return {"id": "foo"}

    @operation(type="action", params={"a": s.int(), "b": s.str()}, returns=s.str())
    def foo(self, a, b):
        return "hoot"
Exemplo n.º 11
0
 def test(
         self,
         a: s.list(s.str()),
         b: s.set(s.str()),
         c: s.int(),
         d: s.float(),
         e: s.bool(),
         f: s.bytes(),
         g: s.datetime(),
         h: s.uuid(),
 ):
     pass
Exemplo n.º 12
0
    def test_crud_dict(self):

        _schema = s.dict({
            "id": s.uuid(required=False),
            "foo": s.str(),
            "bar": s.int(),
        })

        class FooResource(FileResource):

            schema = _schema

            @operation(params={"_body": _schema},
                       returns=s.dict({"id": _schema.properties["id"]}))
            def create(self, _body):
                return super().create(uuid4(), _body)

            @operation(params={"id": _schema.properties["id"]},
                       returns=_schema)
            def read(self, id):
                return super().read(id)

            @operation(params={
                "id": _schema.properties["id"],
                "_body": _schema
            })
            def update(self, id, _body):
                return super().update(id, _body)

            @operation(params={"id": _schema.properties["id"]})
            def delete(self, id):
                return super().delete(id)

            @operation(type="query", returns=s.list(_schema.properties["id"]))
            def list(self):
                return super().list()

        with TemporaryDirectory() as dir:
            rs = FooResource(dir)
            r1 = {"foo": "hello", "bar": 1}
            id = rs.create(r1)["id"]
            r1["id"] = id
            r2 = rs.read(id)
            self.assertEqual(r1, r2)
            r1["bar"] = 2
            rs.update(id, r1)
            r2 = rs.read(id)
            self.assertEqual(r1, r2)
            rs.delete(id)
            self.assertEqual(rs.list(), [])
Exemplo n.º 13
0
    def test_crud_dict(self):
        
        _schema = s.dict(
            properties = {
                "id": s.uuid(),
                "foo": s.str(),
                "bar": s.int(),
            },
            required = {"foo", "bar"},
        )

        class FooResource(MemoryResource):

            @operation(params={"_body": _schema}, returns=s.dict({"id": _schema.properties["id"]}))
            def create(self, _body):
                return super().create(uuid4(), _body)

            @operation(params={"id": _schema.properties["id"]}, returns=_schema)
            def read(self, id):
                return {**super().read(id), "id": id}

            @operation(params={"id": _schema.properties["id"], "_body": _schema})
            def update(self, id, _body):
                return super().update(id, _body)

            @operation(params={"id": _schema.properties["id"]})
            def delete(self, id):
                return super().delete(id)

            @operation(type="query", returns=s.list(_schema.properties["id"]))
            def list(self):
                return super().list()

        rs = FooResource()
        r1 = { "foo": "hello", "bar": 1 }
        id = rs.create(r1)["id"]
        r1["id"] = id
        r2 = rs.read(id)
        self.assertEqual(r1, r2) 
        r1["bar"] = 2
        rs.update(id, r1)
        r2 = rs.read(id)
        self.assertEqual(r1, r2) 
        rs.delete(id)
        self.assertEqual(rs.list(), [])
Exemplo n.º 14
0
def test_crud_dict():

    _schema = s.dict({"id": s.uuid(), "foo": s.str(), "bar": s.int()}, "foo bar")

    class FooResource(FileResource):

        schema = _schema
        id_schema = _schema.props["id"]

        @operation()
        def create(self, _body: _schema) -> s.dict({"id": _schema.props["id"]}):
            return super().create(uuid4(), _body)

        @operation()
        def read(self, id: _schema.props["id"]) -> _schema:
            return {**super().read(id), "id": id}

        @operation()
        def update(self, id: _schema.props["id"], _body: _schema):
            return super().update(id, _body)

        @operation()
        def delete(self, id: _schema.props["id"]):
            return super().delete(id)

        @operation(type="query")
        def list(self) -> s.list(_schema.props["id"]):
            return super().list()

    with TemporaryDirectory() as dir:
        rs = FooResource(dir)
        r1 = {"foo": "hello", "bar": 1}
        id = rs.create(r1)["id"]
        r1["id"] = id
        r2 = rs.read(id)
        assert r1 == r2
        r1["bar"] = 2
        rs.update(id, r1)
        r2 = rs.read(id)
        assert r1 == r2
        rs.delete(id)
        assert rs.list() == []
Exemplo n.º 15
0
 def test_dict_json_decode_optional_success(self):
     self._equal(
         s.dict({
             "djc": s.int(),
             "djd": s.str()
         }).json_decode, {"djc": 12345})
Exemplo n.º 16
0
 def test_one_of_either_match(self):
     s.one_of([s.str(), s.int()]).validate("one")
     s.one_of([s.str(), s.int()]).validate(1)
Exemplo n.º 17
0
 def test_one_of_none_match(self):
     self._error(s.one_of([s.str(), s.int()]).validate, 123.45)
Exemplo n.º 18
0
 def test_dict_json_encode_error(self):
     self._error(
         s.dict({
             "ejh": s.int()
         }, {"ejh"}).json_encode, {"ejh": "not an int"})
Exemplo n.º 19
0
 def test_int_json_encode_success(self):
     self._equal(s.int().json_encode, 6)
Exemplo n.º 20
0
 def test_int_allow_none(self):
     self.assertEqual(s.int(nullable=True).json_encode(None), None)
Exemplo n.º 21
0
 def test_int_disallow_none(self):
     self._error(s.int().json_encode, None)
Exemplo n.º 22
0
 def test_int_validate_enum_error(self):
     self._error(s.int(enum=[6, 7, 8, 9]).validate, 3)
Exemplo n.º 23
0
 def test_int_validate_enum_success(self):
     s.int(enum=[1, 2, 3, 4, 5]).validate(4)
Exemplo n.º 24
0
 def test_int_str_decode_error(self):
     self._error(s.int().str_decode, "11.2")
Exemplo n.º 25
0
                "type": "basic",
                "scheme": self.scheme,
                "realm": self.realm,
                "user_id": user_id,
                "role": "god",
            }


_scheme = _TestBasicSecurityScheme("WallyWorld")

http1 = _TestBasicSecurityRequirement(_scheme)

_r1_schema = s.dict(
    {
        "id": s.str(),
        "foo": s.int(),
        "bar": s.bool(),
        "dt": s.datetime()
    }, "id foo bar")


class _BasicResource1(Resource):

    schema = _r1_schema

    @operation(security=[])
    def create(self, id: _r1_schema.props["id"],
               _body: _r1_schema) -> s.dict({"id": _r1_schema.props["id"]}):
        return {"id": id}

    @operation(security=[])
Exemplo n.º 26
0
 def test_int_json_decode_success_round_float(self):
     self._equal(s.int().json_decode, 8.0)
Exemplo n.º 27
0
 def test_int_json_decode_success_int(self):
     self._equal(s.int().json_decode, 8)
Exemplo n.º 28
0
 def test_int_json_encode_error(self):
     self._error(s.int().json_encode, 7.0)
Exemplo n.º 29
0
 def test_int_json_decode_error_float(self):
     self._error(s.int().json_decode, 9.1)
Exemplo n.º 30
0
 def test_int_str_decode_success(self):
     self.assertEqual(s.int().str_decode("10"), 10)