How to use spidermon - 10 common examples

To help you get started, we’ve selected a few spidermon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scrapinghub / spidermon / tests / fixtures / levels.py View on Github external
# ----------------------------------
# Base Monitors
# ----------------------------------
class NoLevelMethodMonitor(Monitor):
    def test(self):
        pass


class HighLevelMethodMonitor(Monitor):
    @monitors.level.high
    def test(self):
        pass


class NormalLevelMethodMonitor(Monitor):
    @monitors.level.normal
    def test(self):
        pass


class LowLevelMethodMonitor(Monitor):
    @monitors.level.low
    def test(self):
        pass


# ----------------------------------
# Monitors
# ----------------------------------
class Monitors:
    class NoLevelMonitor:
github scrapinghub / spidermon / tests / test_suites.py View on Github external
SuiteDefinition(EmptySuite, [("S", Suite04)], 13),
]
INVALID_SUITE_DEFINITION_NON_ITERABLE = SuiteDefinition(EmptySuite, 10)
INVALID_SUITE_DEFINITION_NONE = SuiteDefinition(EmptySuite, [None])
INVALID_SUITE_DEFINITION_NUMBER = SuiteDefinition(EmptySuite, [10])
INVALID_SUITE_DEFINITION_CLASS = SuiteDefinition(EmptySuite, [object])
INVALID_SUITE_DEFINITION_TUPLE1 = SuiteDefinition(EmptySuite, [(1,)])
INVALID_SUITE_DEFINITION_TUPLE3 = SuiteDefinition(EmptySuite, [(1, 2, 3)])
INVALID_SUITE_DEFINITION_TUPLE2_WRONG1 = SuiteDefinition(EmptySuite, [(1, 2)])
INVALID_SUITE_DEFINITION_TUPLE2_WRONG2 = SuiteDefinition(EmptySuite, [("A", 2)])

INVALID_SUITE_DEFINITIONS = [
    # --------------------------------------------------------------
    # definition                                raises
    # --------------------------------------------------------------
    (INVALID_SUITE_DEFINITION_NONE, InvalidMonitor),
    (INVALID_SUITE_DEFINITION_NUMBER, InvalidMonitor),
    (INVALID_SUITE_DEFINITION_CLASS, InvalidMonitorClass),
    (INVALID_SUITE_DEFINITION_TUPLE1, InvalidMonitorTuple),
    (INVALID_SUITE_DEFINITION_TUPLE3, InvalidMonitorTuple),
    (INVALID_SUITE_DEFINITION_TUPLE2_WRONG1, InvalidMonitorTuple),
    (INVALID_SUITE_DEFINITION_TUPLE2_WRONG2, InvalidMonitor),
]


def test_creation_error_non_iterable():
    with pytest.raises(InvalidMonitorIterable):
        _test_creation_from_init(INVALID_SUITE_DEFINITION_NON_ITERABLE)
    with pytest.raises(InvalidMonitorIterable):
        _test_creation_from_add_monitors(INVALID_SUITE_DEFINITION_NON_ITERABLE)
github scrapinghub / spidermon / tests / test_levels.py View on Github external
from __future__ import absolute_import
from spidermon import settings

from .fixtures.levels import *

HIGH = settings.MONITOR.LEVEL.HIGH
NORMAL = settings.MONITOR.LEVEL.NORMAL
LOW = settings.MONITOR.LEVEL.LOW


LEVEL_TESTS = [
    # ---------------------------------------------------------------------------------------
    # suite                     monitor/methods                                expected level
    # ---------------------------------------------------------------------------------------
    # Suite No Level
    (Suites.NoLevelSuite, Monitors.NoLevelMonitor.NoLevelMethod, NORMAL),
    (Suites.NoLevelSuite, Monitors.NoLevelMonitor.HighLevelMethod, HIGH),
    (Suites.NoLevelSuite, Monitors.NoLevelMonitor.NormalLevelMethod, NORMAL),
    (Suites.NoLevelSuite, Monitors.NoLevelMonitor.LowLevelMethod, LOW),
    (Suites.NoLevelSuite, Monitors.HighLevelMonitor.NoLevelMethod, HIGH),
    (Suites.NoLevelSuite, Monitors.HighLevelMonitor.HighLevelMethod, HIGH),
    (Suites.NoLevelSuite, Monitors.HighLevelMonitor.NormalLevelMethod, NORMAL),
    (Suites.NoLevelSuite, Monitors.HighLevelMonitor.LowLevelMethod, LOW),
github scrapinghub / spidermon / _tests / fixtures / schemas.py View on Github external
"properties": {
                    "message": {"type": "string"},
                    "traceback": {"type": "string"},
                },
                "required": ["message", "traceback"],
            },
        },
        "required": ["state", "rule"],
    }
}

CHECK_RESULTS_PASS_SCHEMA = copy.deepcopy(CHECK_RESULTS_SCHEMA)
CHECK_RESULTS_PASS_SCHEMA['items']['properties']['state']['enum'] = [settings.CHECK_STATE_PASSED]

CHECK_RESULTS_FAIL_SCHEMA = copy.deepcopy(CHECK_RESULTS_SCHEMA)
CHECK_RESULTS_FAIL_SCHEMA['items']['properties']['state']['enum'] = [settings.CHECK_STATE_FAILED]

