summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonas Haag <jonas@lophus.org>2015-10-07 17:25:02 +0200
committerJonas Haag <jonas@lophus.org>2015-10-07 17:25:09 +0200
commitaf284ee2221e5bb6c01097da688f738ba4458309 (patch)
tree55d3d3a0eda2dc149f3df3834a9d0818fe64d276 /tests
parent1ac6ccaeaccdda7b0f1713f43e49295ea36bb7d8 (diff)
Add ctags tests
Diffstat (limited to 'tests')
-rwxr-xr-xtests/repos/scripts/test_repo13
-rw-r--r--tests/test_ctags.py5
-rw-r--r--tests/test_make_app.py52
-rw-r--r--tests/test_views.py2
4 files changed, 61 insertions, 11 deletions
diff --git a/tests/repos/scripts/test_repo b/tests/repos/scripts/test_repo
index 04d59ae..141df97 100755
--- a/tests/repos/scripts/test_repo
+++ b/tests/repos/scripts/test_repo
@@ -1,6 +1,13 @@
#!/bin/bash -e
git init
-echo Hello World > README
-git add README
-git commit -m "First commit"
+echo "int a;" > test.c
+echo "function test() {}" > test.js
+git add test.c
+git add test.js
+git commit -m "Add some code"
+
+git commit --allow-empty -m "Empty commit 1"
+git tag tag1
+
+git commit --allow-empty -m "Empty commit 2"
diff --git a/tests/test_ctags.py b/tests/test_ctags.py
new file mode 100644
index 0000000..725cbc3
--- /dev/null
+++ b/tests/test_ctags.py
@@ -0,0 +1,5 @@
+from io import BytesIO
+import requests
+import tarfile
+import contextlib
+from .utils import *
diff --git a/tests/test_make_app.py b/tests/test_make_app.py
index caa210d..6ceef4b 100644
--- a/tests/test_make_app.py
+++ b/tests/test_make_app.py
@@ -1,4 +1,5 @@
import os
+import re
import subprocess
import tempfile
import shutil
@@ -34,14 +35,15 @@ def test_unauthenticated_push_with_disable_push():
def options_test(make_app_args, expected_permissions):
def test():
with serve(**make_app_args):
- for action, permitted in expected_permissions.items():
- if action.endswith('auth'):
- actions = [action]
+ for check, permitted in expected_permissions.items():
+ if check in globals():
+ checks = [check]
+ elif check.endswith('auth'):
+ checks = ['can_%s' % check]
else:
- actions = [action + '_unauth', action + '_auth']
- for action in actions:
- funcname = 'can_%s' % action
- assert globals()[funcname]() == permitted
+ checks = ['can_%s_unauth' % check, 'can_%s_auth' % check]
+ for check in checks:
+ assert globals()[check]() == permitted
return test
@@ -74,6 +76,19 @@ test_smart_auth_disable_push = options_test(
{'reach_auth': True, 'reach_unauth': False, 'clone_auth': True, 'clone_unauth': False, 'push': False}
)
+test_ctags_disabled = options_test(
+ {},
+ {'ctags_tags_and_branches': False, 'ctags_all': False}
+)
+test_ctags_tags_and_branches = options_test(
+ {'ctags_policy': 'tags-and-branches'},
+ {'ctags_tags_and_branches': True, 'ctags_all': False}
+)
+test_ctags_all = options_test(
+ {'ctags_policy': 'ALL'},
+ {'ctags_tags_and_branches': True, 'ctags_all': True}
+)
+
# Reach
def can_reach_unauth():
@@ -117,6 +132,29 @@ def _can_push(http_get, url):
])
+# Ctags
+def ctags_tags_and_branches():
+ return all(
+ _ctags_enabled(ref, f)
+ for ref in ["master", "tag1"] for f in ["test.c", "test.js"]
+ )
+
+
+def ctags_all():
+ all_refs = re.findall('href=".+/commit/([a-z0-9]{40})/">',
+ requests.get(UNAUTH_TEST_REPO_URL).content)
+ assert len(all_refs) == 3
+ return all(
+ _ctags_enabled(ref, f)
+ for ref in all_refs for f in ["test.c", "test.js"]
+ )
+
+def _ctags_enabled(ref, filename):
+ response = requests.get(UNAUTH_TEST_REPO_URL + "blob/%s/%s" % (ref, filename))
+ href = '<a href="/%sblob/%s/%s#L-1">' % (TEST_REPO_URL, ref, filename)
+ return href in response.content
+
+
def _GET_unauth(url=""):
return requests.get(UNAUTH_TEST_SERVER + url, auth=requests.auth.HTTPDigestAuth("invalid", "password"))
diff --git a/tests/test_views.py b/tests/test_views.py
index 9ac931b..f729c55 100644
--- a/tests/test_views.py
+++ b/tests/test_views.py
@@ -11,7 +11,7 @@ def test_download():
response_body = BytesIO(response.raw.read())
tarball = tarfile.TarFile.gzopen("test.tar.gz", fileobj=response_body)
with contextlib.closing(tarball):
- assert tarball.extractfile('README').read() == b'Hello World\n'
+ assert tarball.extractfile('test.c').read() == b'int a;\n'
def test_no_newline_at_end_of_file():