File: testcases.py

package info (click to toggle)
django-haystack 3.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,504 kB
  • sloc: python: 23,475; xml: 1,708; sh: 74; makefile: 71
file content (46 lines) | stat: -rw-r--r-- 1,258 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
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import shutil

from django.conf import settings
from django.test import TestCase


class WhooshTestCase(TestCase):
    fixtures = ["base_data"]

    @classmethod
    def setUpClass(cls):
        for name, conn_settings in settings.HAYSTACK_CONNECTIONS.items():
            if (
                conn_settings["ENGINE"]
                != "haystack.backends.whoosh_backend.WhooshEngine"
            ):
                continue

            if "STORAGE" in conn_settings and conn_settings["STORAGE"] != "file":
                continue

            # Start clean
            if os.path.exists(conn_settings["PATH"]):
                shutil.rmtree(conn_settings["PATH"])

            from haystack import connections

            connections[name].get_backend().setup()

        super().setUpClass()

    @classmethod
    def tearDownClass(cls):
        for conn in settings.HAYSTACK_CONNECTIONS.values():
            if conn["ENGINE"] != "haystack.backends.whoosh_backend.WhooshEngine":
                continue

            if "STORAGE" in conn and conn["STORAGE"] != "file":
                continue

            # Start clean
            if os.path.exists(conn["PATH"]):
                shutil.rmtree(conn["PATH"])

        super().tearDownClass()