This repository has been archived by the owner on Mar 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
238 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .controllers import * | ||
from .parsers import * | ||
from .renderers import * | ||
from .validators import * | ||
from .views import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# built-in | ||
from __main__ import unittest, djburger | ||
# external | ||
from django.contrib.auth.models import Group | ||
|
||
|
||
class DjangoFormValidatorsTest(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
Group.objects.filter(name='TEST_IT').delete() | ||
Group.objects.filter(name='TEST_IT_2').delete() | ||
|
||
cls.obj = Group.objects.create(name='TEST_IT') | ||
Group.objects.create(name='TEST_IT_2') | ||
cls.qs = Group.objects.all() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
Group.objects.get(name='TEST_IT').delete() | ||
Group.objects.get(name='TEST_IT_2').delete() | ||
|
||
def base_validator(self): | ||
class Base(djburger.v.b.Form): | ||
name = djburger.f.CharField(max_length=20) | ||
mail = djburger.f.EmailField() | ||
with self.subTest(src_text='base pass'): | ||
data = {'name': 'John Doe', 'mail': 'test@gmail.com'} | ||
v = Base(request=None, data=data) | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='base not pass'): | ||
data = {'name': 'John Doe', 'mail': 'test.gmail.com'} | ||
v = Base(request=None, data=data) | ||
self.assertFalse(v.is_valid()) | ||
|
||
def wrapper_validator(self): | ||
class Base(djburger.f.Form): | ||
name = djburger.f.CharField(max_length=20) | ||
mail = djburger.f.EmailField() | ||
Wrapped = djburger.v.w.Form(Base) # noQA | ||
with self.subTest(src_text='base pass'): | ||
data = {'name': 'John Doe', 'mail': 'test@gmail.com'} | ||
v = Wrapped(request=None, data=data) | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='base not pass'): | ||
data = {'name': 'John Doe', 'mail': 'test.gmail.com'} | ||
v = Wrapped(request=None, data=data) | ||
self.assertFalse(v.is_valid()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# built-in | ||
from __main__ import unittest, djburger | ||
# external | ||
from django.contrib.auth.models import Group | ||
import marshmallow | ||
from pyschemes import Scheme as PySchemes | ||
import rest_framework | ||
|
||
|
||
class DjangoOtherValidatorsTest(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
Group.objects.filter(name='TEST_IT').delete() | ||
Group.objects.filter(name='TEST_IT_2').delete() | ||
|
||
cls.obj = Group.objects.create(name='TEST_IT') | ||
Group.objects.create(name='TEST_IT_2') | ||
cls.qs = Group.objects.all() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
Group.objects.get(name='TEST_IT').delete() | ||
Group.objects.get(name='TEST_IT_2').delete() | ||
|
||
def pyschemes(self): | ||
with self.subTest(src_text='pyschemes'): | ||
v = djburger.v.c.PySchemes( | ||
{'name': str, 'id': int}, | ||
policy='drop' | ||
) | ||
v = v(request=None, data=self.obj) | ||
self.assertTrue(v.is_valid()) | ||
|
||
def marshmallow(self): | ||
with self.subTest(src_text='marshmallow base'): | ||
class Base(djburger.v.b.Marshmallow): | ||
name = marshmallow.fields.Str() | ||
v = Base(request=None, data=self.obj) | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='marshmallow wrapper'): | ||
class Base(marshmallow.Schema): | ||
name = marshmallow.fields.Str() | ||
Wrapped = djburger.v.w.Marshmallow(Base) # noQA | ||
v = Wrapped(request=None, data=self.obj) | ||
self.assertTrue(v.is_valid()) | ||
|
||
def rest(self): | ||
with self.subTest(src_text='rest framework base'): | ||
class Base(djburger.v.b.RESTFramework): | ||
name = rest_framework.serializers.CharField(max_length=20) | ||
v = Base(request=None, data=self.obj) | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='rest framework wrapper'): | ||
class Base(rest_framework.serializers.Serializer): | ||
name = rest_framework.serializers.CharField(max_length=20) | ||
Wrapped = djburger.v.w.RESTFramework(Base) # noQA | ||
v = Wrapped(request=None, data=self.obj) | ||
self.assertTrue(v.is_valid()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# built-in | ||
from __main__ import unittest, djburger | ||
# external | ||
import marshmallow | ||
|
||
|
||
class MarshmallowValidatorsTest(unittest.TestCase): | ||
|
||
def base_validator(self): | ||
# BASE | ||
class Base(djburger.v.b.Marshmallow): | ||
name = marshmallow.fields.Str() | ||
mail = marshmallow.fields.Email() | ||
with self.subTest(src_text='base pass'): | ||
data = {'name': 'John Doe', 'mail': 'test@gmail.com'} | ||
v = Base(request=None, data=data) | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='base not pass'): | ||
data = {'name': 'John Doe', 'mail': 'test.gmail.com'} | ||
v = Base(request=None, data=data) | ||
self.assertFalse(v.is_valid()) | ||
|
||
def wrapper_validator(self): | ||
class Base(marshmallow.Schema): | ||
name = marshmallow.fields.Str() | ||
mail = marshmallow.fields.Email() | ||
|
||
Wrapped = djburger.v.w.Marshmallow(Base) # noQA | ||
with self.subTest(src_text='base pass'): | ||
data = {'name': 'John Doe', 'mail': 'test@gmail.com'} | ||
v = Wrapped(request=None, data=data) | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='base not pass'): | ||
data = {'name': 'John Doe', 'mail': 'test.gmail.com'} | ||
v = Wrapped(request=None, data=data) | ||
self.assertFalse(v.is_valid()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# built-in | ||
from __main__ import unittest, djburger | ||
# external | ||
from pyschemes import Scheme as PySchemes | ||
|
||
|
||
class PySchemesValidatorsTest(unittest.TestCase): | ||
|
||
def base_validator(self): | ||
# BASE | ||
with self.subTest(src_text='base pass'): | ||
v = djburger.v.c.PySchemes([str, 2, int]) | ||
v = v(request=None, data=['3', 2, 4]) | ||
v.is_valid() | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='base not pass'): | ||
v = djburger.v.c.PySchemes([str, 2, int]) | ||
v = v(request=None, data=[1, 2, 4]) | ||
self.assertFalse(v.is_valid()) | ||
with self.subTest(src_text='base int data'): | ||
v = djburger.v.c.PySchemes(int) | ||
v = v(request=None, data=3) | ||
v.is_valid() | ||
self.assertEqual(v.cleaned_data, 3) | ||
|
||
def wrapper_validator(self): | ||
with self.subTest(src_text='base pass'): | ||
v = djburger.v.w.PySchemes(PySchemes([str, 2, int])) | ||
v = v(request=None, data=['3', 2, 4]) | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='base not pass'): | ||
v = djburger.v.w.PySchemes(PySchemes([str, 2, int])) | ||
v = v(request=None, data=[1, 2, 4]) | ||
self.assertFalse(v.is_valid()) | ||
with self.subTest(src_text='base int data'): | ||
v = djburger.v.w.PySchemes(PySchemes(int)) | ||
v = v(request=None, data=3) | ||
v.is_valid() | ||
self.assertEqual(v.cleaned_data, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# built-in | ||
from __main__ import unittest, djburger | ||
# external | ||
import rest_framework | ||
|
||
|
||
class RestValidatorsTest(unittest.TestCase): | ||
def base_validator(self): | ||
# BASE | ||
class Base(djburger.v.b.RESTFramework): | ||
name = rest_framework.serializers.CharField(max_length=20) | ||
mail = rest_framework.serializers.EmailField() | ||
with self.subTest(src_text='base pass'): | ||
data = {'name': 'John Doe', 'mail': 'test@gmail.com'} | ||
v = Base(request=None, data=data) | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='base not pass'): | ||
data = {'name': 'John Doe', 'mail': 'test.gmail.com'} | ||
v = Base(request=None, data=data) | ||
self.assertFalse(v.is_valid()) | ||
|
||
def wrapper_validator(self): | ||
class Base(rest_framework.serializers.Serializer): | ||
name = rest_framework.serializers.CharField(max_length=20) | ||
mail = rest_framework.serializers.EmailField() | ||
Wrapped = djburger.v.w.RESTFramework(Base) # noQA | ||
with self.subTest(src_text='base pass'): | ||
data = {'name': 'John Doe', 'mail': 'test@gmail.com'} | ||
v = Wrapped(request=None, data=data) | ||
self.assertTrue(v.is_valid()) | ||
with self.subTest(src_text='base not pass'): | ||
data = {'name': 'John Doe', 'mail': 'test.gmail.com'} | ||
v = Wrapped(request=None, data=data) | ||
self.assertFalse(v.is_valid()) |
Oops, something went wrong.