-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathunittests.py
104 lines (90 loc) · 3.69 KB
/
unittests.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
from profapp import create_app
from flask import g
# from cit.db import db
from unittest import TestCase as Base
# import init_db
from sqlalchemy.orm import sessionmaker
from sqlalchemy_utils import drop_database
from sqlalchemy import create_engine
from config import database_uri, Config, TestingConfig
import sqlalchemy.exc as sqlalchemy_exc
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT,\
ISOLATION_LEVEL_READ_COMMITTED
import json
engine = create_engine(database_uri(Config.host, Config.username, Config.password, 'postgres'))
class TestCase(Base):
app = None
@classmethod
def setUpClass(cls):
# cls.app = create_app(config='config.TestingConfig')
cls.app = create_app(host=args.host, front=args.front, config='config.TestingConfig')
cls.client = cls.app.test_client()
cls._ctx = cls.app.test_request_context()
cls._ctx.push()
session = sessionmaker(bind=engine)()
@classmethod
def tearDownClass(cls):
# g.db.close()
# g.db.remove()
message = 'All tests has been run. '
print(message)
def setUp(self):
self._ctx = self.app.test_request_context()
self._ctx.push()
def tearDown(self):
# g.db.rollback()
# g.db.close()
self._ctx.pop()
class TestModel(TestCase):
def test_add_comment_unauth_user(self):
# comment = dict(issue_id=1, msg='test test')
#
# response = self.client.post('/comments/', data=comment)
#
# message_init = 'A problem with adding comment by unauthorised user.\n'
#
# message = message_init + \
# "response.status_code isn't equal to 401."
# TestCase.assertEqual(self, response.status_code, 401, msg=message)
#
# message = message_init + \
# "response.data doesn't contain message 'Permission denied'."
# TestCase.assertIn(self, 'Permission denied',
# response.data, msg=message)
return True
def test_add_comment_auth_user_1(self):
# user_id = 2 # this user doesn't have superuser rights
# issue_id = 1
# with self.client as c:
# with c.session_transaction() as sess:
# sess['user_id'] = user_id
# comment = dict(issue_id=issue_id, msg='test test')
# response = c.post('/comments/', data=comment)
# with c.session_transaction() as sess:
# sess.pop('user_id', None)
#
# response_in_json = json.loads(response.data)
# comment_id = response_in_json['id']
# comment_from_db = Comment.query.filter_by(id=comment_id).first()
#
# message = 'A problem with adding comment by authorised user.\n' + \
# "response.status_code isn't equal to 201."
# TestCase.assertEqual(self, response.status_code, 201, msg=message)
#
# message = 'A problem with adding comment by authorised user to DB.'
# expr = (str(comment['issue_id']) == comment_from_db.issue_id) and\
# (comment['msg'] == comment_from_db.message)
# TestCase.assertTrue(self, expr, msg=message)
return True
if __name__ == "__main__":
import unittest
import argparse
parser = argparse.ArgumentParser()
# parser = argparse.ArgumentParser(prog='unittests')
parser.add_argument("--host", help="host", default='profireader.com')
parser.add_argument("--port", help="port", default='8080', type=int)
parser.add_argument("--front", help="frontend", default='n')
args = parser.parse_args()
# unittest.main(host='0.0.0.0', port=args.port, debug=False)
# --host=profireader.com --port=8080 --front=n
unittest.main()