def test_should_parse_two_columns(self):
     answer = format_answer(
         "GET hosts\nColumns: host_name notifications_enabled\nFilter: host_name = devica01\n",
         [["devica01", 1]],
         None,
     )
     self.assertEqual(answer, [{"notifications_enabled": 1, "host_name": "devica01"}])
    def test_should_parse_query_with_two_columns(self):
        answer = format_answer(
            """
GET hosts
Columns: host_name notifications_enabled""",
            [
                ["devica01", 1],
                ["tuvdbs05", 1],
                ["tuvdbs06", 1],
                ["tuvdbs50", 1],
                ["tuvmpc01", 1],
                ["tuvmpc02", 1],
                ["tuvrep01", 1],
            ],
            "host_name",
        )
        self.assertEqual(
            answer,
            {
                "devica01": {"notifications_enabled": 1, "host_name": "devica01"},
                "tuvrep01": {"notifications_enabled": 1, "host_name": "tuvrep01"},
                "tuvdbs06": {"notifications_enabled": 1, "host_name": "tuvdbs06"},
                "tuvdbs05": {"notifications_enabled": 1, "host_name": "tuvdbs05"},
                "tuvdbs50": {"notifications_enabled": 1, "host_name": "tuvdbs50"},
                "tuvmpc01": {"notifications_enabled": 1, "host_name": "tuvmpc01"},
                "tuvmpc02": {"notifications_enabled": 1, "host_name": "tuvmpc02"},
            },
        )
    def test_should_parse_query_with_two_columns(self):
        answer = format_answer('''
GET hosts
Columns: host_name notifications_enabled''', [["devica01", 1], ["tuvdbs05", 1], ["tuvdbs06", 1], ["tuvdbs50", 1], ["tuvmpc01", 1], ["tuvmpc02", 1], ["tuvrep01", 1]], 'host_name')
        self.assertEqual(answer, {
            'devica01': {
                'notifications_enabled': 1,
                'host_name': 'devica01'
            },
            'tuvrep01': {
                'notifications_enabled': 1,
                'host_name': 'tuvrep01'
            },
            'tuvdbs06': {
                'notifications_enabled': 1,
                'host_name': 'tuvdbs06'
            },
            'tuvdbs05': {
                'notifications_enabled': 1,
                'host_name': 'tuvdbs05'
            },
            'tuvdbs50': {
                'notifications_enabled': 1,
                'host_name': 'tuvdbs50'
            },
            'tuvmpc01': {
                'notifications_enabled': 1,
                'host_name': 'tuvmpc01'
            },
            'tuvmpc02': {
                'notifications_enabled': 1,
                'host_name': 'tuvmpc02'
            }})
Example #4
0
 def test_should_parse_two_columns(self):
     answer = format_answer(
         'GET hosts\nColumns: host_name notifications_enabled\nFilter: host_name = devica01\n',
         [["devica01", 1]], None)
     self.assertEqual(answer, [{
         'notifications_enabled': 1,
         'host_name': 'devica01'
     }])
Example #5
0
 def test_should_skip_rows_where_the_key_is_missing(self):
     answer = format_answer('GET hosts\nColumns: foo bar baz\n',
                            [["foo1", "bar1", "baz1"], ["foo2", "bar2"]],
                            'baz')
     self.assertEqual(
         answer, {'baz1': {
             'baz': 'baz1',
             'foo': 'foo1',
             'bar': 'bar1'
         }})
 def test_should_return_list_when_no_key_is_given(self):
     answer = format_answer('GET hosts\nColumns: host_name notifications_enabled''',
                           [["devica01",'1']],
                            None)
     self.assertEqual(answer, [
                                 {
                                     'notifications_enabled': '1',
                                     'host_name': 'devica01'
                                 },
                             ])
Example #7
0
 def test_should_return_list_when_no_key_is_given(self):
     answer = format_answer(
         'GET hosts\nColumns: host_name notifications_enabled'
         '', [["devica01", '1']], None)
     self.assertEqual(answer, [
         {
             'notifications_enabled': '1',
             'host_name': 'devica01'
         },
     ])
 def test_should_parse_columns_from_answer_when_no_columns_were_specified(self):
     answer = format_answer(
         "GET hosts",
         [["host_name", "notifications_enabled"], ["devica01", "1"], ["tuvdbs05", "1"], ["tuvdbs06", "1"]],
         None,
     )
     self.assertEqual(
         answer,
         [
             {"notifications_enabled": "1", "host_name": "devica01"},
             {"notifications_enabled": "1", "host_name": "tuvdbs05"},
             {"notifications_enabled": "1", "host_name": "tuvdbs06"},
         ],
     )
