Commit 33e04208 authored by Florent Chehab's avatar Florent Chehab

tweaks and switch to django-pytest

parent 041d5304
Pipeline #26537 failed with stages
in 1 minute and 44 seconds
[run]
omit = *migrations*
source = .
omit =
*migrations*
tests/*
source = .
......@@ -8,4 +8,5 @@ db.sqlite3
node_modules
.coverage
htmlcov
.vscode
\ No newline at end of file
.vscode
.pytest_cache
......@@ -14,9 +14,7 @@ testing:
- export DATABASE_URL=postgres://postgres:@postgres:5432/python-test-app
- pip install -r requirements.txt --quiet
- ./manage.py check
- coverage3 run manage.py test
- coverage3 report
- coverage3 html
- pytest -n 4 general/ frontend/ backend/ --cov-report html
artifacts:
paths:
- htmlcov/
......
......@@ -8,7 +8,9 @@
"**/.DS_Store": true,
"**/__pycache__":true,
"**/*.pyc":true,
"htmlcov":true
"htmlcov":false,
"env":true,
".coverage":true
},
"cSpell.language": "en,fr-FR,fr",
"python.linting.flake8Enabled": true
......
......@@ -29,7 +29,7 @@ class MyModelSerializer(serializers.ModelSerializer):
model = MyModel
def moderation_required(self):
user = self.context['request'].user
user = self.get_user_in_request()
request = self.context['request']
if user.is_staff:
......@@ -44,8 +44,11 @@ class MyModelSerializer(serializers.ModelSerializer):
return False
def get_user_in_request(self):
return self.context['request'].user
def set_model_attr_no_moder(self, moderated_and_updated):
user = self.context['request'].user
user = self.get_user_in_request()
now = timezone.now()
self.validated_data['moderated_by'] = user
self.validated_data['moderated_on'] = now
......@@ -66,17 +69,17 @@ class MyModelSerializer(serializers.ModelSerializer):
content_type=ct, object_id=self.instance.pk)
def save(self, **kwargs):
user = self.get_user_in_request()
self.clean_validated_data()
if self.moderation_required():
print("Modération requise")
user = self.set_model_attr_for_moder()
if self.instance is None: # we need to create the main model
self.instance = super(
MyModelSerializer, self).save(**kwargs)
objs_pending_db = self.get_pending_models()
user = self.context['request'].user
self.clean_validated_data() # Make that it is done...
if len(objs_pending_db) > 0:
......
# from django.test import TestCase
# Create your tests here.
[pytest]
DJANGO_SETTINGS_MODULE = general.settings
python_files = tests.py test_*.py *_tests.py
addopts = --cov --cov-config .coveragerc --cov-report term
......@@ -13,6 +13,8 @@ django-imagekit==4.0.2
django-reversion==2.0.13
django-reversion-compare==0.8.4
reverse-geocoder==1.5.1
coverage==4.5.1
pytest-django==3.4.2
pytest-cov==2.5.1
pytest-xdist==1.23.0
flake8
django-debug-toolbar==1.9.1
django-debug-toolbar==1.9.1
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment