Skip to content

Commit c345817

Browse files
mrsaicharan1abhinavk96
authored andcommitted
test: Unit test for logs helper file (fossasia#5603)
1 parent a04dbc3 commit c345817

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from tests.all.integration.setup_database import Setup
2+
from app import current_app as app
3+
from tests.all.integration.utils import OpenEventTestCase
4+
from app.api.helpers.log import record_activity
5+
from app.models.activity import Activity
6+
from tests.all.integration.auth_helper import create_user
7+
from app.models import db
8+
9+
import unittest
10+
11+
12+
class TestLogging(OpenEventTestCase):
13+
def setUp(self):
14+
self.app = Setup.create_app()
15+
16+
def test_record_activity_valid_template(self):
17+
"""Test to record activity for valid template"""
18+
with app.test_request_context():
19+
test_user = create_user(email="logging@test.com", password="logpass")
20+
record_activity('create_user', login_user=test_user, user=test_user)
21+
user_id_format = ' (' + str(test_user.id) + ')'
22+
test_actor = test_user.email + user_id_format
23+
self.assertTrue('User logging@test.com' + user_id_format + ' created',
24+
db.session.query(Activity).filter_by(actor=test_actor).first().action)
25+
26+
def test_record_activity_invalid_template(self):
27+
"""Test to record activity for invalid template"""
28+
with app.test_request_context():
29+
test_user = create_user(email="logging@test.com", password="logpass")
30+
record_activity('invalid_template', login_user=test_user, user=test_user)
31+
user_id_format = ' (' + str(test_user.id) + ')'
32+
test_actor = test_user.email + user_id_format
33+
self.assertTrue('[ERROR LOGGING] invalid_template',
34+
db.session.query(Activity).filter_by(actor=test_actor).first().action)
35+
36+
37+
if __name__ == '__main__':
38+
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy