-
Notifications
You must be signed in to change notification settings - Fork 0
/
#test_loadbalancer.py#
72 lines (52 loc) · 2.45 KB
/
#test_loadbalancer.py#
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# test_loadbalancer.py
import json
import pytest
from loadbalancer import loadbalancer
@pytest.fixture
def client():
with loadbalancer.test_client() as client:
yield client
def test_host_routing_mango(client):
result = client.get('/', headers={'Host': 'www.mango.com'}, query_string={'RemoveMe': 'Remove'})
data = json.loads(result.data.decode())
assert 'This is the mango application.' in data['message']
assert data['server'] in ['http://localhost:8082/', 'http://localhost:8081/']
assert data['custom_header'] == 'Test'
assert data['host_header'] in ['localhost:8082', 'localhost:8081']
assert data['query_strings'] == 'MyCustomParam=Test'
assert data['custom_params'] == 'Test'
def test_host_routing_apple(client):
result = client.get('/', headers={'Host': 'www.apple.com'})
data = json.loads(result.data.decode())
assert 'This is the apple application.' in data['message']
assert data['server'] in ['http://localhost:9082/', 'http://localhost:9081/']
assert not data['custom_header']
assert data['host_header'] in ['localhost:9082', 'localhost:9081']
def test_host_routing_orange(client):
result = client.get('/', headers={'Host': 'www.orange.com'})
assert b'No backend servers available.' in result.data
def test_host_routing_notfound(client):
result = client.get('/', headers={'Host': 'www.notmango.com'})
assert b'Not Found' in result.data
assert 404 == result.status_code
def test_path_routing_mango(client):
result = client.get('/mango')
data = json.loads(result.data.decode())
assert 'This is the mango application.' in data['message']
assert data['server'] in ['http://localhost:8082/', 'http://localhost:8081/']
assert not data['custom_header']
assert data['host_header'] in ['localhost:8082', 'localhost:8081']
def test_path_routing_apple(client):
result = client.get('/apple')
data = json.loads(result.data.decode())
assert 'This is the apple application.' in data['message']
assert data['server'] in ['http://localhost:9082/', 'http://localhost:9081/']
assert not data['custom_header']
assert data['host_header'] in ['localhost:9082', 'localhost:9081']
def test_path_routing_orange(client):
result = client.get('/orange')
assert b'No backend servers available.' in result.data
def test_path_routing_notfound(client):
result = client.get('/notmango')
assert b'Not Found' in result.data
assert 404 == result.status_code