Skip to content

Commit 3547b78

Browse files
authored
Merge pull request #277 from novafloss/use-py.test
Add configuration for py.test
2 parents 1f76130 + 86f29b1 commit 3547b78

File tree

5 files changed

+67
-14
lines changed

5 files changed

+67
-14
lines changed

CHANGELOG.rst

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ master (unreleased)
88
- Added tests for the validators mapping
99
- Minor syntax changes
1010
- Added perf rec tests
11+
- Add configuration for py.test
12+
- Reactivate accidentally skipped ``test_validations.py`` tests
1113

1214
Release 1.0.2 (2017-10-10)
1315
==========================

demo/tests/serializers/__init__.py

Whitespace-only changes.

demo/tests/serializers/tests_validations.py renamed to demo/tests/serializers/test_validations.py

+34-14
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,70 @@
1212

1313

1414
class ValidationSerializerTest(TestCase):
15+
increment = 0
1516

1617
def setUp(self):
17-
super(ValidationSerializerTest, self).setUp()
1818
self.form = Formidable.objects.create(
1919
label='test', description='test'
2020
)
21-
self.text = self.form.fields.create(
22-
type_id='text', slug='input-text', label='name',
21+
self.increment += 1
22+
self.text_field = self.form.fields.create(
23+
type_id='text',
24+
slug='input-text-{}'.format(self.increment),
25+
label='name',
26+
order=1,
2327
)
2428

2529
def test_int_value(self):
26-
data = {'field_id': self.text.id, 'value': 5, 'type': 'minlength'}
30+
data = {
31+
'field_id': self.text_field.id,
32+
'type': 'MINLENGTH',
33+
'value': 5,
34+
}
2735
serializer = MinLengthSerializer(data=data)
2836
self.assertTrue(serializer.is_valid())
2937

3038
def test_non_int_value(self):
31-
data = {'field_id': self.text.id, 'value': 'test', 'type': 'minlength'}
39+
data = {
40+
'field_id': self.text_field.id,
41+
'type': 'MINLENGTH',
42+
'value': 'test',
43+
}
3244
serializer = MinLengthSerializer(data=data)
3345
self.assertFalse(serializer.is_valid())
3446

3547
def test_regexp_value(self):
3648
data = {
37-
'field_id': self.text.id, 'value': '\w+ly', 'type': 'minlength'
49+
'field_id': self.text_field.id,
50+
'type': 'REGEXP',
51+
'value': '\w+ly',
3852
}
3953
serializer = RegexpSerializer(data=data)
4054
self.assertTrue(serializer.is_valid())
4155

4256
def test_invalid_regexp_value(self):
4357
data = {
44-
'field_id': self.text.id, 'value': '\w+ly(', 'type': 'minlength'
58+
'field_id': self.text_field.id,
59+
'type': 'REGEXP',
60+
'value': '\w+ly(',
4561
}
4662
serializer = RegexpSerializer(data=data)
4763
self.assertFalse(serializer.is_valid())
4864

4965
def test_update_validations(self):
5066
list_serializer = ValidationSerializer(many=True)
51-
self.text.validations.create(
52-
value='5', type='minlength'
67+
self.text_field.validations.create(
68+
type='MINLENGTH',
69+
value='5',
5370
)
5471
list_serializer.update(
55-
self.text.validations,
56-
[{'type': 'minlength', 'value': '12'}],
57-
self.text
72+
self.text_field.validations,
73+
self.text_field,
74+
[{
75+
'type': 'MINLENGTH',
76+
'value': '12'
77+
}],
5878
)
59-
self.assertEquals(self.text.validations.count(), 1)
60-
validation = self.text.validations.first()
79+
self.assertEquals(self.text_field.validations.count(), 1)
80+
validation = self.text_field.validations.first()
6181
self.assertEquals(validation.value, '12')

docs/source/dev.rst

+23
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Developer's documentation
55
Testing
66
-------
77

8+
Using tox
9+
~~~~~~~~~
10+
811
Tests are launched using `tox <http://tox.readthedocs.io/>`_. You may want to become proficient with this tool but the core command you need to know is:
912

1013
.. code:: shell
@@ -41,6 +44,26 @@ If somehow you've messed-up with your environment(s), you can still recreate it/
4144
$ tox -re django18-py27 # recreate and run tests using `django18-py27`
4245
4346
47+
Using py.test
48+
~~~~~~~~~~~~~
49+
50+
You can also run tests with ``py.test``.
51+
52+
You can install it with the following command:
53+
54+
.. code:: shell
55+
56+
$ pip install pytest{,-django}
57+
# Optionally
58+
$ pip install pytest-sugar
59+
60+
We've added a section in our ``setup.cfg``, so you should be able to run tests simply with:
61+
62+
.. code:: shell
63+
64+
$ py.test
65+
66+
4467
Swagger documentation update
4568
----------------------------
4669

setup.cfg

+8
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ multi_line_output = 5
1010
not_skip = __init__.py
1111
skip = migrations, settings
1212
line_length = 80
13+
14+
[tool:pytest]
15+
16+
addopts =
17+
--ds=demo.settings
18+
19+
testpaths =
20+
demo/tests

0 commit comments

Comments
 (0)