Skip to content

Commit

Permalink
Merge 01c1f41 into 2bc2d74
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Jun 22, 2021
2 parents 2bc2d74 + 01c1f41 commit b2e65da
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 33 deletions.
28 changes: 20 additions & 8 deletions Makefile
@@ -1,6 +1,14 @@
KIWI_INCLUDE_PATH="../Kiwi/"


.PHONY: test
test:
PYTHONWARNINGS=d EXECUTOR=standard AUTO_CREATE_SCHEMA='' coverage run \
if [ ! -d "$(KIWI_INCLUDE_PATH)/kiwi_lint" ]; then \
git clone --depth 1 https://github.com/kiwitcms/Kiwi.git $(KIWI_INCLUDE_PATH); \
pip install -U -r $(KIWI_INCLUDE_PATH)/requirements/base.txt; \
fi

PYTHONPATH=$(KIWI_INCLUDE_PATH) PYTHONWARNINGS=d EXECUTOR=standard AUTO_CREATE_SCHEMA='' coverage run \
--include "tcms_github_app/*.py" \
--omit "tcms_github_app/tests/*.py" \
./manage.py test -v2 tcms_github_app.tests
Expand All @@ -11,23 +19,27 @@ flake8:
# ignore "line too long"
@flake8 --exclude=$(FLAKE8_EXCLUDE) --ignore=E501 tcms_github_app/

KIWI_LINT_INCLUDE_PATH="../Kiwi/"

.PHONY: pylint
pylint:
if [ ! -d "$(KIWI_LINT_INCLUDE_PATH)/kiwi_lint" ]; then \
git clone --depth 1 https://github.com/kiwitcms/Kiwi.git $(KIWI_LINT_INCLUDE_PATH); \
if [ ! -d "$(KIWI_INCLUDE_PATH)/kiwi_lint" ]; then \
git clone --depth 1 https://github.com/kiwitcms/Kiwi.git $(KIWI_INCLUDE_PATH); \
pip install -U -r $(KIWI_INCLUDE_PATH)/requirements/base.txt; \
fi

PYTHONPATH=$(KIWI_LINT_INCLUDE_PATH) DJANGO_SETTINGS_MODULE="test_project.settings" \
PYTHONPATH=$(KIWI_INCLUDE_PATH) DJANGO_SETTINGS_MODULE="test_project.settings" \
pylint --load-plugins=pylint_django --load-plugins=kiwi_lint -d similar-string \
-d missing-docstring -d duplicate-code -d module-in-directory-without-init \
*.py tcms_github_app/ test_project/ tcms_settings_dir/

.PHONY: test_for_missing_migrations
test_for_missing_migrations:
./manage.py migrate
./manage.py makemigrations --check
if [ ! -d "$(KIWI_INCLUDE_PATH)/kiwi_lint" ]; then \
git clone --depth 1 https://github.com/kiwitcms/Kiwi.git $(KIWI_INCLUDE_PATH); \
pip install -U -r $(KIWI_INCLUDE_PATH)/requirements/base.txt; \
fi

PYTHONPATH=$(KIWI_INCLUDE_PATH) ./manage.py migrate
PYTHONPATH=$(KIWI_INCLUDE_PATH) ./manage.py makemigrations --check

.PHONY: check
check: flake8 pylint test_for_missing_migrations test
Expand Down
11 changes: 11 additions & 0 deletions README.rst
Expand Up @@ -107,6 +107,17 @@ Then configure how the application interacts with GitHub:
Changelog
---------


v1.3.0 (14 Feb 2021)
~~~~~~~~~~~~~~~~~~~~

- Migrate to Python 3.8
- Always test with the latest Kiwi TCMS version
- Adjustments to the internal test suite now that Kiwi TCMS is available via
source
- Prevent crash if ``uid`` field is not a number to make it work with Keycloak


v1.2.4 (14 Feb 2021)
~~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 0 additions & 1 deletion devel.txt
Expand Up @@ -7,5 +7,4 @@ PyGithub
pylint
pylint-django
psycopg2
kiwitcms>=10.0
textdistance
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -25,7 +25,7 @@ def get_install_requires(path):