Example #9
0
 def test_should_parse_columns_from_answer_when_no_columns_were_specified(
         self):
     answer = format_answer(
         'GET hosts',
         [['host_name', 'notifications_enabled'], ['devica01', '1'],
          ['tuvdbs05', '1'], ['tuvdbs06', '1']], None)
     self.assertEqual(answer, [{
         'notifications_enabled': '1',
         'host_name': 'devica01'
     }, {
         'notifications_enabled': '1',
         'host_name': 'tuvdbs05'
     }, {
         'notifications_enabled': '1',
         'host_name': 'tuvdbs06'
     }])
 def test_should_skip_rows_where_the_key_is_missing(self):
     answer = format_answer('GET hosts\nColumns: foo bar baz\n', [["foo1","bar1", "baz1"], ["foo2", "bar2"]], 'baz')
     self.assertEqual(answer, {'baz1': {'baz': 'baz1', 'foo': 'foo1', 'bar': 'bar1'}})
 def test_should_parse_two_columns(self):
     answer = format_answer('GET hosts\nColumns: host_name notifications_enabled\nFilter: host_name = devica01\n', [["devica01",1]], None)
     self.assertEqual(answer, [{'notifications_enabled': 1, 'host_name': 'devica01'}])
 def test_should_parse_query_with_several_columns(self):
     answer = format_answer('GET hosts\nColumns: host_name notifications_enabled accept_passive_checks acknowledged acknowledgement_type action_url',
                            [["devica01",1,1,0,0,""], ["tuvdbs05",1,1,0,0,""], ["tuvdbs06",1,1,0,0,""], ["tuvdbs50",1,1,0,0,""], ["tuvmpc01",1,1,0,0,""], ["tuvmpc02",1,1,0,0,""], ["tuvrep01",1,1,0,0,""]],
                            'host_name')
     self.assertEqual(answer, {'devica01': {'acknowledgement_type': 0, 'notifications_enabled': 1, 'acknowledged': 0, 'action_url': '', 'accept_passive_checks': 1, 'host_name': 'devica01'}, 'tuvrep01': {'acknowledgement_type': 0, 'notifications_enabled': 1, 'acknowledged': 0, 'action_url': '', 'accept_passive_checks': 1, 'host_name': 'tuvrep01'}, 'tuvdbs06': {'acknowledgement_type': 0, 'notifications_enabled': 1, 'acknowledged': 0, 'action_url': '', 'accept_passive_checks': 1, 'host_name': 'tuvdbs06'}, 'tuvdbs05': {'acknowledgement_type': 0, 'notifications_enabled': 1, 'acknowledged': 0, 'action_url': '', 'accept_passive_checks': 1, 'host_name': 'tuvdbs05'}, 'tuvdbs50': {'acknowledgement_type': 0, 'notifications_enabled': 1, 'acknowledged': 0, 'action_url': '', 'accept_passive_checks': 1, 'host_name': 'tuvdbs50'}, 'tuvmpc01': {'acknowledgement_type': 0, 'notifications_enabled': 1, 'acknowledged': 0, 'action_url': '', 'accept_passive_checks': 1, 'host_name': 'tuvmpc01'}, 'tuvmpc02': {'acknowledgement_type': 0, 'notifications_enabled': 1, 'acknowledged': 0, 'action_url': '', 'accept_passive_checks': 1, 'host_name': 'tuvmpc02'}})
 def test_should_parse_columns_from_answer_when_no_columns_were_specified(self):
     answer = format_answer('GET hosts', [['host_name','notifications_enabled'],['devica01', '1'], ['tuvdbs05','1'], ['tuvdbs06','1']], None)
     self.assertEqual(answer, [{'notifications_enabled': '1', 'host_name': 'devica01'}, {'notifications_enabled': '1', 'host_name': 'tuvdbs05'}, {'notifications_enabled': '1', 'host_name': 'tuvdbs06'}])
 def test_should_skip_rows_where_the_key_is_missing(self):
     answer = format_answer("GET hosts\nColumns: foo bar baz\n", [["foo1", "bar1", "baz1"], ["foo2", "bar2"]], "baz")
     self.assertEqual(answer, {"baz1": {"baz": "baz1", "foo": "foo1", "bar": "bar1"}})
