From 1b24f84055cfdf00e751ad37780d7fe8ee735d0a Mon Sep 17 00:00:00 2001
From: Julian Rother <julian@jrother.eu>
Date: Fri, 23 Jul 2021 18:42:32 +0200
Subject: [PATCH] Added dummy test and test CI job

---
 .gitignore          | 12 ++++++++++++
 .gitlab-ci.yml      | 24 ++++++++++++++++++++++--
 tests/test_dummy.py |  8 ++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)
 create mode 100644 tests/test_dummy.py

diff --git a/.gitignore b/.gitignore
index 04aa2b0..3220182 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,18 @@
 docs/_build/
 dist/
 
+# coverage
+.coverage
+htmlcov
+coverage.xml
+
+# pytest
+report.xml
+
+# pylint
+pylint.html
+codeclimate.json
+
 *.egg-info
 __pycache__
 *.pyc
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3f9e37d..6717ddc 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,7 +2,7 @@ linter:
   stage: test
   image: python:3.7
   script:
-  - pip3 install pylint-gitlab # this force-updates jinja2 and some other packages!
+  - pip install pylint-gitlab
   - python3 -m pylint --exit-zero --rcfile .pylintrc --output-format=pylint_gitlab.GitlabCodeClimateReporter src/ldapserver > codeclimate.json || true
   - python3 -m pylint --exit-zero --rcfile .pylintrc --output-format=pylint_gitlab.GitlabPagesHtmlReporter src/ldapserver > pylint.html || true
   - python3 -m pylint --rcfile .pylintrc --output-format=text src/ldapserver
@@ -14,8 +14,28 @@ linter:
     reports:
       codequality: codeclimate.json
 
+test:
+  stage: test
+  image: python:3.7
+  script:
+  - pip install pytest coverage
+  - PYTHONPATH=src coverage run --include 'src/*.py' -m pytest --junitxml=report.xml
+  - coverage report -m
+  - coverage html
+  - coverage xml
+  artifacts:
+    when: always
+    paths:
+    - htmlcov/index.html
+    - htmlcov
+    expose_as: 'Coverage Report'
+    reports:
+      cobertura: coverage.xml
+      junit: report.xml
+  coverage: '/^TOTAL.*\s+(\d+\%)$/'
+
 build-docs:
-  stage: build
+  stage: deploy
   image: python:3.7
   script:
   - pip install Sphinx sphinx-rtd-theme
diff --git a/tests/test_dummy.py b/tests/test_dummy.py
new file mode 100644
index 0000000..6308729
--- /dev/null
+++ b/tests/test_dummy.py
@@ -0,0 +1,8 @@
+import unittest
+
+# Test if imports work in tests
+from ldapserver.dn import DN
+
+class TestDummy(unittest.TestCase):
+	def test_dummy(self):
+		DN('cn=foobar') == DN('CN=foobar')
-- 
GitLab