-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
40 lines (31 loc) · 1011 Bytes
/
Copy pathconftest.py
File metadata and controls
40 lines (31 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
from unittest.mock import MagicMock, patch
import pytest
SAMPLE_STATE = json.dumps({
'lastModified': 1000,
'colors': [{'hue': 100, 'sat': 255, 'lum': 255}],
'multipler': 'SINGLE_COLOR',
'animation': None,
'lockedBy': None,
})
@pytest.fixture(scope='session')
def flask_app():
mock_redis = MagicMock()
mock_redis.ping.return_value = True
mock_redis.get.return_value = SAMPLE_STATE
with patch('redis.Redis', return_value=mock_redis), \
patch('animator.send'), \
patch('helpers.microcontroller.sendColors', return_value=b'ok'):
import importlib
import server as server_module
importlib.reload(server_module)
server_module.app.config['TESTING'] = True
server_module.r = mock_redis
yield server_module.app
@pytest.fixture
def client(flask_app):
return flask_app.test_client()
@pytest.fixture
def redis_client(flask_app):
import server as server_module
return server_module.r