-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
92 lines (75 loc) · 2.33 KB
/
test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import json
import os
import unittest
from bottle import request, BottleException, HTTPResponse
from requests import get, post
import responses
#Set environment variables before importing server
os.environ['CLIENT_ID'] = '3ab60c1b74db358e9527'
os.environ['CLIENT_SECRET'] = '3ed64d186697b5bdc18de444949e9a6b258eedc8'
os.environ['DISTRICT_ID'] = '0944b6201000003ce'
import server
ACCESS_TOKEN_RESPONSE = {
"access_token": "abc123"
}
ME_RESPONSE = {
"data": {
"district": "55108ad78349a40100000022",
"id": "55108b7a63886c0f0034efc9",
"type": "student"
},
"links": [
{
"rel": "self",
"uri": "/me"
},
{
"rel": "canonical",
"uri": "/v1.1/students/55108b7a63886c0f0034efc9"
},
{
"rel": "district",
"uri": "/v1.1/districts/55108ad78349a40100000022"
}
],
"type": "student"
}
NAME_RESPONSE = {
"data": {
"name": {
"first": "Aaron",
"middle": "B",
"last": "McClure"
}
}
}
class TestServer(unittest.TestCase):
def testIndex(self):
assert 'https://clever.com/oauth/authorize' in server.index()
@responses.activate
def testOauth(self):
responses.add(responses.POST, 'https://clever.com/oauth/tokens',
body=json.dumps(ACCESS_TOKEN_RESPONSE), status=200,
content_type='application/json')
responses.add(responses.GET, 'https://api.clever.com/me',
body=json.dumps(ME_RESPONSE), status=200,
content_type='application/json')
responses.add(responses.GET, 'https://api.clever.com/v1.1/students/%s'%ME_RESPONSE['data']['id'],
body=json.dumps(NAME_RESPONSE), status=200,
content_type='application/json')
server.request.query['code'] = 'foo'
server.request.environ['beaker.session'] = {}
# Bottle redirects are raised BottleExceptions, for some reason.
try:
server.oauth()
except BottleException, e:
assert type(e) == HTTPResponse
def testApp(self):
server.request.environ['beaker.session'] = {}
assert "You must be logged in" in server.app()
server.request.environ['beaker.session'] = {
'nameObject': NAME_RESPONSE['data']['name']
}
assert "Aaron McClure" in server.app()
if __name__ == '__main__':
unittest.main()