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
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
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
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
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
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
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
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
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
def test_endpoint(): return Endpoint()
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() ],