forked from department-of-veterans-affairs/wtf-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_wtf.py
55 lines (46 loc) · 1.7 KB
/
tests_wtf.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
import http
import os
import json
import pytest
from wtf import APP
ROUTE = '/slack'
TEST_TOKENS = ['token1', 'token2']
@pytest.fixture
def client():
client = APP.test_client()
APP.config['TESTING'] = True
APP.config['SLACK_TOKENS'] = TEST_TOKENS
yield client
def test_env_vars_present():
for var in ['SLACK_TOKENS', 'DATA_URL']:
assert os.getenv(var) != None
@pytest.mark.parametrize("token", TEST_TOKENS)
def test_good_payload_using_valid_token(client, token):
data = {'text': 'vba','token': token}
r = client.post(ROUTE, data=data)
assert b'Veterans Benefits Administration' in r.data
assert r.status_code == http.HTTPStatus.OK
def test_multi_def_payload(client):
data = {'text': 'aaa','token': TEST_TOKENS[0]}
r = client.post(ROUTE, data=data)
assert b'Abdominal Aortic Aneurysm; or Area Agencies on Aging;' in r.data
def test_comma_in_def(client):
data = {'text': 'acre','token': TEST_TOKENS[0]}
r = client.post(ROUTE, data=data)
assert b'A measure of land 43,560 sq. ft.' in r.data
def test_bad_payload(client):
data = {'foo': 'bar', 'token': TEST_TOKENS[0]}
r = client.post(ROUTE, data=data)
assert b'Improper request' in r.data
assert r.status_code == http.HTTPStatus.BAD_REQUEST
def test_no_slack_token(client):
data = {'text': 'vba','token': 'foobar'}
r = client.post(ROUTE, data=data)
assert b'Not authorized' in r.data
assert r.status_code == http.HTTPStatus.UNAUTHORIZED
def test_not_found(client):
data = {'text': '13231312334','token': TEST_TOKENS[0]}
r = client.post(ROUTE, data=data)
assert b'not found!' in r.data
assert b'13231312334' in r.data
assert r.status_code == http.HTTPStatus.OK