Skip to content

Commit 872a167

Browse files
authored
Fix integration tests (#216)
* Fix unit and integration tests * Fix GitHub Docker Repo auth failure
1 parent bc6a7dd commit 872a167

7 files changed

Lines changed: 40 additions & 25 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ jobs:
3939
- stage: Integration
4040
name: Integration Test
4141
script:
42+
- echo "$GITHUB_TOKEN" | docker login docker.pkg.github.com -u "$DOCKER_USERNAME" --password-stdin
4243
- docker-compose -f docker-compose.ci.yaml build sut
4344
- docker-compose -f docker-compose.ci.yaml up --exit-code-from sut
4445
- docker-compose -f docker-compose.ci.yaml rm --stop --force
4546

46-
4747
after_success:
4848
- coveralls

Dockerfile

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
FROM python:3.7
2-
RUN apt-get update
1+
FROM python:3.8-alpine
32

4-
RUN apt-get install -y \
5-
build-essential \
6-
python3-dev \
3+
RUN apk add --no-cache \
4+
bash \
5+
build-base \
76
libffi-dev \
8-
libssl-dev
7+
openssl-dev \
8+
postgresql-dev \
9+
python3-dev
910

10-
WORKDIR /usr/src/app
11+
COPY . /app
12+
WORKDIR /app
1113

12-
COPY requirements*.txt ./
13-
RUN pip install --no-cache-dir \
14-
-r requirements.txt \
15-
-r requirements-dev.txt
16-
17-
COPY . .
14+
RUN pip install -r requirements.txt
15+
RUN pip install -r requirements-dev.txt
16+
RUN pip install .

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ lint: $(PYLINT) $(MYPY) $(BLACK)
6868
hooks: $(PRE_COMMIT)
6969
$(PRE_COMMIT) run -a
7070

71+
## test - Run all tests.
72+
test: test.unit test.integration
73+
7174
## test.unit - Run unit tests.
7275
test.unit: $(TOX) $(PYTEST)
7376
$(TOX) $(toxparams)
7477

7578
## test.integration - Run integration tests.
76-
test.integration: $(TOX) $(PYTEST)
79+
test.integration:
7780
docker-compose -f docker-compose.ci.yaml rm --stop --force
7881
docker-compose -f docker-compose.ci.yaml build sut
7982
docker-compose -f docker-compose.ci.yaml up --exit-code-from sut

alertaclient/api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,19 @@ def alert_note(self, id, text):
148148
data = {
149149
'text': text
150150
}
151-
return self.http.put('/alert/%s/note' % id, data)
151+
r = self.http.put('/alert/{}/note'.format(id), data)
152+
return Note.parse(r['note'])
152153

153154
def get_alert_notes(self, id, page=1, page_size=None):
154155
r = self.http.get('/alert/{}/notes'.format(id), page=page, page_size=page_size)
155-
return [Note.parse(b) for b in r['notes']]
156+
return [Note.parse(n) for n in r['notes']]
156157

157158
def update_alert_note(self, id, note_id, text):
158159
data = {
159160
'text': text,
160161
}
161-
self.http.put('/alert/{}/note/{}'.format(id, note_id), data)
162+
r = self.http.put('/alert/{}/note/{}'.format(id, note_id), data)
163+
return Note.parse(r['note'])
162164

163165
def delete_alert_note(self, id, note_id):
164166
return self.http.delete('/alert/{}/note/{}'.format(id, note_id))

docker-compose.ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.7'
22

33
services:
44
api:
5-
image: alerta/alerta-web # use API in "alerta-web" image
5+
image: docker.pkg.github.com/alerta/alerta/alerta-api:latest
66
ports:
77
- "8080:8080"
88
depends_on:

tests/integration/test_sdk.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class AlertTestCase(unittest.TestCase):
77

88
def setUp(self):
9-
self.client = Client(endpoint='http://api:8080/api', key='demo-key')
9+
self.client = Client(endpoint='http://api:8080', key='demo-key')
1010

1111
def test_alert(self):
1212
id, alert, message = self.client.send_alert(
@@ -63,8 +63,20 @@ def test_note(self):
6363
environment='Production', resource='web02', event='node_down', correlated=['node_up', 'node_down'],
6464
service=['Web', 'App'], severity='critical', tags=['london', 'linux'], value=4
6565
)
66-
n = self.client.alert_note(id, text='this is a test note')
67-
self.assertEqual(n.text, 'this is a test note')
66+
note = self.client.alert_note(id, text='this is a test note')
67+
self.assertEqual(note.text, 'this is a test note')
68+
69+
notes = self.client.get_alert_notes(id)
70+
self.assertEqual(notes[0].text, 'this is a test note')
71+
self.assertEqual(notes[0].user, 'admin@alerta.io')
72+
73+
note = self.client.update_alert_note(id, notes[0].id, text='updated note text')
74+
self.assertEqual(note.text, 'updated note text')
75+
76+
self.client.delete_alert_note(id, notes[0].id)
77+
78+
notes = self.client.get_alert_notes(id)
79+
self.assertEqual(notes, [])
6880

6981
def test_permission(self):
7082
perm = self.client.create_perm(role='websys', scopes=['admin:users', 'admin:keys', 'write'])

tests/unit/test_notes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ def setUp(self):
4040
@requests_mock.mock()
4141
def test_add_note(self, m):
4242
m.put('http://localhost:8080/alert/e7020428-5dad-4a41-9bfe-78e9d55cda06/note', text=self.note)
43-
r = self.client.alert_note(id='e7020428-5dad-4a41-9bfe-78e9d55cda06', text='this is a new note')
44-
self.assertEqual(r['status'], 'ok')
45-
self.assertEqual(r['note']['text'], 'this is a new note')
43+
note = self.client.alert_note(id='e7020428-5dad-4a41-9bfe-78e9d55cda06', text='this is a new note')
44+
self.assertEqual(note.text, 'this is a new note')

0 commit comments

Comments
 (0)