Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Django REST Assured instantly test-covers your Django REST Framework based API.
.. image:: https://secure.travis-ci.org/ydaniv/django-rest-assured.svg :target: http://travis-ci.org/ydaniv/django-rest-assured/ :alt: Build
.. image:: https://pypip.in/download/django-rest-assured/badge.svg :target: https://pypi.python.org/pypi/django-rest-assured/ :alt: Downloads
.. image:: https://pypip.in/version/django-rest-assured/badge.svg :target: https://pypi.python.org/pypi/django-rest-assured/ :alt: Latest Version
.. image:: https://pypip.in/license/django-rest-assured/badge.svg :target: https://pypi.python.org/pypi/django-rest-assured/ :alt: License
Instantly test-cover your Django REST Framework based API.
Django-REST-Assured adds another layer on top of
Django REST Framework's APITestCase <http://www.django-rest-framework.org/api-guide/testing#test-cases>
_
which allows covering a set of RESTful resource's endpoints with a single class declaration.
This gives both a quick coverage of sanity tests to your API and a more DRY and more friendly platform for writing additional, more comprehensive tests.
.. code-block:: python
class CategoryTestCase(ReadWriteRESTAPITestCaseMixin, BaseRESTAPITestCase):
base_name = 'category'
factory_class = CategoryFactory
create_data = {'name': 'comedy'}
update_data = {'name': 'horror'}
Django-REST-Assured is designed to work with factory_boy <http://factoryboy.readthedocs.org/en/latest/>
_
for mocking objects to test against. However, you can easily extend the BaseRESTAPITestCase
to work directly with Django Models or any other factory.
route > view > serializer > model
.The basic form of usage is simply to create a class that extends
any mixin from rest_assured.testcases
, according to the
endpoints you wish to cover, and the BaseRESTAPITestCase
class.
Then just set the required attributes, and continue extending it from there.
.. admonition:: example
.. code:: python
class CategoryAPITestCase(ReadWriteRESTAPITestCaseMixin, BaseRESTAPITestCase):
base_name = 'category'
factory_class = Category
create_data = {'name': 'documentary'}
update_data = {'name': 'horror'}
If your API requires authentication and/or authorization just add
a user factory class. Assuming you use factory_boy <http://factoryboy.readthedocs.org/en/latest/>
_:
.. admonition:: example
.. code:: python
# in some factories.py module in your accounts app
class User(factory.DjangoModelFactory):
class Meta:
model = User
exclude = ('raw_password',)
first_name = 'Robert'
last_name = factory.Sequence(lambda n: 'Paulson the {0}'.format(n))
email = factory.sequence(lambda n: 'account{0}@example.com'.format(n))
username = 'mayhem'
raw_password = '123'
password = factory.PostGenerationMethodCall('set_password', raw_password)
is_active = True
# now back in your tests.py module
class CategoryAPITestCase(ReadWriteRESTAPITestCaseMixin, BaseRESTAPITestCase):
base_name = 'category'
factory_class = Category
# see here:
user_factory = User
create_data = {'name': 'documentary'}
update_data = {'name': 'horror'}
Support is determined by which Django versions are supported, and the Python and Django REST Framework versions that go with them. Tests run against all Django versions supported as of July 28, 2020.
PyPI: https://pypi.python.org/pypi/django-rest-assured
.. code-block:: sh
$ pip install django-rest-assured
Source: https://github.com/ydaniv/django-rest-assured
.. code-block:: sh
$ git clone https://github.com/ydaniv/django-rest-assured
$ python setup.py install
Issues are tracked in the github repository <https://github.com/ydaniv/django-rest-assured/issues/>
_.
Pull requests are welcome!
.. code-block:: sh
$ pip install pytest pytest-django $ py.test
Django-REST-Assured is distributed under the BSD license.
FAQs
Django REST Assured instantly test-covers your Django REST Framework based API.
We found that django-rest-assured demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.