Skip to content

Commit

Permalink
Merge pull request #7 from quillcraftsman/design
Browse files Browse the repository at this point in the history
Design
  • Loading branch information
quillcraftsman authored Oct 12, 2023
2 parents bf5a7fb + 0cf91da commit 5bd940f
Show file tree
Hide file tree
Showing 33 changed files with 1,231 additions and 47 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install pytest-cov
if [ -f requirements.txt ]; then pip install -r dev-requirements.txt; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
Expand Down
45 changes: 25 additions & 20 deletions CHECKLIST.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
[Main points](https://github.com/quillcraftsman/open-source-checklist#main-points)
- [x] [Open Source Project Checklist](https://github.com/quillcraftsman/open-source-checklist#open-source-project-checklist)
- [X] [Existing Analogues](https://github.com/quillcraftsman/open-source-checklist#existing-analogues)
- [x] [Existing Analogues](https://github.com/quillcraftsman/open-source-checklist#existing-analogues)
> [django-test-plus](https://github.com/revsys/django-test-plus/)
- [X] [Good Project Name](https://github.com/quillcraftsman/open-source-checklist#good-project-name)
- [ ] [Mission](https://github.com/quillcraftsman/open-source-checklist#mission)
- [ ] [State What the Project Is Free](https://github.com/quillcraftsman/open-source-checklist#state-what-the-project-is-free)
- [ ] [Features](https://github.com/quillcraftsman/open-source-checklist#features)
- [ ] [Requirements](https://github.com/quillcraftsman/open-source-checklist#requirements)
- [ ] [Development Status](https://github.com/quillcraftsman/open-source-checklist#development-status)
- [ ] [Download Page](https://github.com/quillcraftsman/open-source-checklist#download-page)
- [x] [Good Project Name](https://github.com/quillcraftsman/open-source-checklist#good-project-name)
- [x] [Mission](https://github.com/quillcraftsman/open-source-checklist#mission)
> https://github.com/quillcraftsman/django-dry-tests#mission
- [x] [State What the Project Is Free](https://github.com/quillcraftsman/open-source-checklist#state-what-the-project-is-free)
> https://github.com/quillcraftsman/django-dry-tests#open-source-project
- [x] [Features](https://github.com/quillcraftsman/open-source-checklist#features)
> https://github.com/quillcraftsman/django-dry-tests#features
- [x] [Requirements](https://github.com/quillcraftsman/open-source-checklist#requirements)
> https://github.com/quillcraftsman/django-dry-tests#requirements
- [x] [Development Status](https://github.com/quillcraftsman/open-source-checklist#development-status)
- [x] [Download Page](https://github.com/quillcraftsman/open-source-checklist#download-page)
> https://github.com/quillcraftsman/django-dry-tests#install
- [X] [Version Control Access](https://github.com/quillcraftsman/open-source-checklist#version-control-access)
- [X] [Bug Tracker Access](https://github.com/quillcraftsman/open-source-checklist#bug-tracker-access)
- [ ] [Communication Channels](https://github.com/quillcraftsman/open-source-checklist#communication-channels)
- - [ ] Discussions
- [x] [Communication Channels](https://github.com/quillcraftsman/open-source-checklist#communication-channels)
- - [x] Discussions
- - [ ] Mailing List
- - [ ] Real-time chat
- - [ ] Forum
- [X] [Developer Guidelines](https://github.com/quillcraftsman/open-source-checklist#developer-guidelines)
> [CONTRIBUTING.md](CONTRIBUTING.md)
- [ ] [Documentation](https://github.com/quillcraftsman/open-source-checklist#documentation)
- [ ] [Developer Documentation](https://github.com/quillcraftsman/open-source-checklist#developer-documentation)
- [ ] [Availability of Documentation](https://github.com/quillcraftsman/open-source-checklist#availability-of-documentation)
- [x] [Documentation](https://github.com/quillcraftsman/open-source-checklist#documentation)
- [x] [Developer Documentation](https://github.com/quillcraftsman/open-source-checklist#developer-documentation)
- [x] [Availability of Documentation](https://github.com/quillcraftsman/open-source-checklist#availability-of-documentation)
- [ ] [FAQ](https://github.com/quillcraftsman/open-source-checklist#faq)
- [ ] [Examples Output and Screenshots](https://github.com/quillcraftsman/open-source-checklist#examples-output-and-screenshots)
- [X] [License](https://github.com/quillcraftsman/open-source-checklist#license)
Expand All @@ -29,12 +34,12 @@
- [X] [Security Policy](https://github.com/quillcraftsman/open-source-checklist#security-policy)

[CI and CD](https://github.com/quillcraftsman/open-source-checklist#ci-and-cd)
- [ ] Tests
- [ ] Test Coverage
- [ ] Test Coverage 100%
- [ ] Linters
- [ ] Build
- [ ] Deploy To PyPi
- [x] Tests
- [x] Test Coverage
- [x] Test Coverage 100%
- [x] Linters
- [x] Build
- [x] Deploy To PyPi

Others
- [ ] Makefile?
- [x] Makefile
43 changes: 43 additions & 0 deletions DEVELOPER_DOCUMENTATION.md
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
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
test:
pytest
python manage.py test

server:
python manage.py runserver

makemigrations:
python manage.py makemigrations

coverage:
pytest -s --cov --cov-report html --cov-fail-under 100
coverage run --source='.' manage.py test
coverage report --omit=settings/asgi.py,settings/wsgi.py,manage.py,setup.py --fail-under=100
coverage html --omit=settings/asgi.py,settings/wsgi.py,manage.py,setup.py

yamllint:
yamllint -d relaxed .
Expand Down
143 changes: 142 additions & 1 deletion README.md
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.
3 changes: 3 additions & 0 deletions demo/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# from django.contrib import admin

# Register your models here.
12 changes: 12 additions & 0 deletions demo/apps.py
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'
21 changes: 21 additions & 0 deletions demo/migrations/0001_initial.py
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.
11 changes: 11 additions & 0 deletions demo/models.py
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)
1 change: 1 addition & 0 deletions demo/templates/demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{title}}
Empty file added demo/tests/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions demo/tests/db_test_data.py
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
Loading

0 comments on commit 5bd940f

Please sign in to comment.