setup(
name='kiwitcms-github-app',
version='1.2.4',
version='1.3.0',
description='GitHub App integration for Kiwi TCMS',
long_description=get_long_description(),
author='Kiwi TCMS',
Expand Down
4 changes: 2 additions & 2 deletions tcms_github_app/middleware.py
@@ -1,4 +1,4 @@
# Copyright (c) 2019 Alexander Todorov <atodorov@MrSenko.com>
# Copyright (c) 2019-2021 Alexander Todorov <atodorov@MrSenko.com>

# Licensed under the GPL 3.0: https://www.gnu.org/licenses/gpl-3.0.txt
# pylint: disable=too-few-public-methods
Expand All @@ -25,7 +25,7 @@ def __call__(self, request):

app_inst = None
social_user = request.user.social_auth.first()
if social_user:
if social_user and social_user.uid.isdigit():
app_inst = AppInstallation.objects.filter(
sender=social_user.uid,
tenant_pk=None
Expand Down
16 changes: 1 addition & 15 deletions tcms_github_app/tests/__init__.py
@@ -1,4 +1,4 @@
# Copyright (c) 2019 Alexander Todorov <atodorov@MrSenko.com>
# Copyright (c) 2019-2021 Alexander Todorov <atodorov@MrSenko.com>

# Licensed under the GPL 3.0: https://www.gnu.org/licenses/gpl-3.0.txt

Expand Down Expand Up @@ -29,20 +29,6 @@ class Meta:
uid = factory.Sequence(lambda n: n)


class ClassificationFactory(DjangoModelFactory):
class Meta:
model = 'management.Classification'
name = factory.Sequence(lambda n: 'Classification %d' % n)


class ProductFactory(DjangoModelFactory):
class Meta:
model = 'management.Product'

name = factory.Sequence(lambda n: 'Product %d' % n)
classification = factory.SubFactory(ClassificationFactory)


class AnonymousTestCase(LoggedInTestCase):
def setUp(self):
super().setUp()
Expand Down
4 changes: 2 additions & 2 deletions tcms_github_app/tests/test_installation_repositories.py
@@ -1,4 +1,4 @@
# Copyright (c) 2020 Alexander Todorov <atodorov@MrSenko.com>
# Copyright (c) 2020-2021 Alexander Todorov <atodorov@MrSenko.com>

# Licensed under the GPL 3.0: https://www.gnu.org/licenses/gpl-3.0.txt
# pylint: disable=too-many-ancestors
Expand All @@ -15,10 +15,10 @@
from tcms.utils import github
from tcms.management.models import Product
from tcms.testcases.models import BugSystem
from tcms.tests.factories import ProductFactory

from tcms_github_app.tests import AnonymousTestCase
from tcms_github_app.tests import AppInstallationFactory
from tcms_github_app.tests import ProductFactory
from tcms_github_app.tests import UserSocialAuthFactory


Expand Down
12 changes: 11 additions & 1 deletion tcms_github_app/tests/test_middleware.py
@@ -1,4 +1,4 @@
# Copyright (c) 2019 Alexander Todorov <atodorov@MrSenko.com>
# Copyright (c) 2019-2021 Alexander Todorov <atodorov@MrSenko.com>

# Licensed under the GPL 3.0: https://www.gnu.org/licenses/gpl-3.0.txt
# pylint: disable=too-many-ancestors
Expand Down Expand Up @@ -65,3 +65,13 @@ def test_nothing_when_unconfigured_installation_not_owned_by_user(self):

self.assertContains(response, 'Kiwi TCMS - Dashboard')
self.assertNotContains(response, 'Unconfigured GitHub App')

@modify_settings(MIDDLEWARE={
'append': 'tcms_github_app.middleware.CheckGitHubAppMiddleware',
})
def test_dont_crash_with_keycloak(self):
UserSocialAuthFactory(user=self.tester, uid="kc_atodorov")

response = self.client.get('/', follow=True)

self.assertContains(response, 'Dashboard')
15 changes: 12 additions & 3 deletions test_project/settings.py
Expand Up @@ -9,11 +9,20 @@
import sys

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# site-packages/tcms_settings_dir/ must be before ./tcms_settings_dir/
# so we can load multi_tenant.py first!
if BASE_DIR in sys.path:
sys.path.remove(BASE_DIR)
sys.path.append(BASE_DIR)
home_dir = os.path.expanduser("~")
removed_paths = []
for path in sys.path:
if path.startswith(home_dir) and path.find('site-packages') == -1:
removed_paths.append(path)

for path in removed_paths:
sys.path.remove(path)

# re add them again
sys.path.extend(removed_paths)

import pkg_resources

Expand Down

0 comments on commit b2e65da

Please sign in to comment.