How to use the pytest.mark.django_db function in pytest

To help you get started, we’ve selected a few pytest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github studybuffalo / django-flexible-subscriptions / tests / subscriptions / test_views_subscription.py View on Github external
@pytest.mark.django_db
def test_subscription_list_template(admin_client):
    """Tests for proper subscription_list template."""
    response = admin_client.get(reverse('dfs_subscription_list'))

    assert (
        'subscriptions/subscription_list.html' in [
            t.name for t in response.templates
        ]
github dominicrodger / django-tinycontent / tests / test_models.py View on Github external
@pytest.mark.django_db
def test_tinycontentfile_slug(file_upload):
    assert "foobar" == file_upload.slug
github CenterForOpenScience / osf.io / api_tests / schemas / views / test_registration_schemas_detail.py View on Github external
import pytest

from api.base.settings.defaults import API_BASE
from osf.models import RegistrationSchema
from osf_tests.factories import (
    AuthUserFactory,
)

pytestmark = pytest.mark.django_db

SCHEMA_VERSION = 2

@pytest.fixture()
def user():
    return AuthUserFactory()

@pytest.fixture()
def schema():
    return RegistrationSchema.objects.filter(
        name='Prereg Challenge',
        schema_version=SCHEMA_VERSION
    ).first()


class TestDeprecatedMetaSchemaDetail:
github studybuffalo / django-flexible-subscriptions / tests / subscriptions / test_models.py View on Github external
@pytest.mark.django_db
def test_plan_cost_display_billing_frequency_text_hour_singular():
    """Tests display_billing_frequency_text for singular per hour billing."""
    plan = models.SubscriptionPlan.objects.create(
        plan_name='Test Plan',
        plan_description='This is a test plan',
    )

    cost = models.PlanCost.objects.create(
        plan=plan, recurrence_period=1, recurrence_unit=models.HOUR
    )

    assert cost.display_billing_frequency_text == 'per hour'
github OpenSlides / OpenSlides / tests / integration / motions / test_viewset.py View on Github external
@pytest.mark.django_db(transaction=False)
def test_category_db_queries():
    """
    Tests that only the following db queries are done:
    * 1 requests to get the list of all categories.
    """
    for index in range(10):
        Category.objects.create(name=f"category{index}")

    assert count_queries(Category.get_elements) == 1
github saxix / django-concurrency / tests / test_command.py View on Github external
@pytest.mark.django_db
def test_command_list():
    out = six.StringIO()
    call_command('triggers', 'list', stdout=out)
    out.seek(0)
    output = out.read()
    assert output.find('concurrency_demo_triggerconcurrentmodel_i')
    assert output.find('concurrency_demo_triggerconcurrentmodel_u')
github fga-eps-mds / 2017.1-PlataformaJogosUnB / backend / media / test_models.py View on Github external
    @pytest.mark.django_db
    def test_video_valid_extension(self, game_created):
        video = VideoFactory.build(game=game_created)
        video.save()
        assert Video.objects.last() == video
github translate / pootle / tests / pootle_data / data_tool.py View on Github external
@pytest.mark.django_db
def test_data_tool_obsolete_resurrect_store(store0):
    assert store0.check_data.count()
    orig_stats = store0.data_tool.get_stats()
    store0.makeobsolete()
    assert store0.data.total_words == 0
    assert store0.data.critical_checks == 0
    assert not store0.check_data.count()
    assert store0.data_tool.get_stats() != orig_stats
    assert store0.data.max_unit_revision
    store0.resurrect()
    assert store0.data.total_words
    assert store0.check_data.count()
    assert store0.data.critical_checks
github tr11 / wagtail-graphql / tests / test_settings.py View on Github external
@pytest.mark.django_db
def test_settings(client):
    assert_query(client, 'settings')
github erudit / eruditorg / tests / unit / base / test_viewcompat.py View on Github external
from unittest import mock

import pytest
from django.test import Client
from django.urls import reverse

from apps.public.journal.views_compat import get_fedora_ids_from_url_kwargs
from erudit.fedora import repository
from erudit.test.factories import IssueFactory, ArticleFactory
from erudit.test.factories import JournalFactory

pytestmark = pytest.mark.django_db


def test_can_redirect_to_retro_for_unknown_urls():
    url = '/fr/test/unknown'
    response = Client().get(url)
    assert response.status_code == 301


@pytest.mark.django_db
class TestCanRedirectToRetro:
    def test_can_redirect_to_retro_for_unknown_urls(self):
        # Setup
        url = '/fr/test/unknown'
        # Run
        response = Client().get(url)
        # Check