|
| 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