File: common_testing.py

package info (click to toggle)
django-oauth-toolkit 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,852 kB
  • sloc: python: 12,414; makefile: 159; javascript: 9
file content (33 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from django.conf import settings
from django.test import TestCase as DjangoTestCase
from django.test import TransactionTestCase as DjangoTransactionTestCase


# The multiple database scenario setup for these tests purposefully defines 'default' as
# an empty database in order to catch any assumptions in this package about database names
# and in particular to ensure there is no assumption that 'default' is a valid database.
#
# When there are multiple databases defined, Django tests will not work unless they are
# told which database(s) to work with.


def retrieve_current_databases():
    if len(settings.DATABASES) > 1:
        return [name for name in settings.DATABASES if name != "default"]
    else:
        return ["default"]


class OAuth2ProviderBase:
    @classmethod
    def setUpClass(cls):
        cls.databases = retrieve_current_databases()
        super().setUpClass()


class OAuth2ProviderTestCase(OAuth2ProviderBase, DjangoTestCase):
    """Place holder to allow overriding behaviors."""


class OAuth2ProviderTransactionTestCase(OAuth2ProviderBase, DjangoTransactionTestCase):
    """Place holder to allow overriding behaviors."""