-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
113 lines (89 loc) · 3.95 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from http import client
import json
from unittest import TestCase
import unittest
from flask import request,session
from sqlalchemy import null, true
from app import app
from forms import PaymentDetails
from models import Student, db,connect_db,Teacher
import stripe
import os
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
API_KEY=os.getenv('API_KEY')
stripe.api_key=API_KEY
app.config['WTF_CSRF_ENABLED'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///teach'
app.config['SQLALCHEMY_ECHO'] = False
app.config['TESTING'] = True
app.config['DEBUG_TB_HOSTS'] = ['dont-show-debug-toolbar']
class OnBoarding(TestCase):
def tearDown(self):
user= Student.query.filter_by(username="tester91").first() if Student.query.filter_by(username="tester91").first() else Teacher.query.filter_by(username="teachertest").first()
if user.username == "tester91":
db.session.query(Student).filter(Student.username=="tester91").delete()
db.session.commit()
else:
db.session.query(Teacher).filter(Teacher.username=="teachertest").delete()
db.session.commit()
def test_student_signup(self):
with app.test_client() as client:
resp=client.post("/student/signup",data={
"username":"tester91",
"email":"[email protected]",
"password":"123456"
}, follow_redirects=True)
self.assertEqual(resp.status_code, 200)
self.assertIn("/get-started/payment",request.path)
s=Student.query.filter_by(username='tester91').first()
print(s.id)
self.assertIsNotNone(session['curr_user'])
def test_teacher_signup(self):
with app.test_client() as client:
resp=client.post("/teacher/signup",data={
"username":"teachertest",
"email":"[email protected]",
"password":"123456"
}, follow_redirects=True)
teacher=Teacher.query.filter_by(username="teachertest").first()
self.assertEqual(resp.status_code, 200)
self.assertIn("/teacher/plan/prices",request.path)
self.assertEqual(session['curr_user'],teacher.stripe_id)
class TeacherStripeOnboarding(TestCase):
def setUp(self):
with app.test_client() as client:
resp=client.post("/teacher/signup",data={
"username":"stripe_testuser",
"email": "[email protected]",
"password": "123456"
})
def tearDown(self):
teacher=Teacher.query.filter_by(username="stripe_testuser").first()
stripe.Customer.delete(teacher.stripe_id)
db.session.query(Teacher).filter(Teacher.username=="stripe_testuser").delete()
db.session.commit()
def test_teacher_signup(self):
teacher=Teacher.query.filter_by(username="stripe_testuser").first()
self.assertIsNotNone(teacher.stripe_id)
def test_teacher_subscription(self):
with app.test_client() as client:
with client.session_transaction() as sess:
teacher=Teacher.query.filter_by(username="stripe_testuser").first()
sess["curr_user"]=teacher.stripe_id
resp=client.post("/teacher/plan/prices",data={
'plan': "prod_L3c8LwHYwslzi1",
'name':'Michael Wiltfong',
'card_number':"4242424242424242",
'expiration':'01/25',
'city':'Kanata',
'state':'AL',
'country':'US',
'address_1':'8 Bishops Mills Way',
'address_2':None,
'postal_code':'K2K3B9'
})
html=resp.get_data(as_text=true)
## TODO: This test is not passing the form.validate function.
self.assertIn("TEST",html)
self.assertEqual(resp.status_code,200)