From d22cbb6538a66229e39be3abc757d3081e178ac8 Mon Sep 17 00:00:00 2001 From: ikame Date: Tue, 29 Apr 2014 13:53:57 +0200 Subject: [PATCH] New tests skeleton and examples using pytest Instructions (from the project root): 1. pip install -r requirements-devel.txt 2. py.test --- pytest.ini | 2 ++ requirements-devel.txt | 6 ++++++ tests/__init__.py | 0 tests/auth/__init__.py | 0 tests/auth/test_api.py | 23 +++++++++++++++++++++++ tests/factories.py | 13 +++++++++++++ 6 files changed, 44 insertions(+) create mode 100644 pytest.ini create mode 100644 requirements-devel.txt create mode 100644 tests/__init__.py create mode 100644 tests/auth/__init__.py create mode 100644 tests/auth/test_api.py create mode 100644 tests/factories.py diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..d683ade3 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +DJANGO_SETTINGS_MODULE = settings.testing \ No newline at end of file diff --git a/requirements-devel.txt b/requirements-devel.txt new file mode 100644 index 00000000..c2187e13 --- /dev/null +++ b/requirements-devel.txt @@ -0,0 +1,6 @@ +-r requirements.txt + +factory-boy==2.3.1 +py==1.4.20 +pytest==2.5.2 +pytest-django==2.6.1 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/auth/__init__.py b/tests/auth/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/auth/test_api.py b/tests/auth/test_api.py new file mode 100644 index 00000000..eb1390be --- /dev/null +++ b/tests/auth/test_api.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +import pytest +from unittest import mock + +from rest_framework.reverse import reverse + +from ..factories import DomainFactory + +pytestmark = pytest.mark.django_db + + +def setup_module(module): + module.patcher = mock.patch("taiga.domains.base.get_default_domain", DomainFactory.build) + module.patcher.start() + + +def teardown_module(module): + module.patcher.stop() + + +def test_respond_400_if_credentials_are_invalid(client): + response = client.post(reverse("auth-list"), {"username": "john", "password": "smith"}) + assert response.status_code == 400 diff --git a/tests/factories.py b/tests/factories.py new file mode 100644 index 00000000..96a325f7 --- /dev/null +++ b/tests/factories.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +import factory + +from taiga.domains import models + + +class DomainFactory(factory.DjangoModelFactory): + FACTORY_FOR = models.Domain + + public_register = False + scheme = None + name = "localhost" + domain = "localhost"