Ejemplo n.º 1
0
def test_valchk_list_match():
    """Test that mismatched lists result in a False status"""

    allowed = [1, 2, 3]
    ep = Endpoint()

    assert ep.__valchk__(badlist(allowed), allowed) is False
Ejemplo n.º 2
0
def test_valchk_list_element():
    """Test that invalid list elements result in a False status"""

    allowed = [1, 2]
    ep = Endpoint()

    assert ep.__valchk__(3, allowed) is False
Ejemplo n.º 3
0
def test_valchk_dict_value_type():
    """Test that invalid value types result in a False status"""

    allowed = {"test": str, "test2": int, "test3": bool}
    passed = badparams(allowed)
    ep = Endpoint()

    assert ep.__valchk__(passed, allowed) is False
Ejemplo n.º 4
0
def test_valchk_dict_keys():
    """Test that a invalid keys result in a False status"""

    allowed = {"test": str, "test2": int}
    passed = {"test": "toast", randstr(3): 3}
    ep = Endpoint()

    assert ep.__valchk__(passed, allowed) is False
Ejemplo n.º 5
0
def test_valchk_str():
    """Test that an invalid string results in a False status"""

    allowed = "test"
    passed = randstr(5)
    ep = Endpoint()

    assert ep.__valchk__(allowed, passed) is False
Ejemplo n.º 6
0
def test_valchk_dict_required():
    """Test that required elements are present and of the correct type - expect False for bad data"""

    allowed = {"test": str, "test2": int, "test3": bool}
    required = {"test": str, "test2": int}
    passed = missingreq(required)
    ep = Endpoint()

    print(passed, allowed, required)
    assert ep.__valchk__(passed, allowed, required=required) is False
Ejemplo n.º 7
0
def test_valchk_dict_related():
    """Test that related element types are validated - expect False for bad data"""

    allowed = {"test__in": list, "test2__in": list, "created_at__gt": datetime}
    related = {"test": str, "test2": int, "created_at": datetime}
    passed = {
        "test__in": [1, 2, 3],
        "test2__in": ["a", "b", "c"],
        "created_at__gt": randstr(3)
    }
    ep = Endpoint()

    assert ep.__valchk__(passed, allowed, related=related) is False
Ejemplo n.º 8
0
    def __init__(self,
                 method=None,
                 params=None,
                 filters=None,
                 expands=None,
                 fields=None,
                 paging=None,
                 body=None):

        Endpoint.__init__(self,
                          base_uri=URI,
                          allowed_meths=ALLOWED_METHS)

        self.method = method
        self.params = params
        self.filters = filters
        self.expands = expands
        self.fields = fields
        self.paging = paging
        self.body = body
Ejemplo n.º 9
0
    def __init__(self,
                 method=None,
                 params=None,
                 filters=None,
                 expands=None,
                 fields=None,
                 paging=None,
                 body=None):

        Endpoint.__init__(self,
                          base_uri=URI,
                          allowed_meths=ALLOWED_METHS,
                          allowed_params=ALLOWED_PARAMS,
                          required_params=REQUIRED_PARAMS,
                          allowed_filters=ALLOWED_FILTERS,
                          allowed_expands=ALLOWED_EXPANDS)

        self.method = method
        self.params = params
        self.filters = filters
        self.expands = expands
        self.fields = fields
        self.paging = paging
        self.body = body
Ejemplo n.º 10
0
def test_endpoint():
    return Endpoint()
Ejemplo n.º 11
0
    if isinstance(allowed[0], int):
        p = [randstr(3) for i in allowed]

    elif isinstance(allowed[0], str):
        p = [random.randint(0, 255) for i in allowed]

    else:
        p = False

    return p


@pytest.fixture(scope="module",
                params=[
                    Endpoint(),
                    Accounts(),
                    Routers(),
                    RouterStreamUsageSamples(),
                    RouterStateSamples(),
                    NetDeviceUsageSamples(),
                    RouterLogs(),
                    RouterAlerts(),
                    NetDeviceSignalSamples(),
                    NetDevices(),
                    Groups(),
                    Firmwares(),
                    ConfigurationManagers(),
                    Products(),
                    RebootActivity()
                ],