Code Monkey home page Code Monkey logo

django-dry-tests's Introduction

Django DRY Tests

Package with new powerful TestCases and Assets to test django application fast. TDD is supported

You can find Full Project Documentation here


Workflows

Tests Pylint

Package

Version Development Status Python version License Wheel

Support

Documentation Discussions Issues

Downloads

Day Downloads Week Downloads Month Downloads All Downloads

Languages

Languages Top Language

Development

  • Release date Last Commit
  • Issues Closed Issues
  • Pull Requests Closed Pull Requests
  • Discussions

Menu

Mission

The mission of the Django DRY Tests to design and develop open source python package to test django application

  • fast
  • with minimal code duplication
  • with the ability to use TDD easily
  • simple and comfortable

Open Source Project

This is the open source project with MIT license. Be free to use, fork, clone and contribute.

Features

  • Special Request, Response and Form classes to simple set test data
  • Special SimpleTestCase and TestCase classes with new asserts:
    • The main asserts is assertTrueResponse and assertTrueForm. You can use this for most cases.

Requirements

Development Status

Install

with pip

pip install django-dry-tests

See more in Full Documentation

Quickstart

To test view

class QuickStartViewSimpleTestCase(SimpleTestCase):
    """
    SimpleTestCase example
    """

    def test_get(self):
        """
        Test Example with django-dry-tests
        :return:
        """
        # Create Request Model
        request = Request(
            url='/quickstart/'
        )

        # Create Response Model to check all view.
        # You can set only one param without others to check it.
        true_response = TrueResponse(
            status_code=200,
            context=Context(
                keys=['quickstart'],  # check that quickstart key in context
                values=['Quickstart'],  # check that "Quickstart" value in context
                items={
                    'quickstart': 'Quickstart'
                },  # check both keys and values in context
                types={
                    'quickstart': str
                }  # check values types without check values
            ),
            content_values = [
                'Quickstart',
                '<h1>Quickstart title</h1>'
            ],  # check values after template will be rendered
        )

        # get url response with Django default Test Client
        current_response = request.get_response(self.client)
        # Use main assert to run all asserts
        self.assertTrueResponse(current_response, true_response)

To test Form

class ExampleFromTestCase(SimpleTestCase):
    """
    Example Form Test Class
    """

    def test_form(self):
        """
        Example Test with django-dry-tests
        :return:
        """
        true_form = TrueForm(  # Set Up TrueForm instance
               Fields(  # TrueForm Fields
                   count=2,  # check fields count
                   names=[
                       'number', 'name'
                   ],  # check field names
                   types={
                       'name': forms.CharField,
                       'number': forms.IntegerField
                   }  # check fields types
               ),
            )
        current_form = ExampleForm()  # Get project form
        self.assertTrueForm(current_form, true_form)  # use this main assert to check all conditions

More examples in Full Documentation

Contributing

You are welcome! To easy start please check:

django-dry-tests's People

Contributors

danteonline avatar quillcraftsman avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

danteonline

django-dry-tests's Issues

Improve documentation with using RST instead of MD

  • Use .rst format for documentation files (May be sphinx or something else)
    Automation:
  • In the requirements block use requirements.txt
  • In the Development status use setup.py for version and status
  • For examples how to use package use source code
  • In developer documentation use Makefile with commands
  • Create autodocumentation in html for source code

Compare to forms in context

Test example:

    def test_get(self):
        request = Request(
            url=self.url
        )
        true_response = TrueResponse(
            status_code=200,
            context_values={
                'form': OneTextForm()
            }
        )
        current_response = request.get_url_response(self.client)
        self.assertTrueResponse(current_response, true_response)

Output:

AssertionError: <OneTextForm bound=False, valid=Unknown, fields=(text)> != <OneTextForm bound=False, valid=False, fields=(text)>

Looks like django can't compare two similar forms.

What should we do in this case?

Design and develop asserts for testing django forms

For example:

class TestTwoTextForm(SimpleTestCase):
    """
    One text form test
    """

    def test_fields(self):
        """
        Test available fields
        """
        form = TwoTextForm()
        self.assertEqual(len(form.fields), 2)
        self.assertIn('one_text', form.fields)
        self.assertIn('two_text', form.fields)

assertFormFields maybe and special class for fields

Add initial value to the form Field model

Is your feature request related to a problem? Please describe.
Frequently we use initial value in django model field. We can't test in now with Field model

Describe the solution you'd like

  • Add new parameter "initial" to the Field model
  • Add special assert to the TestCaseMixin
  • Add condition to the main assert assertTrueFrom

Describe alternatives you've considered

Additional context
This is the form example to test initial value:

class LoadTrainingDataForm(forms.Form):
    name = forms.CharField(max_length=128, widget=forms.TextInput(attrs={
        'class': 'form-control'
    }))
    excel_file = forms.FileField(max_length=128, widget=forms.FileInput(attrs={
        'class': 'form-control'
    }))
    sheet_name = forms.IntegerField(required=False, initial=0, widget=forms.NumberInput(attrs={
        'class': 'form-control'
    }))

Add reverted asserts (with Not)

  • for in_context (not_in_context)
  • for context_values (values_not_in_context)
  • for content_values (values_not_in_content)

Or use some different way to check it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.