Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test that fails intermittently under python 3.5 #173

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified bin/prom2teams
100644 → 100755
Empty file.
15 changes: 15 additions & 0 deletions tests/test_json_fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import json
import sys

from prom2teams.teams.alarm_mapper import map_prom_alerts_to_teams_alarms
from prom2teams.prometheus.message_schema import MessageSchema
Expand All @@ -9,6 +10,10 @@
class TestJSONFields(unittest.TestCase):
TEST_CONFIG_FILES_PATH = 'tests/data/jsons/'

def __init__(self, *args, **kwargs):
super(TestJSONFields, self).__init__(*args, **kwargs)
self.maxDiff = None

def test_json_with_all_fields(self):
with open(self.TEST_CONFIG_FILES_PATH + 'all_ok.json') as json_data:
json_received = json.load(json_data)
Expand Down Expand Up @@ -85,6 +90,16 @@ def test_with_extra_labels(self):
rendered_data = AlarmSender()._create_alarms(alerts)[0]
json_rendered = json.loads(rendered_data)

# account for unsorted dicts in python 3.5
if sys.version_info[0] == 3 and sys.version_info[1] == 5:
facts = json_rendered['sections'][0]['facts']
(extra_label1, extra_label2) = facts[-2:]
# if the names are not in alphabetical order
if extra_label2['name'] != 'prometheus':
# switch the fact order
facts[-1] = extra_label1
facts[-2] = extra_label2

self.assertDictEqual(json_rendered, json_expected)

def test_with_extra_annotations(self):
Expand Down