def test_clean(self):
     # all ok
     kwargs = {"requested": 5, "value": "test", "type": "msm", "action": "add"}
     source = AtlasChangeSource(**kwargs)
     self.assertEqual(source.clean(), None)
     # value missing
     source.value = None
     self.assertRaises(
         MalFormattedSource, lambda: source.clean()
     )
     # type missing
     kwargs = {"requested": 5, "value": "test", "action": "add"}
     self.assertRaises(
         MalFormattedSource, lambda: AtlasChangeSource(**kwargs).clean()
     )
     # action missing
     kwargs = {"requested": 5, "value": "test", "type": "probes"}
     self.assertRaises(
         MalFormattedSource, lambda: AtlasChangeSource(**kwargs).clean()
     )
     # requested missing
     source.value = "test"
     source.requested = None
     self.assertRaises(
         MalFormattedSource, lambda: source.clean()
     )
Exemple #2
0
    def test_change_request(self):
        """Unittest for Atlas change request"""
        if self.server == "":
            raise SkipTest

        remove = AtlasChangeSource(**{
            "value": "6001",
            "requested": 1,
            "action": "remove",
            "type": "probes"
        })
        add = AtlasChangeSource(**{
            "value": "6002",
            "requested": 1,
            "action": "add",
            "type": "probes"
        })
        request = AtlasChangeRequest(
            **{
                "key": self.change_key,
                "verify": False,
                "msm_id": 1000032,
                "server": self.server,
                "sources": [add, remove]
            })
        result = namedtuple('Result', 'success response')
        (result.success, result.response) = request.create()
        print(result.response)
        self.assertTrue(result.success)
 def setUp(self):
     change_source = AtlasChangeSource(
         **{"value": "WW", "requested": 3, "action": "add", "type": "area"}
     )
     self.request = AtlasChangeRequest(**{
         "msm_id": 1, "sources": [change_source]
     })
 def test_clean(self):
     # all ok
     kwargs = {"requested": 5, "value": "test", "type": "msm", "action": "add"}
     source = AtlasChangeSource(**kwargs)
     self.assertEqual(source.clean(), None)
     # value missing
     source.value = None
     self.assertRaises(
         MalFormattedSource, lambda: source.clean()
     )
     # type missing
     kwargs = {"requested": 5, "value": "test", "action": "add"}
     self.assertRaises(
         MalFormattedSource, lambda: AtlasChangeSource(**kwargs).clean()
     )
     # action missing
     kwargs = {"requested": 5, "value": "test", "type": "probes"}
     self.assertRaises(
         MalFormattedSource, lambda: AtlasChangeSource(**kwargs).clean()
     )
     # requested missing
     source.value = "test"
     source.requested = None
     self.assertRaises(
         MalFormattedSource, lambda: source.clean()
     )
    def test_setting_type(self):
        kwargs = {
            "requested": 5, "value": "test", "action": "add"
        }
        source = AtlasChangeSource(**kwargs)
        for source_type in ["area", "country", "prefix", "asn", "msm", "probes"]:
            self.assertEqual(setattr(source, "type", source_type), None)

        kwargs = {
            "requested": 5, "value": "test", "action": "remove"
        }
        source = AtlasChangeSource(**kwargs)
        for source_type in ["area", "country", "prefix", "asn", "msm"]:
            self.assertRaises(
                MalFormattedSource,
                lambda: setattr(source, "type", source_type)
            )
        self.assertEqual(setattr(source, "type", "probes"), None)
Exemple #6
0
class TestAtlasChangeSource(unittest.TestCase):

    def setUp(self):
        self.kwargs = {
            "requested": 5, "value": "test", "action": "add"
        }
        self.source = AtlasChangeSource(**self.kwargs)

    def test_setting_type(self):
        for source_type in ["area", "country", "prefix", "asn", "msm"]:
            self.assertRaises(
                MalFormattedSource,
                lambda: setattr(self.source, "type", source_type)
            )

        self.assertEqual(setattr(self.source, "type", "probes"), None)

    def test_setting_action(self):
        for source_action in ["remove", "add"]:
            self.assertEqual(
                setattr(self.source, "action", source_action), None
            )

        self.assertRaises(
            MalFormattedSource,
            lambda: setattr(self.source, "action", "test")
        )

    def test_clean(self):
        self.assertEqual(self.source.clean(), None)
        self.source.value = None
        self.assertRaises(
            MalFormattedSource, lambda: self.source.clean()
        )
        self.source.value = "test"
        self.source.requested = None
        self.assertRaises(
            MalFormattedSource, lambda: self.source.clean()
        )

    def test_build_api_struct(self):
        self.kwargs.update({"type": "probes"})
        self.assertEqual(self.source.build_api_struct(), self.kwargs)
        validate(self.source.build_api_struct(), probes_change_schema)
    def test_setting_action(self):
        kwargs = {
            "requested": 5, "value": "test", "type": "probes"
        }
        source = AtlasChangeSource(**kwargs)
        for source_action in ["remove", "add"]:
            self.assertEqual(
                setattr(source, "action", source_action), None
            )

        self.assertRaises(
            MalFormattedSource,
            lambda: setattr(source, "action", "test")
        )
 def test_set_tags(self):
     # missing action
     kwargs = {
         "requested": 5, "value": "test", "type": "msm",
         "tags": {"include": ["one", "two"], "exclude": ["one", "two"]}
     }
     self.assertRaises(
         MalFormattedSource, lambda: AtlasChangeSource(**kwargs).build_api_struct()
     )
     # action == add
     kwargs = {
         "requested": 5, "value": "test", "type": "msm", "action": "add",
         "tags": {"include": ["one", "two"], "exclude": ["one", "two"]}
     }
     source = AtlasChangeSource(**kwargs)
     self.assertEqual(source.clean(), None)
     # action == remove
     kwargs = {
         "requested": 5, "value": "test", "type": "msm", "action": "remove",
         "tags": {"include": ["one", "two"], "exclude": ["one", "two"]}
     }
     self.assertRaises(
         MalFormattedSource, lambda: AtlasChangeSource(**kwargs)
     )
 def test_build_api_struct(self):
     kwargs = {"requested": 5, "value": "test", "type": "msm", "action": "add"}
     source = AtlasChangeSource(**kwargs)
     self.assertEqual(source.build_api_struct(), kwargs)
     validate(source.build_api_struct(), probes_change_schema)
 def test_build_api_struct(self):
     kwargs = {"requested": 5, "value": "test", "type": "msm", "action": "add"}
     source = AtlasChangeSource(**kwargs)
     self.assertEqual(source.build_api_struct(), kwargs)
     validate(source.build_api_struct(), probes_change_schema)
Exemple #11
0
 def setUp(self):
     self.kwargs = {
         "requested": 5, "value": "test", "action": "add"
     }
     self.source = AtlasChangeSource(**self.kwargs)