This repository has been archived on 2023-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
django-pyvows/README.md

52 lines
2.7 KiB
Markdown
Raw Permalink Normal View History

2015-07-19 11:26:40 +00:00
# Django-PyVows
2011-08-18 23:08:10 +00:00
2015-07-19 11:26:40 +00:00
This project is an extension of pyVows to test [Django](https://www.djangoproject.com/) projects. It enables usage of core Django testing tools in a way that is in sync with pyVows workflow mindset.
2011-08-18 23:08:10 +00:00
2015-07-19 11:26:40 +00:00
PyVows is a BDD (Behaviour Driven Development) inspired by Vows for node.js
2011-08-18 23:08:10 +00:00
2015-07-19 11:34:58 +00:00
More documentation about pyVows can be found at [the project homepage](http://pyvows.org) or for more updated usage check the project [tests itself](https://github.com/heynemann/pyvows/tree/master/tests).
2011-08-18 23:08:10 +00:00
2015-07-19 11:26:40 +00:00
Django-PyVows is in sync with the latest Django developments and supports Django 1.8.
2011-08-18 23:08:10 +00:00
2015-07-19 11:26:40 +00:00
## Usage
2011-08-18 23:08:10 +00:00
2015-07-19 11:26:40 +00:00
There is no need to modify your project to use Django-PyVows. You only have to define where is your project settings module and start calling your project urls in your tests.
2011-08-18 23:08:10 +00:00
```python
from pyvows import Vows, expect
2011-08-18 23:08:10 +00:00
2015-07-19 11:26:40 +00:00
from django_pyvows.context import DjangoContext
2011-08-18 23:08:10 +00:00
@Vows.batch
2015-07-19 11:26:40 +00:00
class SimpleTestVows(DjangoContext):
2015-07-19 11:26:40 +00:00
def settings_module(self):
return 'yourproject.settings'
2011-08-18 23:08:10 +00:00
def topic(self):
return self.get('/mygreaturl/')
def should_be_a_success(self, topic):
2015-07-19 11:26:40 +00:00
expect(topic.status_code).to_equal(200)
2015-07-19 11:34:58 +00:00
def should_return_the_correct_response(self, topic):
2015-07-19 11:26:40 +00:00
expect(topic).contains("Welcome!")
```
2011-08-18 23:08:10 +00:00
2015-07-19 11:26:40 +00:00
The default `settings_module` is `settings` so you should define it accordly based on your `PYTHONPATH`.
### HTTP Client
2015-07-19 11:34:58 +00:00
We support `django.test.Client`, the methods `DjangoContext.get` and `DjangoContext.post` are actually simple wrappers around it so [the usage](https://docs.djangoproject.com/en/1.8/topics/testing/tools/#the-test-client) is the same. The test client is also available in the `DjangoContext` instance as `self.client`.
2015-07-19 11:26:40 +00:00
### Assertions
The available assertions in Django-PyVows are the same as in `django.test.SimpleTestCase` they were adapted to the context of BDD and PyVows.
- `contains`: reflects the `django.test.SimpleTestCase.assertContains`. Check usage at: [https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.SimpleTestCase.assertContains](https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.SimpleTestCase.assertContains)
- `redirects_to`: reflects the `django.test.SimpleTestCase.assertRedirects`. Check usage at: [https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.SimpleTestCase.assertRedirects](https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.SimpleTestCase.assertRedirects)
- `with_form_error`: reflects the `django.test.SimpleTestCase.assertFormError`. Check usage at: [https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.SimpleTestCase.assertFormError](https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.SimpleTestCase.assertFormError)
2011-08-23 14:13:54 +00:00
2015-07-19 11:26:40 +00:00
### Settings Override
2015-07-19 11:26:40 +00:00
TODO