mirror of https://gitlab.crans.org/bde/nk20
Use python Warnings instead of printing messages during tests
Signed-off-by: Yohann D'ANELLO <yohann.danello@gmail.com>
This commit is contained in:
parent
3a20555663
commit
5cb4183e9f
|
@ -4,6 +4,7 @@
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
|
from warnings import warn
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -46,7 +47,7 @@ class TestAPI(TestCase):
|
||||||
model = viewset.serializer_class.Meta.model
|
model = viewset.serializer_class.Meta.model
|
||||||
|
|
||||||
if not model.objects.exists(): # pragma: no cover
|
if not model.objects.exists(): # pragma: no cover
|
||||||
print(f"Warning: unable to test API filters for the model {model._meta.verbose_name} "
|
warn(f"Warning: unable to test API filters for the model {model._meta.verbose_name} "
|
||||||
"since there is no instance of it.")
|
"since there is no instance of it.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ class TestAPI(TestCase):
|
||||||
|
|
||||||
value = self.get_value(obj, field)
|
value = self.get_value(obj, field)
|
||||||
if value is None: # pragma: no cover
|
if value is None: # pragma: no cover
|
||||||
print(f"Warning: the filter {field} for the model {model._meta.verbose_name} "
|
warn(f"Warning: the filter {field} for the model {model._meta.verbose_name} "
|
||||||
"has not been tested.")
|
"has not been tested.")
|
||||||
continue
|
continue
|
||||||
resp = self.client.get(url + f"?format=json&{field}={quote_plus(str(value))}")
|
resp = self.client.get(url + f"?format=json&{field}={quote_plus(str(value))}")
|
||||||
|
@ -90,7 +91,7 @@ class TestAPI(TestCase):
|
||||||
field = field[1:]
|
field = field[1:]
|
||||||
value = self.get_value(obj, field)
|
value = self.get_value(obj, field)
|
||||||
if value is None: # pragma: no cover
|
if value is None: # pragma: no cover
|
||||||
print(f"Warning: the filter {field} for the model {model._meta.verbose_name} "
|
warn(f"Warning: the filter {field} for the model {model._meta.verbose_name} "
|
||||||
"has not been tested.")
|
"has not been tested.")
|
||||||
continue
|
continue
|
||||||
resp = self.client.get(url + f"?format=json&search={quote_plus(str(value))}")
|
resp = self.client.get(url + f"?format=json&search={quote_plus(str(value))}")
|
||||||
|
|
Loading…
Reference in New Issue