forked from tomekp/warsjawa2014backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflaskr_tests.py
83 lines (64 loc) · 2.22 KB
/
flaskr_tests.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
# -*- coding: utf-8 -*-
import datetime
import unittest
import mongomock
from emails import EmailMessage
import flaskr
NAME = "Jan Kowalski"
EMAIL_ADDRESS = "[email protected]"
TEST_KEY = "TEST_KEY"
FIRST_MAIL_SUBJECT = "Introduction to test workshop"
SECOND_MAIL_SUBJECT = "Link to repository"
WORKSHOP_ID = "test_workshop"
WORKSHOP_EMAIL_SECRET = "tajny-kod"
CURRENT_DATE = datetime.datetime(2007, 12, 6, 16, 29, 43, 79043)
EMAIL_MESSAGE = EmailMessage(FIRST_MAIL_SUBJECT, "text", sender="[email protected]", date=CURRENT_DATE, email_id=1)
def user_in_db(confirmed=False):
return {
"email": EMAIL_ADDRESS,
"name": NAME,
"key": TEST_KEY,
"isConfirmed": confirmed,
"emails": []
}
def workshop_in_db(with_user, with_mail):
return {
"workshopId": WORKSHOP_ID,
"emailSecret": WORKSHOP_EMAIL_SECRET,
"mentors": [
],
"users": [EMAIL_ADDRESS] if with_user else [],
"emails": [EMAIL_MESSAGE] if with_mail else []
}
EMAILS = {"emails": [{"from": "[email protected]", "subject": FIRST_MAIL_SUBJECT, "text": "text",
"date": "Thu, 06 Dec 2007 16:29:43 GMT"}]}
REGISTER_EMAIL_REQUEST = """{
"subject": "%s",
"text": "text"
}""" % SECOND_MAIL_SUBJECT
EXAMPLE_MAILGUN_POST = {
'from': 'Jan Kowalski <[email protected]>',
'to': 'Warsjawa',
'subject': SECOND_MAIL_SUBJECT,
'recipient': 'test-workshop-%[email protected]' % WORKSHOP_EMAIL_SECRET,
'body-plain': 'text',
'body-html': 'text'
}
class FlaskrWithMongoTest():
def setUp(self):
def get_db():
return self.db
self.app = flaskr.app.test_client()
self.db = mongomock.Connection().db
flaskr.get_db = get_db
def assert_mailgun(requests_mock, to=None, subject=None):
((mailgun_url, ), mailgun_attrs) = requests_mock.post.call_args
assert "https://api.mailgun.net/v2/system.warsjawa.pl/messages" == mailgun_url
if to is not None:
assert to == mailgun_attrs['data']['to']
if subject is not None:
assert subject == mailgun_attrs['data']['subject']
if __name__ == '__main__':
unittest.main()