Skip to content

Commit 32af870

Browse files
author
EvaBardou
committed
Apply Bastien's suggestions + Add tests
1 parent da898e1 commit 32af870

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

.taskcluster.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ tasks:
294294
command:
295295
- /bin/sh
296296
- -lxce
297-
- "git clone --quiet ${repository} /code-review && cd /code-review && git checkout ${head_rev} -b build &&
298-
/bin/sh backend/build.sh ${head_rev} ${head_branch} ${repository} ${channel}"
297+
- "git clone --quiet ${repository} /code-review && cd /code-review && git checkout ${head_rev} -b build
298+
&& backend/build.sh ${head_rev} ${head_branch} ${repository} ${channel}"
299299
artifacts:
300300
public/code-review-backend.tar:
301301
expires: {$fromNow: '2 weeks'}

backend/build.sh

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ printf '{"commit": "%s", "version": "%s", "source": "%s", "build": "%s"}\n' \
1111
"$SOURCE" \
1212
"${TASKCLUSTER_ROOT_URL}/tasks/${TASK_ID}" > backend/code_review_backend/version.json
1313

14+
# Run 'taskboot build' with our local copy of the Git repository where we updated the version.json with correct values.
15+
# To do so, we use '--target /path/to/existing/clone' instead of passing environment variables (GIT_REPOSITORY, GIT_REVISION)
16+
# to taskboot that would activate an automated clone.
1417
taskboot --target /code-review build --image mozilla/code-review --tag "$CHANNEL" --tag "$COMMIT_SHA" --write /backend.tar backend/Dockerfile
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
6+
import json
7+
8+
from django.conf import settings
9+
from django.test import TestCase
10+
11+
12+
class DockerflowEndpointsTestCase(TestCase):
13+
def setUp(self):
14+
self.old_setting = settings.DEBUG
15+
16+
def tearDown(self):
17+
settings.DEBUG = self.old_setting
18+
19+
def test_get_version(self):
20+
response = self.client.get("/__version__")
21+
self.assertEqual(response.status_code, 200)
22+
23+
with open(f"{settings.BASE_DIR}/version.json", "r") as version_file:
24+
self.assertEqual(response.json(), json.loads(version_file.read()))
25+
26+
def test_get_heartbeat_debug(self):
27+
settings.DEBUG = True
28+
29+
response = self.client.get("/__heartbeat__")
30+
self.assertEqual(response.status_code, 200)
31+
32+
# In DEBUG mode, we can retrieve checks details
33+
heartbeat = response.json()
34+
self.assertEqual(heartbeat["status"], "ok")
35+
self.assertTrue("checks" in heartbeat)
36+
self.assertTrue("details" in heartbeat)
37+
38+
def test_get_heartbeat(self):
39+
settings.DEBUG = False
40+
41+
response = self.client.get("/__heartbeat__")
42+
self.assertEqual(response.status_code, 200)
43+
44+
# When DEBUG is False, we can't retrieve checks details and the status is certainly
45+
# equal to "warning" because of the deployment checks that are added:
46+
# https://github.com/mozilla-services/python-dockerflow/blob/e316f0c5f0aa6d176a6d08d1f568f83658b51339/src/dockerflow/django/views.py#L45
47+
self.assertEqual(response.json(), {"status": "warning"})
48+
49+
def test_get_lbheartbeat(self):
50+
response = self.client.get("/__lbheartbeat__")
51+
self.assertEqual(response.status_code, 200)

0 commit comments

Comments
 (0)