Example #15
0
 def test_should_parse_query_with_several_columns(self):
     answer = format_answer(
         'GET hosts\nColumns: host_name notifications_enabled accept_passive_checks acknowledged acknowledgement_type action_url',
         [["devica01", 1, 1, 0, 0, ""], ["tuvdbs05", 1, 1, 0, 0, ""],
          ["tuvdbs06", 1, 1, 0, 0, ""], ["tuvdbs50", 1, 1, 0, 0, ""],
          ["tuvmpc01", 1, 1, 0, 0, ""], ["tuvmpc02", 1, 1, 0, 0, ""],
          ["tuvrep01", 1, 1, 0, 0, ""]], 'host_name')
     self.assertEqual(
         answer, {
             'devica01': {
                 'acknowledgement_type': 0,
                 'notifications_enabled': 1,
                 'acknowledged': 0,
                 'action_url': '',
                 'accept_passive_checks': 1,
                 'host_name': 'devica01'
             },
             'tuvrep01': {
                 'acknowledgement_type': 0,
                 'notifications_enabled': 1,
                 'acknowledged': 0,
                 'action_url': '',
                 'accept_passive_checks': 1,
                 'host_name': 'tuvrep01'
             },
             'tuvdbs06': {
                 'acknowledgement_type': 0,
                 'notifications_enabled': 1,
                 'acknowledged': 0,
                 'action_url': '',
                 'accept_passive_checks': 1,
                 'host_name': 'tuvdbs06'
             },
             'tuvdbs05': {
                 'acknowledgement_type': 0,
                 'notifications_enabled': 1,
                 'acknowledged': 0,
                 'action_url': '',
                 'accept_passive_checks': 1,
                 'host_name': 'tuvdbs05'
             },
             'tuvdbs50': {
                 'acknowledgement_type': 0,
                 'notifications_enabled': 1,
                 'acknowledged': 0,
                 'action_url': '',
                 'accept_passive_checks': 1,
                 'host_name': 'tuvdbs50'
             },
             'tuvmpc01': {
                 'acknowledgement_type': 0,
                 'notifications_enabled': 1,
                 'acknowledged': 0,
                 'action_url': '',
                 'accept_passive_checks': 1,
                 'host_name': 'tuvmpc01'
             },
             'tuvmpc02': {
                 'acknowledgement_type': 0,
                 'notifications_enabled': 1,
                 'acknowledged': 0,
                 'action_url': '',
                 'accept_passive_checks': 1,
                 'host_name': 'tuvmpc02'
             }
         })
 def test_should_parse_query_with_several_columns(self):
     answer = format_answer(
         "GET hosts\nColumns: host_name notifications_enabled accept_passive_checks acknowledged acknowledgement_type action_url",
         [
             ["devica01", 1, 1, 0, 0, ""],
             ["tuvdbs05", 1, 1, 0, 0, ""],
             ["tuvdbs06", 1, 1, 0, 0, ""],
             ["tuvdbs50", 1, 1, 0, 0, ""],
             ["tuvmpc01", 1, 1, 0, 0, ""],
             ["tuvmpc02", 1, 1, 0, 0, ""],
             ["tuvrep01", 1, 1, 0, 0, ""],
         ],
         "host_name",
     )
     self.assertEqual(
         answer,
         {
             "devica01": {
                 "acknowledgement_type": 0,
                 "notifications_enabled": 1,
                 "acknowledged": 0,
                 "action_url": "",
                 "accept_passive_checks": 1,
                 "host_name": "devica01",
             },
             "tuvrep01": {
                 "acknowledgement_type": 0,
                 "notifications_enabled": 1,
                 "acknowledged": 0,
                 "action_url": "",
                 "accept_passive_checks": 1,
                 "host_name": "tuvrep01",
             },
             "tuvdbs06": {
                 "acknowledgement_type": 0,
                 "notifications_enabled": 1,
                 "acknowledged": 0,
                 "action_url": "",
                 "accept_passive_checks": 1,
                 "host_name": "tuvdbs06",
             },
             "tuvdbs05": {
                 "acknowledgement_type": 0,
                 "notifications_enabled": 1,
                 "acknowledged": 0,
                 "action_url": "",
                 "accept_passive_checks": 1,
                 "host_name": "tuvdbs05",
             },
             "tuvdbs50": {
                 "acknowledgement_type": 0,
                 "notifications_enabled": 1,
                 "acknowledged": 0,
                 "action_url": "",
                 "accept_passive_checks": 1,
                 "host_name": "tuvdbs50",
             },
             "tuvmpc01": {
                 "acknowledgement_type": 0,
                 "notifications_enabled": 1,
                 "acknowledged": 0,
                 "action_url": "",
                 "accept_passive_checks": 1,
                 "host_name": "tuvmpc01",
             },
             "tuvmpc02": {
                 "acknowledgement_type": 0,
                 "notifications_enabled": 1,
                 "acknowledged": 0,
                 "action_url": "",
                 "accept_passive_checks": 1,
                 "host_name": "tuvmpc02",
             },
         },
     )
 def test_should_return_list_when_no_key_is_given(self):
     answer = format_answer("GET hosts\nColumns: host_name notifications_enabled" "", [["devica01", "1"]], None)
     self.assertEqual(answer, [{"notifications_enabled": "1", "host_name": "devica01"}])