source: main/branches/3D/openPLM/plmapp/tests/base.py @ 662

Revision 662, 1.5 KB checked in by pcosquer, 9 years ago (diff)

3D branch: merge changes from trunk (rev [661])

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
9class BaseTestCase(TestCase):
10    CONTROLLER = PLMObjectController
11    TYPE = "Part"
12    DATA = {}
13
14    def setUp(self):
15        self.cie = User.objects.create(username="company")
16        p = self.cie.get_profile()
17        p.is_contributor = True
18        p.save()
19        self.leading_group = GroupInfo.objects.create(name="leading_group",
20                owner=self.cie, creator=self.cie)
21        self.cie.groups.add(self.leading_group)
22        self.user = User(username="user")
23        self.user.set_password("password")
24        self.user.email = "test@example.net"
25        self.user.save()
26        self.user.get_profile().is_contributor = True
27        self.user.get_profile().save()
28        self.group = GroupInfo(name="grp", owner=self.user, creator=self.user,
29                description="grp")
30        self.group.save()
31        self.user.groups.add(self.group)
32        self.DATA["group"] = self.group
33
34    def create(self, ref="Part1"):
35        return self.CONTROLLER.create(ref, self.TYPE, "a", self.user, self.DATA)
36
37    def get_file(self, name="temp.txt", data="data"):
38        f = ContentFile(data)
39        f.name = name
40        return f
41
42    def tearDown(self):
43        from haystack import backend
44        backend.SearchBackend.inmemory_db = None
45        super(BaseTestCase, self).tearDown()
46
Note: See TracBrowser for help on using the repository browser.