Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Start using pytest

Patryk Zawadzkiacd037df17e4
diff --git a/pytest.ini b/pytest.ini
new file mode 100644
index 0000000000..4345aed91e
--- /dev/null
+++ b/pytest.ini
@@ -0,0 +1,2 @@
+[pytest]
+DJANGO_SETTINGS_MODULE=saleor.test_settings
diff --git a/saleor/cart/tests.py b/saleor/cart/test_cart.py
similarity index 98%
rename from saleor/cart/tests.py
rename to saleor/cart/test_cart.py
index cd40e2268b..16c0b5c3a7 100755
--- a/saleor/cart/tests.py
+++ b/saleor/cart/test_cart.py
@@ -16,7 +16,7 @@ __all__ = ['CartTest', 'BigShipCartFormTest']
class BigShip(ProductVariant, StockedProduct, PhysicalProduct):
- name = models.CharField()
+ name = models.CharField(max_length=250)
def get_price_per_item(self, discounted=True, **kwargs):
return self.price
@@ -26,7 +26,7 @@ class BigShip(ProductVariant, StockedProduct, PhysicalProduct):
class ShipPhoto(ProductVariant, PhysicalProduct):
- name = models.CharField()
+ name = models.CharField(max_length=250)
def get_slug(self):
return 'bigship-photo'
diff --git a/saleor/checkout/tests.py b/saleor/checkout/test_checkout.py
similarity index 100%
rename from saleor/checkout/tests.py
rename to saleor/checkout/test_checkout.py
diff --git a/saleor/core/tests.py b/saleor/core/test_core.py
similarity index 96%
rename from saleor/core/tests.py
rename to saleor/core/test_core.py
index cedf5945b4..19b1ae85e3 100644
--- a/saleor/core/tests.py
+++ b/saleor/core/test_core.py
@@ -1,5 +1,6 @@
+from unittest import TestCase
+
from django.template.response import TemplateResponse
-from django.test import TestCase
from mock import MagicMock
from satchless.process import InvalidData
diff --git a/saleor/order/tests.py b/saleor/order/test_order.py
similarity index 100%
rename from saleor/order/tests.py
rename to saleor/order/test_order.py
diff --git a/saleor/registration/tests.py b/saleor/registration/test_registration.py
similarity index 100%
rename from saleor/registration/tests.py
rename to saleor/registration/test_registration.py
diff --git a/saleor/tests.py b/saleor/tests.py
deleted file mode 100644
index 9286175753..0000000000
--- a/saleor/tests.py
+++ /dev/null
@@ -1,22 +0,0 @@
-from unittest import TestSuite, TestLoader
-
-import django
-
-if hasattr(django, 'setup'):
- django.setup()
-
-TEST_MODULES = [
- 'saleor.cart.tests',
- 'saleor.checkout.tests',
- 'saleor.core.tests',
- #'saleor.delivery.tests',
- 'saleor.order.tests',
- #'saleor.payment.tests',
- #'saleor.product.tests',
- 'saleor.registration.tests',
- 'saleor.userprofile.tests']
-
-suite = TestSuite()
-loader = TestLoader()
-for module in TEST_MODULES:
- suite.addTests(loader.loadTestsFromName(module))
diff --git a/saleor/userprofile/tests.py b/saleor/userprofile/tests.py
deleted file mode 100755
index 501deb776c..0000000000
--- a/saleor/userprofile/tests.py
+++ /dev/null
@@ -1,16 +0,0 @@
-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
-from django.test import TestCase
-
-
-class SimpleTest(TestCase):
- def test_basic_addition(self):
- """
- Tests that 1 + 1 always equals 2.
- """
- self.assertEqual(1 + 1, 2)
diff --git a/setup.py b/setup.py
index b0c4f7d3b7..4cd511b771 100755
--- a/setup.py
+++ b/setup.py
@@ -1,9 +1,31 @@
#! /usr/bin/env python
from setuptools import setup, find_packages
+from setuptools.command.test import test as TestCommand
import os
+import sys
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'saleor.settings')
+
+class PyTest(TestCommand):
+ user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
+
+ def initialize_options(self):
+ TestCommand.initialize_options(self)
+ self.pytest_args = []
+
+ def finalize_options(self):
+ TestCommand.finalize_options(self)
+ self.test_args = []
+ self.test_suite = True
+
+ def run_tests(self):
+ #import here, cause outside the eggs aren't loaded
+ import pytest
+ errno = pytest.main(self.pytest_args)
+ sys.exit(errno)
+
+
setup(
name='saleor',
author='Mirumee Software',
@@ -33,20 +55,18 @@ setup(
'prices>=0.5,<0.6a0',
'requests>=1.2.0',
'satchless>=1.1.2,<1.2a0',
- 'unidecode'
- ],
+ 'unidecode'],
extras_require={
'PaaS': [
'whitenoise==1.0.6',
'gunicorn==19.2.1',
- 'psycopg2==2.6',
- ]
- },
+ 'psycopg2==2.6']},
+ cmdclass={
+ 'test': PyTest},
entry_points={
'console_scripts': ['saleor = saleor:manage']},
tests_require=[
'mock==1.0.1',
'purl>=0.4.1',
- ],
- test_suite='saleor.tests.suite'
-)
+ 'pytest',
+ 'pytest-django'])
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000000..e52640ac7a
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,10 @@
+[tox]
+envlist = py27,py33,py34
+
+[testenv]
+deps=
+ mock
+ purl
+ pytest
+ pytest-django
+commands=py.test