changeset 7681:ea799beea5dd

tests: better coverage of UserLog action logging
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 16 Jan 2019 02:32:33 +0100
parents 1660b2c71e03
children f8c0549df529
files kallithea/tests/other/test_vcs_operations.py
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/tests/other/test_vcs_operations.py	Wed Jan 16 02:11:55 2019 +0100
+++ b/kallithea/tests/other/test_vcs_operations.py	Wed Jan 16 02:32:33 2019 +0100
@@ -329,6 +329,9 @@
 
     @parametrize_vcs_test
     def test_push_new_file(self, webserver, testfork, vt):
+        UserLog.query().delete()
+        Session().commit()
+
         dest_dir = _get_tmp_dir()
         clone_url = vt.repo_url_param(webserver, vt.repo_name)
         stdout, stderr = Command(TESTS_TMP_PATH).execute(vt.repo_type, 'clone', clone_url, dest_dir)
@@ -337,13 +340,16 @@
         stdout, stderr = _add_files_and_push(webserver, vt, dest_dir, clone_url=clone_url)
 
         if vt.repo_type == 'git':
-            print [(x.repo_full_path, x.repo_path) for x in Repository.query()]  # TODO: what is this for
             _check_proper_git_push(stdout, stderr)
         elif vt.repo_type == 'hg':
             assert 'pushing to' in stdout
             assert 'Repository size' in stdout
             assert 'Last revision is now' in stdout
 
+        action_parts = [ul.action.split(':', 1) for ul in UserLog.query().order_by(UserLog.user_log_id)]
+        assert [(t[0], (t[1].count(',') + 1) if len(t) == 2 else 0) for t in action_parts] == \
+            [(u'pull', 0), (u'push', 3)]
+
     @parametrize_vcs_test
     def test_push_invalidates_cache(self, webserver, testfork, vt):
         key = CacheInvalidation.query().filter(CacheInvalidation.cache_key
@@ -384,6 +390,9 @@
 
     @parametrize_vcs_test
     def test_push_with_readonly_credentials(self, webserver, vt):
+        UserLog.query().delete()
+        Session().commit()
+
         dest_dir = _get_tmp_dir()
         clone_url = vt.repo_url_param(webserver, vt.repo_name, username=TEST_USER_REGULAR_LOGIN, password=TEST_USER_REGULAR_PASS)
         stdout, stderr = Command(TESTS_TMP_PATH).execute(vt.repo_type, 'clone', clone_url, dest_dir)
@@ -395,6 +404,10 @@
         elif vt.repo_type == 'hg':
             assert 'abort: HTTP Error 403: Forbidden' in stderr
 
+        action_parts = [ul.action.split(':', 1) for ul in UserLog.query().order_by(UserLog.user_log_id)]
+        assert [(t[0], (t[1].count(',') + 1) if len(t) == 2 else 0) for t in action_parts] == \
+            [(u'pull', 0)]
+
     @parametrize_vcs_test
     def test_push_back_to_wrong_url(self, webserver, vt):
         dest_dir = _get_tmp_dir()