Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made SimpleJson optional #182

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion advanced_filters/q_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db.models import Q
from django.core.serializers.base import SerializationError

import simplejson as json
import json


try:
Expand Down
56 changes: 44 additions & 12 deletions advanced_filters/tests/test_q_serializer.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,71 @@
from django.db.models import Q
from django.test import TestCase
import json
import datetime


from ..q_serializer import QSerializer


class QSerializerTest(TestCase):
correct_query = {
'children': [('test', 1234)],
'connector': 'AND',
'negated': False,
"children": [("test", 1234)],
"connector": "AND",
"negated": False,
}
datetime_query = {
"children": [("date", datetime.datetime.now().isoformat())],
"connector": "AND",
"negated": False,
}

def setUp(self):
self.s = QSerializer()
self.query_a = Q(test=1234)
self.query_b = Q(another="test")
self.date_query = Q(date=datetime.datetime.now().isoformat())

def test_serialize_q(self):
res = self.s.serialize(self.query_a)
self.assertEqual(res, self.correct_query)

date = self.s.serialize(self.date_query)
self.assertEqual(date, self.datetime_query)

def test_jsondump_q(self):
jres = self.s.dumps(self.query_a)
self.assertJSONEqual(jres, json.dumps(self.correct_query))

jdate = self.s.serialize(self.date_query)
self.assertEqual(jdate, json.dumps(self.datetime_query))

def test_deserialize_q(self):
qres = self.s.deserialize({
'children': [('test', 1234)],
'connector': 'AND',
'negated': False,
'subtree_parents': []
})
qres = self.s.deserialize(
{
"children": [("test", 1234)],
"connector": "AND",
"negated": False,
"subtree_parents": [],
}
)
self.assertIsInstance(qres, Q)

qres = self.s.loads('{"connector": "AND", "negated": false, "children"'
' :[["test", 1234]], "subtree_parents": []}')
qres = self.s.loads(
'{"connector": "AND", "negated": false, "children"'
' :[["test", 1234]], "subtree_parents": []}'
)
self.assertIsInstance(qres, Q)

dres = self.s.deserialize(
{
"children": [("date", datetime.datetime.now().isoformat())],
"connector": "AND",
"negated": False,
}
)
self.assertIsInstance(dres, Q)

qres = self.s.loads(
'{"connector": "AND", "negated": false, "children"'
' :[["date", 2024-06-11T13:02:16.568909]], "subtree_parents": []}'
)
self.assertIsInstance(qres, Q)
78 changes: 38 additions & 40 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class Tox(TestCommand):
user_options = [('tox-args=', 'a', "Arguments to pass to tox")]
user_options = [("tox-args=", "a", "Arguments to pass to tox")]

def initialize_options(self):
TestCommand.initialize_options(self)
Expand All @@ -22,6 +22,7 @@ def run_tests(self):
# import here, cause outside the eggs aren't loaded
import tox
import shlex

args = self.tox_args
if args:
args = shlex.split(self.tox_args)
Expand All @@ -31,20 +32,20 @@ def run_tests(self):

def get_full_description():
# get long description from README
readme = 'README.rst'
changelog = 'CHANGELOG.rst'
readme = "README.rst"
changelog = "CHANGELOG.rst"
base = os.path.dirname(__file__)
with open(os.path.join(base, readme), encoding='utf-8') as readme:
with open(os.path.join(base, readme), encoding="utf-8") as readme:
README = readme.read()
with open(os.path.join(base, changelog), encoding='utf-8') as changelog:
with open(os.path.join(base, changelog), encoding="utf-8") as changelog:
CHANGELOG = changelog.read()
return f'{README}\n{CHANGELOG}'
return f"{README}\n{CHANGELOG}"


# allow setup.py to be run from any path
CUR_DIR = os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))
os.chdir(CUR_DIR)
TEST_REQ_FILE = os.path.join(CUR_DIR, 'test-reqs.txt')
TEST_REQ_FILE = os.path.join(CUR_DIR, "test-reqs.txt")
if os.path.exists(TEST_REQ_FILE):
with open(TEST_REQ_FILE) as f:
TEST_REQS = list(f.readlines())
Expand All @@ -53,43 +54,40 @@ def get_full_description():


setup(
name='django-advanced-filters',
name="django-advanced-filters",
version=__version__,
url='https://github.com/modlinltd/django-advanced-filters',
license='MIT',
description='A Django application for advanced admin filters',
keywords='django-admin admin advanced filters custom query',
url="https://github.com/modlinltd/django-advanced-filters",
license="MIT",
description="A Django application for advanced admin filters",
keywords="django-admin admin advanced filters custom query",
long_description=get_full_description(),
packages=find_packages(exclude=['tests*', 'tests.*', '*.tests']),
packages=find_packages(exclude=["tests*", "tests.*", "*.tests"]),
include_package_data=True,
install_requires=[
'simplejson>=3.6.5,<4',
],
extras_require=dict(test=TEST_REQS),
extras_require=dict(test=TEST_REQS, simplejson="simplejson"),
zip_safe=False,
author='Pavel Savchenko',
author_email='[email protected]',
python_requires='>=3.6',
author="Pavel Savchenko",
author_email="[email protected]",
python_requires=">=3.6",
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3 :: Only',
'Framework :: Django',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.0',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3 :: Only",
"Framework :: Django",
"Framework :: Django :: 2.2",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
],
tests_require=['tox'],
cmdclass={'test': Tox},
tests_require=["tox"],
cmdclass={"test": Tox},
)
Loading