Merge branch 'aureplop/ci_parallel' into 'master'

core.ci -- Run tests in parallel

See merge request klub-dev-ens/gestioCOF!327
This commit is contained in:
Martin Pepin 2019-01-05 19:36:20 +01:00
commit e0e75b53bb
2 changed files with 24 additions and 15 deletions

View file

@ -27,10 +27,10 @@ test:
- sed -i.bak -E 's;^REDIS_PASSWD = .*$;REDIS_PASSWD = "";' cof/settings/secret.py - sed -i.bak -E 's;^REDIS_PASSWD = .*$;REDIS_PASSWD = "";' cof/settings/secret.py
# Remove the old test database if it has not been done yet # Remove the old test database if it has not been done yet
- psql --username=$POSTGRES_USER --host=$DBHOST -c "DROP DATABASE IF EXISTS test_$POSTGRES_DB" - psql --username=$POSTGRES_USER --host=$DBHOST -c "DROP DATABASE IF EXISTS test_$POSTGRES_DB"
- pip install --upgrade -r requirements.txt coverage - pip install --upgrade -r requirements.txt coverage tblib
- python --version - python --version
script: script:
- coverage run manage.py test - coverage run manage.py test --parallel
after_script: after_script:
- coverage report - coverage report
services: services:

View file

@ -1,4 +1,5 @@
import json import json
import threading
from datetime import timedelta from datetime import timedelta
from unittest import mock from unittest import mock
@ -8,7 +9,7 @@ from django.contrib.auth.models import AnonymousUser, Permission, User
from django.test import Client from django.test import Client
from django.utils import timezone from django.utils import timezone
from . import OpenKfet, kfet_open from . import OpenKfet
from .consumers import OpenKfetConsumer from .consumers import OpenKfetConsumer
@ -16,10 +17,10 @@ class OpenKfetTest(ChannelTestCase):
"""OpenKfet object unit-tests suite.""" """OpenKfet object unit-tests suite."""
def setUp(self): def setUp(self):
self.kfet_open = OpenKfet() self.kfet_open = OpenKfet(
cache_prefix="test_kfetopen_%s" % threading.get_ident()
def tearDown(self): )
self.kfet_open.clear_cache() self.addCleanup(self.kfet_open.clear_cache)
def test_defaults(self): def test_defaults(self):
"""Default values.""" """Default values."""
@ -136,8 +137,14 @@ class OpenKfetViewsTest(ChannelTestCase):
self.c_a = Client() self.c_a = Client()
self.c_a.login(username="admin", password="admin") self.c_a.login(username="admin", password="admin")
def tearDown(self): self.kfet_open = OpenKfet(
kfet_open.clear_cache() cache_prefix="test_kfetopen_%s" % threading.get_ident()
)
self.addCleanup(self.kfet_open.clear_cache)
views_patcher = mock.patch("kfet.open.views.kfet_open", self.kfet_open)
views_patcher.start()
self.addCleanup(views_patcher.stop)
def test_door(self): def test_door(self):
"""Edit raw_status.""" """Edit raw_status."""
@ -146,14 +153,14 @@ class OpenKfetViewsTest(ChannelTestCase):
"/k-fet/open/raw_open", {"raw_open": sent, "token": "plop"} "/k-fet/open/raw_open", {"raw_open": sent, "token": "plop"}
) )
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
self.assertEqual(expected, kfet_open.raw_open) self.assertEqual(expected, self.kfet_open.raw_open)
def test_force_close(self): def test_force_close(self):
"""Edit force_close.""" """Edit force_close."""
for sent, expected in [(1, True), (0, False)]: for sent, expected in [(1, True), (0, False)]:
resp = self.c_a.post("/k-fet/open/force_close", {"force_close": sent}) resp = self.c_a.post("/k-fet/open/force_close", {"force_close": sent})
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
self.assertEqual(expected, kfet_open.force_close) self.assertEqual(expected, self.kfet_open.force_close)
def test_force_close_forbidden(self): def test_force_close_forbidden(self):
"""Can't edit force_close without kfet.can_force_close permission.""" """Can't edit force_close without kfet.can_force_close permission."""
@ -236,8 +243,10 @@ class OpenKfetScenarioTest(ChannelTestCase):
self.r_c_ws = WSClient() self.r_c_ws = WSClient()
self.r_c_ws.force_login(self.r) self.r_c_ws.force_login(self.r)
def tearDown(self): self.kfet_open = OpenKfet(
kfet_open.clear_cache() cache_prefix="test_kfetopen_%s" % threading.get_ident()
)
self.addCleanup(self.kfet_open.clear_cache)
def ws_connect(self, ws_client): def ws_connect(self, ws_client):
ws_client.send_and_consume( ws_client.send_and_consume(
@ -288,8 +297,8 @@ class OpenKfetScenarioTest(ChannelTestCase):
def test_scenario_2(self): def test_scenario_2(self):
"""Starting falsely closed, clients connect, disable force close.""" """Starting falsely closed, clients connect, disable force close."""
kfet_open.raw_open = True self.kfet_open.raw_open = True
kfet_open.force_close = True self.kfet_open.force_close = True
msg = self.ws_connect(self.c_ws) msg = self.ws_connect(self.c_ws)
self.assertEqual(OpenKfet.CLOSED, msg["status"]) self.assertEqual(OpenKfet.CLOSED, msg["status"])