Skip to content
Merged
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
24 changes: 12 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ jobs:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/alerta
run: |
pytest -v webhooks/*/test*.py --cov=webhooks
# - name: Unit Test Integrations
# id: unit-test-integrations
# env:
# DATABASE_URL: mongodb://127.0.0.1:27017/alerta
# run: |
# pytest -v integrations/*/test*.py --cov=integrations
- name: Unit Test Integrations
id: unit-test-integrations
env:
DATABASE_URL: mongodb://127.0.0.1:27017/alerta
run: |
pytest -v integrations/*/test*.py --cov=integrations
- uses: act10ns/slack@v2
with:
status: ${{ job.status }}
Expand Down Expand Up @@ -122,12 +122,12 @@ jobs:
DATABASE_URL: mongodb://127.0.0.1:27017/alerta
run: |
pytest -v webhooks/*/test*.py --cov=webhooks
# - name: Unit Test Integrations
# id: unit-test-integrations
# env:
# DATABASE_URL: mongodb://127.0.0.1:27017/alerta
# run: |
# pytest -v integrations/*/test*.py --cov=integrations
- name: Unit Test Integrations
id: unit-test-integrations
env:
DATABASE_URL: mongodb://127.0.0.1:27017/alerta
run: |
pytest -v integrations/*/test*.py --cov=integrations
- uses: act10ns/slack@v2
with:
status: ${{ job.status }}
Expand Down
2 changes: 2 additions & 0 deletions integrations/mailer/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ def validate_rules(rules):
rule, key)
valid = False
break
if valid is False:
break
try:
re.compile(field['regex'])
except re.error:
Expand Down
14 changes: 8 additions & 6 deletions integrations/mailer/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

def test_rules_dont_exist():
'''
Test the rules file is read
Test that parse_group_rules returns None when rules dir does not exist
'''
with patch('mailer.os') as system_os:
system_os.path.exists.return_value = False
# res = mailer.parse_group_rules('config_file')
system_os.path.exists.called_once_with('confile_file')
# assert res is None
system_os.path.dirname.return_value = '/etc'
res = mailer.parse_group_rules('/etc/alerta.conf')
system_os.path.exists.assert_called_once_with('/etc/alerta.rules.d')
assert res == ()


def test_rules_parsing():
Expand All @@ -25,6 +26,7 @@ def test_rules_parsing():
with patch.multiple(mailer, os=DEFAULT, open=DEFAULT,
json=DEFAULT, validate_rules=DEFAULT) as mocks:
mocks['os'].path.exists.return_value = True
mocks['os'].path.dirname.return_value = '/etc'
mocks['os'].walk().__iter__\
.return_value = [('/', None,
['cantopen.json', 'invalid.json', 'valid.json'])]
Expand All @@ -34,10 +36,10 @@ def test_rules_parsing():
doc = [{'notify': {'fields': []}}]
mocks['json'].load.side_effect = [TypeError, doc]
mocks['validate_rules'].return_value = doc
res = mailer.parse_group_rules('config_file')
res = mailer.parse_group_rules('/etc/alerta.conf')

# Assert that we checked for folder existence
mocks['os'].path.exists.called_once_with('confile_file')
mocks['os'].path.exists.assert_called_once_with('/etc/alerta.rules.d')

# Check that validation was called for valid file
mocks['validate_rules'].assert_called_once_with(doc)
Expand Down
Loading