def setUp(self): super(HooksTests, self).setUp() self.hooks = Hooks("123") self.hook_dict = { "actions": ["35c73af7-d72b-45e7-a1af-94d1a66383f7"], "groups": [], "id": "6e39eeb3-c5ba-48c3-95bb-3692d6ef4d22", "name": "curl user_agent", "sources": ["580a199c-8e25-4f60-9369-16390fd047e0"], "triggers": ["user_agent = /curl\\/[\\d.]*/"], }
class HooksTests(TestCase): """ Tests for the Hooks class """ def setUp(self): super(HooksTests, self).setUp() self.hooks = Hooks("123") self.hook_dict = { "actions": ["35c73af7-d72b-45e7-a1af-94d1a66383f7"], "groups": [], "id": "6e39eeb3-c5ba-48c3-95bb-3692d6ef4d22", "name": "curl user_agent", "sources": ["580a199c-8e25-4f60-9369-16390fd047e0"], "triggers": ["user_agent = /curl\\/[\\d.]*/"], } @patch.object(Hooks, "_post") def test_create(self, mock_post): """ Test .create() """ self.hooks.create( "newhook", regexes=["hostname = /*.example.com/"], tag_ids=["ce5eb877-a0ea-4a0a-ac38-7b7e83a1c307"], logs=["0a4cb373-0ab5-4934-ab99-b6236c7324ff"], ) mock_post.assert_called_once_with( request="create", uri="hooks", params={ "name": "newhook", "triggers": ["hostname = /*.example.com/"], "sources": ["0a4cb373-0ab5-4934-ab99-b6236c7324ff"], "groups": [], "actions": ["ce5eb877-a0ea-4a0a-ac38-7b7e83a1c307"], }, ) @patch.object(Hooks, "_post") def test_list(self, mock_post): """ Test .list() """ self.hooks.list() mock_post.assert_called_once_with(request="list", uri="hooks") @patch.object(Hooks, "list") def test_get(self, mock_list): """ Test .get() """ mock_list.return_value = [{"name": "abcd", "actions": []}, {"name": "hook1", "actions": []}] response = self.hooks.get("hook1") self.assertEqual(response, [{"name": "hook1", "actions": []}]) @patch.object(Hooks, "list") def test_get_none(self, mock_list): """ Test .get() with no matches """ mock_list.return_value = [{"name": "abcd", "actions": []}, {"name": "hook1", "actions": []}] response = self.hooks.get("hook2") self.assertEqual(response, []) @patch.object(Hooks, "_post") def test_update(self, mock_post): """ Test .update() """ hook = { "should not get through": "nope", "id": "d9d4596e-49e4-4135-b3b3-847f9e7c1f43", "name": "My Sandbox", "triggers": ["host = you.example.com"], "sources": ["4d42c719-4005-4929-aa4a-994da4b95040"], "groups": [], "actions": ["9f6adf69-37b9-4a4b-88fb-c3fc4c781a11", "ddc36d71-33cb-4f4f-be1b-8591814b1946"], } self.hooks.update(hook) mock_post.assert_called_once_with( request="update", uri="hooks", params={ "id": "d9d4596e-49e4-4135-b3b3-847f9e7c1f43", "name": "My Sandbox", "triggers": ["host = you.example.com"], "sources": ["4d42c719-4005-4929-aa4a-994da4b95040"], "groups": [], "actions": ["9f6adf69-37b9-4a4b-88fb-c3fc4c781a11", "ddc36d71-33cb-4f4f-be1b-8591814b1946"], }, ) @patch.object(Hooks, "_post") def test_delete(self, mock_post): """ Test .delete() """ self.hooks.delete("006d95a8-4fac-42c4-90ed-c3c34978de3e") mock_post.assert_called_once_with( request="delete", uri="hooks", params={"id": "006d95a8-4fac-42c4-90ed-c3c34978de3e"} )