CHECK_RESULTS_ERROR_SCHEMA = copy.deepcopy(CHECK_RESULTS_SCHEMA)
CHECK_RESULTS_ERROR_SCHEMA['items']['properties']['state']['enum'] = [settings.CHECK_STATE_ERROR]
CHECK_RESULTS_ERROR_SCHEMA['items']['required'].append('error')


ACTION_RESULTS_SCHEMA = {
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "state": {"enum": list(settings.ACTION_STATES)},
            "action": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
github scrapinghub / spidermon / tests / fixtures / names.py View on Github external
    @monitors.name("A Test")
    def test_with_name(self):
        pass
github scrapinghub / spidermon / tests / fixtures / names.py View on Github external
# Child Suites
# ----------------------------------
class BaseChildSuite(MonitorSuite):
    monitors = [
        UnnamedMonitor,
        NamedMonitor,
        ("Instance Monitor", UnnamedMonitor),
        ("Instance Monitor", NamedMonitor),
    ]


class ChildUnnamedSuite(BaseChildSuite):
    pass


@monitors.name("The Child Suite")
class ChildNamedSuite(BaseChildSuite):
    pass


# ----------------------------------
# Top Suites
# ----------------------------------
class BaseTopSuite(MonitorSuite):
    monitors = [
        ChildUnnamedSuite,
        ChildNamedSuite,
        ("Instance Suite Name", ChildUnnamedSuite),
        ("Instance Suite Name", ChildNamedSuite),
    ]
github scrapinghub / spidermon / tests / fixtures / names.py View on Github external
    @monitors.name("A Test")
    def test_with_name(self):
        pass
github scrapinghub / spidermon / tests / test_validators_jsonschema.py View on Github external
),
        DataTest(
            name="Wrong type for A",
            data={"A": 1, "B": False},
            valid=False,
            expected_errors={
                "": [messages.VALID_FOR_SEVERAL_EXCLUSIVE_SCHEMAS],
                "A": [messages.INVALID_BOOLEAN],
            },
        ),
        DataTest(
            name="Wrong type for both",
            data={"A": 1, "B": 1},
            valid=False,
            expected_errors={
                "": [messages.VALID_FOR_SEVERAL_EXCLUSIVE_SCHEMAS],
                "A": [messages.INVALID_BOOLEAN],
                "B": [messages.INVALID_BOOLEAN],
            },
        ),
    ]


class Pattern(SchemaTest):
    schema = {"pattern": "^a*$"}
    data_tests = [
        DataTest(name="valid", data="aaa", valid=True),
        DataTest(
            name="invalid",
            data="abc",
            valid=False,
            expected_errors={"": [messages.REGEX_NOT_MATCHED]},
github scrapinghub / spidermon / tests / test_validators_jsonschema.py View on Github external
),
    ]


class OneOf(SchemaTest):
    schema = {
        "type": "object",
        "properties": {"A": {"type": "boolean"}, "B": {"type": "boolean"}},
        "oneOf": [{"required": ["A"]}, {"required": ["B"]}],
    }
    data_tests = [
        DataTest(
            name="Empty object",
            data={},
            valid=False,
            expected_errors={"": [messages.NOT_VALID_UNDER_ANY_SCHEMA]},
        ),
        DataTest(name="Mismatch B", data={"A": True}, valid=True),
        DataTest(name="Mismatch A", data={"B": True}, valid=True),
        DataTest(
            name="Both values",
            data={"A": False, "B": False},
            valid=False,
            expected_errors={"": [messages.VALID_FOR_SEVERAL_EXCLUSIVE_SCHEMAS]},
        ),
        DataTest(
            name="Wrong type for A",
            data={"A": 1, "B": False},
            valid=False,
            expected_errors={
                "": [messages.VALID_FOR_SEVERAL_EXCLUSIVE_SCHEMAS],
                "A": [messages.INVALID_BOOLEAN],
github scrapinghub / spidermon / tests / test_validators_jsonschema.py View on Github external
"xn--hxajbheg2az3al.xn--jxalpdlp",
                    "a" * 63,
                ]
            },
            valid=True,
        ),
        DataTest(
            name="hostname. invalid",
            data={"hostnames": ["...", "a" * 64, "-hi-", "_hi_", "*hi*"]},
            valid=False,
            expected_errors={
                "hostnames.0": [messages.INVALID_HOSTNAME],
                "hostnames.1": [messages.INVALID_HOSTNAME],
                "hostnames.2": [messages.INVALID_HOSTNAME],
                "hostnames.3": [messages.INVALID_HOSTNAME],
                "hostnames.4": [messages.INVALID_HOSTNAME],
            },
        ),
        DataTest(
            name="urls. valid",
            data={
                "urls": [
                    "http://www.domain",
                    "http://www.com",
                    "http://www.domain.com.",
                    "http://www.domain.com/.",
                    "http://www.domain.com/..",
                    "http://www.domain.com//cataglog//index.html",
                    "http://www.domain.net/",
                    "http://www.domain.com/level2/leafnode-L2.xhtml/",
                    "http://www.domain.com/level2/level3/leafnode-L3.xhtml/",
                    "http://www.domain.com?pageid=123&testid=1524",