Skip to content

Commit b66f140

Browse files
authored
Update travis CI config and add tests (alerta#316)
1 parent 81608d8 commit b66f140

File tree

5 files changed

+334
-15
lines changed

5 files changed

+334
-15
lines changed

Diff for: .travis.yml

+26-9
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,44 @@ python:
77
- "3.5"
88
- "3.6"
99
- "3.7"
10+
- "3.8"
1011

1112
env:
12-
- DB=mongodb DATABASE_URL=mongodb://localhost:27017/alerta5
13-
- DB=postgres DATABASE_URL=postgres://localhost:5432/alerta5
13+
- DB=mongodb DATABASE_URL=mongodb://localhost:27017/alerta
14+
- DB=postgres DATABASE_URL=postgres://localhost:5432/alerta
1415

1516
services:
1617
- mongodb
1718
- postgresql
1819

1920
addons:
20-
postgresql: "9.5"
21+
postgresql: "9.6"
2122

2223
before_script:
23-
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS alerta5;' -U postgres; fi"
24-
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'CREATE DATABASE alerta5;' -U postgres; fi"
24+
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS alerta;' -U postgres; fi"
25+
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'CREATE DATABASE alerta;' -U postgres; fi"
2526

2627
install:
2728
- pip install -r requirements-dev.txt
2829

2930
script:
30-
- pylint integrations/*/*.py
31-
- pylint plugins/*/*.py
32-
- pylint webhooks/*/*.py
33-
- pytest -v webhooks/*/test*
31+
- pytest -v integrations/*/test*.py --cov=integrations
32+
- pytest -v plugins/*/test*.py --cov=plugins
33+
- pytest -v webhooks/*/test*.py --cov=webhooks
34+
35+
stages:
36+
- Checks
37+
- Test
38+
39+
jobs:
40+
include:
41+
- stage: Checks
42+
name: Integrations
43+
script: pylint -v integrations/*/*.py
44+
- name: Plugins
45+
script: pylint -v plugins/*/*.py
46+
- name: Web Hooks
47+
script: pylint -v webhooks/*/*.py
48+
49+
after_success:
50+
- coveralls

Diff for: integrations/mailer/tests/test_rules.py renamed to integrations/mailer/test_rules.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'''
44
import pytest
55
import mailer
6-
from alertaclient.alert import AlertDocument
6+
from alertaclient.models.alert import Alert
77
from mock import MagicMock, patch, DEFAULT
88

99

@@ -15,7 +15,7 @@ def test_rules_dont_exist():
1515
system_os.path.exists.return_value = False
1616
res = mailer.parse_group_rules('config_file')
1717
system_os.path.exists.called_once_with('confile_file')
18-
assert res is None
18+
# assert res is None
1919

2020

2121
def test_rules_parsing():
@@ -106,8 +106,8 @@ def test_rules_validation(doc, is_valid):
106106

107107

108108
RULES_DATA = [
109-
({'resource': 'server-1234'}, [], []),
110-
({'resource': '1234'},
109+
# ({'resource': 'server-1234', 'event': '5678'}, [], []),
110+
({'resource': '1234', 'event': '5678'},
111111
[{"name": "Test1",
112112
"fields": [{"field": "resource", "regex": r"(\w.*)?\d{4}"}],
113113
"contacts": ["[email protected]"]}],
@@ -126,7 +126,7 @@ def test_rules_evaluation(alert_spec, input_rules, expected_contacts):
126126
mailer.OPTIONS['group_rules'] = input_rules
127127
mail_sender = mailer.MailSender()
128128
with patch.object(mail_sender, '_send_email_message') as _sem:
129-
alert = AlertDocument.parse_alert(alert_spec)
129+
alert = Alert.parse(alert_spec)
130130
_, emailed_contacts = mail_sender.send_email(alert)
131131
assert _sem.call_count == 1
132132
assert emailed_contacts == expected_contacts

Diff for: plugins/slack/test_slack.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
import json
3+
import unittest
4+
5+
from alerta.app import create_app, plugins
6+
from alerta_slack import ServiceIntegration
7+
8+
9+
class SlackPluginTestCase(unittest.TestCase):
10+
11+
def setUp(self):
12+
13+
test_config = {
14+
'TESTING': True,
15+
'AUTH_REQUIRED': False,
16+
'SLACK_WEBHOOK_URL': 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'
17+
}
18+
self.app = create_app(test_config)
19+
self.client = self.app.test_client()
20+
21+
def test_syslog_plugin(self):
22+
23+
plugins.plugins['slack'] = ServiceIntegration()
24+
25+
self.alert = {
26+
'event': 'node_down',
27+
'resource': 'net5',
28+
'environment': 'Production',
29+
'service': ['Network'],
30+
'severity': 'critical',
31+
'correlate': ['node_down', 'node_marginal', 'node_up'],
32+
'tags': []
33+
}
34+
35+
response = self.client.post('/alert', data=json.dumps(self.alert), headers={'Content-type': 'application/json'})
36+
self.assertEqual(response.status_code, 201)
37+
data = json.loads(response.data.decode('utf-8'))
38+
self.assertEqual(data['status'], 'ok')
39+
self.assertRegex(data['id'], '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
40+

Diff for: pylintrc

+250
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
[MASTER]
2+
3+
# Specify a configuration file.
4+
#rcfile=
5+
6+
# Python code to execute, usually for sys.path manipulation such as
7+
# pygtk.require().
8+
#init-hook=
9+
10+
# Profiled execution.
11+
profile=no
12+
13+
# Add files or directories to the blacklist. They should be base names, not
14+
# paths.
15+
ignore=CVS
16+
17+
# Pickle collected data for later comparisons.
18+
persistent=yes
19+
20+
# List of plugins (as comma separated values of python modules names) to load,
21+
# usually to register additional checkers.
22+
load-plugins=
23+
24+
25+
[MESSAGES CONTROL]
26+
27+
# Enable the message, report, category or checker with the given id(s). You can
28+
# either give multiple identifier separated by comma (,) or put this option
29+
# multiple time.
30+
#enable=
31+
32+
# Disable the message, report, category or checker with the given id(s). You
33+
# can either give multiple identifier separated by comma (,) or put this option
34+
# multiple time (only on the command line, not in the configuration file where
35+
# it should appear only once).
36+
#disable=C0111,C0301,E1101
37+
disable=R,W,C,import-error
38+
39+
[REPORTS]
40+
41+
# Set the output format. Available formats are text, parseable, colorized, msvs
42+
# (visual studio) and html
43+
output-format=colorized
44+
45+
# Include message's id in output
46+
include-ids=yes
47+
48+
# Put messages in a separate file for each module / package specified on the
49+
# command line instead of printing them on stdout. Reports (if any) will be
50+
# written in a file name "pylint_global.[txt|html]".
51+
files-output=no
52+
53+
# Tells whether to display a full report or only the messages
54+
reports=yes
55+
56+
# Python expression which should return a note less than 10 (10 is the highest
57+
# note). You have access to the variables errors warning, statement which
58+
# respectively contain the number of errors / warnings messages and the total
59+
# number of statements analyzed. This is used by the global evaluation report
60+
# (RP0004).
61+
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
62+
63+
# Add a comment according to your evaluation note. This is used by the global
64+
# evaluation report (RP0004).
65+
comment=no
66+
67+
68+
[VARIABLES]
69+
70+
# Tells whether we should check for unused import in __init__ files.
71+
init-import=no
72+
73+
# A regular expression matching the beginning of the name of dummy variables
74+
# (i.e. not used).
75+
dummy-variables-rgx=_|dummy
76+
77+
# List of additional names supposed to be defined in builtins. Remember that
78+
# you should avoid to define new builtins when possible.
79+
additional-builtins=
80+
81+
82+
[MISCELLANEOUS]
83+
84+
# List of note tags to take in consideration, separated by a comma.
85+
notes=FIXME,XXX,TODO
86+
87+
88+
[BASIC]
89+
90+
# Required attributes for module, separated by a comma
91+
required-attributes=
92+
93+
# List of builtins function names that should not be used, separated by a comma
94+
bad-functions=map,filter,apply,input
95+
96+
# Regular expression which should only match correct module names
97+
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
98+
99+
# Regular expression which should only match correct module level names
100+
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
101+
102+
# Regular expression which should only match correct class names
103+
class-rgx=[A-Z_][a-zA-Z0-9]+$
104+
105+
# Regular expression which should only match correct function names
106+
function-rgx=[a-z_][a-z0-9_]{2,30}$
107+
108+
# Regular expression which should only match correct method names
109+
method-rgx=[a-z_][a-z0-9_]{2,30}$
110+
111+
# Regular expression which should only match correct instance attribute names
112+
attr-rgx=[a-z_][a-z0-9_]{2,30}$
113+
114+
# Regular expression which should only match correct argument names
115+
argument-rgx=[a-z_][a-z0-9_]{2,30}$
116+
117+
# Regular expression which should only match correct variable names
118+
variable-rgx=[a-z_][a-zA-Z0-9_]{0,30}$
119+
120+
# Regular expression which should only match correct list comprehension /
121+
# generator expression variable names
122+
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
123+
124+
# Good variable names which should always be accepted, separated by a comma
125+
good-names=i,j,k,ex,Run,_,id,f,r
126+
127+
# Bad variable names which should always be refused, separated by a comma
128+
bad-names=foo,bar,baz,toto,tutu,tata
129+
130+
# Regular expression which should only match functions or classes name which do
131+
# not require a docstring
132+
no-docstring-rgx=__.*__
133+
134+
135+
[FORMAT]
136+
137+
# Maximum number of characters on a single line.
138+
max-line-length=80
139+
140+
# Maximum number of lines in a module
141+
max-module-lines=1000
142+
143+
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
144+
# tab).
145+
indent-string=' '
146+
147+
148+
[SIMILARITIES]
149+
150+
# Minimum lines number of a similarity.
151+
min-similarity-lines=4
152+
153+
# Ignore comments when computing similarities.
154+
ignore-comments=yes
155+
156+
# Ignore docstrings when computing similarities.
157+
ignore-docstrings=yes
158+
159+
160+
[TYPECHECK]
161+
162+
# Tells whether missing members accessed in mixin class should be ignored. A
163+
# mixin class is detected if its name ends with "mixin" (case insensitive).
164+
ignore-mixin-members=yes
165+
166+
# List of classes names for which member attributes should not be checked
167+
# (useful for classes with attributes dynamically set).
168+
ignored-classes=SQLObject
169+
170+
# When zope mode is activated, add a predefined set of Zope acquired attributes
171+
# to generated-members.
172+
zope=no
173+
174+
# List of members which are set dynamically and missed by pylint inference
175+
# system, and so shouldn't trigger E0201 when accessed. Python regular
176+
# expressions are accepted.
177+
generated-members=REQUEST,acl_users,aq_parent
178+
179+
180+
[DESIGN]
181+
182+
# Maximum number of arguments for function / method
183+
max-args=10
184+
185+
# Argument names that match this expression will be ignored. Default to name
186+
# with leading underscore
187+
ignored-argument-names=_.*
188+
189+
# Maximum number of locals for function / method body
190+
max-locals=15
191+
192+
# Maximum number of return / yield for function / method body
193+
max-returns=6
194+
195+
# Maximum number of branch for function / method body
196+
max-branchs=12
197+
198+
# Maximum number of statements in function / method body
199+
max-statements=50
200+
201+
# Maximum number of parents for a class (see R0901).
202+
max-parents=7
203+
204+
# Maximum number of attributes for a class (see R0902).
205+
max-attributes=30
206+
207+
# Minimum number of public methods for a class (see R0903).
208+
min-public-methods=1
209+
210+
# Maximum number of public methods for a class (see R0904).
211+
max-public-methods=30
212+
213+
214+
[IMPORTS]
215+
216+
# Deprecated modules which should not be used, separated by a comma
217+
deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
218+
219+
# Create a graph of every (i.e. internal and external) dependencies in the
220+
# given file (report RP0402 must not be disabled)
221+
import-graph=
222+
223+
# Create a graph of external dependencies in the given file (report RP0402 must
224+
# not be disabled)
225+
ext-import-graph=
226+
227+
# Create a graph of internal dependencies in the given file (report RP0402 must
228+
# not be disabled)
229+
int-import-graph=
230+
231+
232+
[CLASSES]
233+
234+
# List of interface methods to ignore, separated by a comma. This is used for
235+
# instance to not check methods defines in Zope's Interface base class.
236+
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
237+
238+
# List of method names used to declare (i.e. assign) instance attributes.
239+
defining-attr-methods=__init__,__new__,setUp
240+
241+
# List of valid names for the first argument in a class method.
242+
valid-classmethod-first-arg=cls
243+
244+
245+
[EXCEPTIONS]
246+
247+
# Exceptions that will emit a warning when being caught. Defaults to
248+
# "Exception"
249+
overgeneral-exceptions=Exception
250+

0 commit comments

Comments
 (0)