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 / View on Github external
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 [
   for t in response.templates
github dominicrodger / django-tinycontent / tests / View on Github external
def test_tinycontentfile_slug(file_upload):
    assert "foobar" == file_upload.slug
github CenterForOpenScience / / api_tests / schemas / views / View on Github external
import pytest

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

pytestmark = pytest.mark.django_db


def user():
    return AuthUserFactory()

def schema():
    return RegistrationSchema.objects.filter(
        name='Prereg Challenge',

class TestDeprecatedMetaSchemaDetail:
github studybuffalo / django-flexible-subscriptions / tests / subscriptions / View on Github external
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 / View on Github external
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):

    assert count_queries(Category.get_elements) == 1
github saxix / django-concurrency / tests / View on Github external
def test_command_list():
    out = six.StringIO()
    call_command('triggers', 'list', stdout=out)
    output =
    assert output.find('concurrency_demo_triggerconcurrentmodel_i')
    assert output.find('concurrency_demo_triggerconcurrentmodel_u')
github fga-eps-mds / 2017.1-PlataformaJogosUnB / backend / media / View on Github external
    def test_video_valid_extension(self, game_created):
        video =
        assert Video.objects.last() == video
github translate / pootle / tests / pootle_data / View on Github external
def test_data_tool_obsolete_resurrect_store(store0):
    assert store0.check_data.count()
    orig_stats = store0.data_tool.get_stats()
    assert == 0
    assert == 0
    assert not store0.check_data.count()
    assert store0.data_tool.get_stats() != orig_stats
    assert store0.check_data.count()
github tr11 / wagtail-graphql / tests / View on Github external
def test_settings(client):
    assert_query(client, 'settings')
github erudit / eruditorg / tests / unit / base / 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

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