generated from quillcraftsman/open-source-checklist
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from quillcraftsman/design
Design
- Loading branch information
Showing
33 changed files
with
1,231 additions
and
47 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
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,43 @@ | ||
# Django DRY Tests Developer Documentation | ||
|
||
## Makefile | ||
|
||
First check **Makefile**. It contains many useful commands to work with project | ||
|
||
## Main commands | ||
|
||
### Run Tests | ||
|
||
```commandline | ||
make test | ||
``` | ||
|
||
### Tests coverage | ||
|
||
```commandline | ||
make coverage | ||
``` | ||
|
||
### Lint | ||
|
||
```commandline | ||
make lint | ||
``` | ||
|
||
## How to develop new feature | ||
|
||
### Preparation | ||
|
||
- Make django test. Let it fail | ||
- Add example view or something else with demo project | ||
- Make the django test work. | ||
|
||
This step allow you to comfortably create new feature | ||
|
||
### Make new feature | ||
|
||
- Add new feature to the dry_tests package | ||
- Make all tests work | ||
- Check the coverage | ||
- Run linter | ||
- Make a new pull-request to contribute |
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 |
---|---|---|
@@ -1,3 +1,144 @@ | ||
# Django DRY Tests | ||
|
||
Some description will be here | ||
Package with new powerful TestCases and Assets to test django application fast. TDD is supported | ||
|
||
- [Mission](#mission) | ||
- [Open Source Project](#open-source-project) | ||
- [Features](#features) | ||
- [Requirements](#requirements) | ||
- [Development Status](#development-status) | ||
- [Install](#install) | ||
- [Quickstart](#quickstart) | ||
- [Contributing](#contributing) | ||
|
||
## 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](LICENSE). | ||
Be free to use, fork, clone and contribute. | ||
|
||
## Features | ||
|
||
- Special **Request** and **Response** classes to simple set test data | ||
- Special **SimpleTestCase** class with: | ||
- `assertTrueResponse(self, current_response, true_response)` - Main assert to compare real response with expected | ||
- `assertResponsesAreTrue(self, response_pairs)` - Compare many responses | ||
- Other more simple asserts (`assertStatusCode`, `assertRedirectUrl`, `assertValueInContext`, | ||
`assertContextValues`, `assertContentValues`) | ||
- Special **TestCase** class. Similar with **SimpleTestCase** but with testing database (**Not ready yet**) | ||
|
||
## Requirements | ||
|
||
- `Django==4` (Lower versions haven't been tested) | ||
|
||
## Development Status | ||
|
||
- **django-dry-tests** | ||
- **v0.1.0** | ||
- **3 - Alpha** | ||
|
||
Package available on [PyPi](https://pypi.org/project/django-dry-tests/) | ||
|
||
## Install | ||
|
||
### with pip | ||
|
||
```commandline | ||
pip install django-dry-tests | ||
``` | ||
|
||
### from release page | ||
|
||
Download source code from [GitHub Releases page](https://github.com/quillcraftsman/django-dry-tests/releases) | ||
|
||
### clone from GitHub | ||
|
||
```commandline | ||
git clone https://github.com/quillcraftsman/django-dry-tests.git | ||
make install | ||
``` | ||
|
||
## Quickstart | ||
|
||
For example, you need to test some view like this: | ||
|
||
```python | ||
def index_view(request): | ||
if request.method == 'GET': | ||
context = { | ||
'title': 'Title' | ||
} | ||
return render(request, 'demo/index.html', context) | ||
|
||
name = request.POST.get('name', None) | ||
if name is not None: | ||
Simple.objects.create(name=name) | ||
return HttpResponseRedirect('/') | ||
``` | ||
|
||
And you want to check: | ||
- GET response status code | ||
- GET response context data | ||
- GET response some html data | ||
- POST response status code | ||
- POST response redirect url | ||
- POST response save object to database (**Not implemented yet**) | ||
|
||
Let`s see the tests code: | ||
```python | ||
from dry_tests import ( | ||
Request, | ||
TrueResponse as Response, | ||
SimpleTestCase, | ||
POST, | ||
) | ||
|
||
|
||
class ViewTestCase(SimpleTestCase): | ||
|
||
def test_main(self): | ||
data = [ | ||
# Multy parameters GET | ||
{ | ||
'request': Request(url='/'), | ||
'response': Response( | ||
status_code=200, | ||
in_context='title', | ||
context_values={'title': 'Title'}, | ||
content_values=['Title'], | ||
), | ||
}, | ||
# Multy parameters POST | ||
{ | ||
'request': Request(url='/', method=POST), | ||
'response': Response( | ||
status_code=302, | ||
redirect_url='/', | ||
), | ||
}, | ||
] | ||
for item in data: | ||
request = item['request'] | ||
true_response = item['response'] | ||
current_response = request.get_url_response(self.client) | ||
self.assertTrueResponse(current_response, true_response) | ||
``` | ||
|
||
That's all this simple test cover all your test tasks with (**assertTrueResponse**) | ||
|
||
## Contributing | ||
|
||
You are welcome! To easy start please check: | ||
- [Developer Guidelines](CONTRIBUTING.md) | ||
- [Developer Documentation](DEVELOPER_DOCUMENTATION.md) | ||
- [Code of Conduct](CODE_OF_CONDUCT.md) | ||
- [Security Policy](SECURITY.md) | ||
|
File renamed without changes.
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,3 @@ | ||
# from django.contrib import admin | ||
|
||
# Register your models here. |
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,12 @@ | ||
""" | ||
Demo app module | ||
""" | ||
from django.apps import AppConfig | ||
|
||
|
||
class DemoConfig(AppConfig): | ||
""" | ||
Demo app config class | ||
""" | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'demo' |
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,21 @@ | ||
# Generated by Django 4.2.6 on 2023-10-11 11:39 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Simple', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=32, unique=True)), | ||
], | ||
), | ||
] |
File renamed without changes.
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,11 @@ | ||
""" | ||
Demo models | ||
""" | ||
from django.db import models | ||
|
||
|
||
class Simple(models.Model): | ||
""" | ||
Simple model with unique name | ||
""" | ||
name = models.CharField(max_length=32, unique=True) |
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 @@ | ||
{{title}} |
Empty file.
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,10 @@ | ||
# from demo.models import Simple | ||
# | ||
# | ||
# def simple_start(): | ||
# Simple.objects.create(name='first') | ||
# | ||
# | ||
# def create_simple(): | ||
# simple = Simple.objects.create(name='new name') | ||
# return simple |
Oops, something went wrong.