source: main/trunk/openPLM/plmapp/tests/base.py @ 474

Revision 474, 1.6 KB checked in by pcosquer, 8 years ago (diff)

tests: add a custom test runner

  • always clean up the xapian database
  • tasks: raise exceptions
Line 
1
2from django.core.files.base import ContentFile
3from django.contrib.auth.models import User
4from django.test import TestCase
5
6from openPLM.plmapp.models import GroupInfo
7from openPLM.plmapp.controllers import PLMObjectController
8
9import os.path
10import shutil
11from django.conf import settings
12
13class BaseTestCase(TestCase):
14    CONTROLLER = PLMObjectController
15    TYPE = "Part"
16    DATA = {}
17
18    def setUp(self):
19        self.cie = User.objects.create(username="company")
20        p = self.cie.get_profile()
21        p.is_contributor = True
22        p.save()
23        self.leading_group = GroupInfo.objects.create(name="leading_group",
24                owner=self.cie, creator=self.cie)
25        self.cie.groups.add(self.leading_group)
26        self.user = User(username="user")
27        self.user.set_password("password")
28        self.user.email = "test@example.net"
29        self.user.save()
30        self.user.get_profile().is_contributor = True
31        self.user.get_profile().save()
32        self.group = GroupInfo(name="grp", owner=self.user, creator=self.user,
33                description="grp")
34        self.group.save()
35        self.user.groups.add(self.group)
36        self.DATA["group"] = self.group
37
38    def create(self, ref="Part1"):
39        return self.CONTROLLER.create(ref, self.TYPE, "a", self.user, self.DATA)
40
41    def get_file(self, name="temp.txt", data="data"):
42        f = ContentFile(data)
43        f.name = name
44        return f
45
46    def tearDown(self):
47        if os.path.exists(settings.HAYSTACK_XAPIAN_PATH):
48            shutil.rmtree(settings.HAYSTACK_XAPIAN_PATH)
49        super(BaseTestCase, self).tearDown()
50
Note: See TracBrowser for help on using the repository browser.