source: main/trunk/openPLM/apps/document3D/tests/views.py @ 1465

Revision 1465, 10.3 KB checked in by pcosquer, 9 years ago (diff)

document3D: rewrites (optimize) function to get a product from a step file

Line 
1from openPLM.apps.document3D.views import *
2from openPLM.apps.document3D.models import *
3from openPLM.apps.document3D.forms import *
4from openPLM.plmapp.tests.views import CommonViewTest
5from openPLM.apps.document3D.models import Document3DController
6from openPLM.plmapp.decomposers import DecomposersManager
7from django.core.files import File
8
9
10
11class view_3dTest(CommonViewTest):
12
13    def setUp(self):
14        super(view_3dTest, self).setUp()
15        self.document = Document3DController.create('doc1', 'Document3D',
16                'a', self.user, self.DATA)
17
18    def update_time(self,data):
19        data.update({u'last_modif_time': [u'%s-%s-%s %s:%s:%s'%(self.document.mtime.year,self.document.mtime.month,self.document.mtime.day,self.document.mtime.hour,self.document.mtime.minute,self.document.mtime.second)],
20           u'last_modif_microseconds' : [u'%s'%self.document.mtime.microsecond]
21           })
22
23    def update_data(self,new_doc_file,update_time=True):
24        data={}
25        new_ArbreFile=ArbreFile.objects.get(stp=new_doc_file)
26        product =Product_from_Arb(json.loads(new_ArbreFile.file.read()))
27
28        index=[1]
29        lifecycle='draft_official_deprecated'
30        part_type='Part'
31        decomposition_fromPOST_data(data,product,index,self.group.id,lifecycle,part_type)
32        if update_time:
33            self.update_time(data)
34
35        return data
36
37    def test_view3D_stp_decompose(self):
38        f=open("apps/document3D/data_test/test2.stp")
39        myfile = File(f)
40        new_doc_file=self.document.add_file(myfile)
41        self.controller.attach_to_document(self.document.object)
42
43        data=self.update_data(new_doc_file)
44
45        self.assertTrue(DecomposersManager.is_decomposable(self.controller.object))
46        self.post(self.base_url+"decompose/"+str(new_doc_file.id)+"/",data)
47        self.assertFalse(DecomposersManager.is_decomposable(self.controller.object))
48        reponse = self.get(self.document.object.plmobject_url+"3D/")
49        self.assertEqual(len(reponse.context["GeometryFiles"]), 5)
50
51    def test_3D_no_stp_associe(self):
52        response = self.get(self.document.object.plmobject_url+"3D/")
53        self.assertFalse(response.context["GeometryFiles"])
54        self.assertFalse(response.context["javascript_arborescense"])
55
56    def test_3D_stp_associe_sans_arborescense(self):
57        f=open("apps/document3D/data_test/test.stp")
58        myfile = File(f)
59        new_doc_file=self.document.add_file(myfile)
60        ArbreFile.objects.get(stp=new_doc_file).delete()
61        response = self.get(self.document.object.plmobject_url+"3D/")
62        self.assertEqual(3, len(list(response.context["GeometryFiles"])))
63        self.assertFalse(response.context["javascript_arborescense"])
64
65    def test_3D_stp_valide_no_info(self):
66        f=open("apps/document3D/data_test/valid_sans_information.stp")
67        myfile = File(f)
68        new_doc_file=self.document.add_file(myfile)
69        response = self.get(self.document.object.plmobject_url+"3D/")
70        self.assertFalse(response.context["GeometryFiles"])
71        self.assertTrue(response.context["javascript_arborescense"])
72
73    def test_3D_stp_associe_sans_geometry_with_arborescense(self):
74        f=open("apps/document3D/data_test/test.stp")
75        myfile = File(f)
76        new_doc_file=self.document.add_file(myfile)
77        GeometryFile.objects.filter(stp=new_doc_file).delete()
78        response = self.get(self.document.object.plmobject_url+"3D/")
79        self.assertFalse(response.context["GeometryFiles"])
80        self.assertTrue(response.context["javascript_arborescense"])
81
82    def test_decompose_bom_child(self):
83        f=open("apps/document3D/data_test/test.stp")
84        myfile = File(f)
85        new_doc_file=self.document.add_file(myfile)
86        self.controller.attach_to_document(self.document.object)
87        response = self.get(self.base_url + "BOM-child/", page="BOM-child")
88        self.assertEqual(0, len(list(response.context["children"])))
89        msg = response.context["decomposition_msg"]
90        self.assertTrue(msg)
91
92
93    def test_decompose_bom_child_whit_child_decomposable(self):
94        child2 = PartController.create("c2", "Part", "a", self.user, self.DATA)
95        self.controller.add_child(child2, 10, 20)
96        f=open("apps/document3D/data_test/test.stp")
97        myfile = File(f)
98        new_doc_file=self.document.add_file(myfile)
99        child2.attach_to_document(self.document.object)
100        self.controller.attach_to_document(self.document.object)
101        response = self.get(self.base_url + "BOM-child/", page="BOM-child")
102        self.assertEqual(1, len(list(response.context["children"])))
103        msg = response.context["decomposition_msg"]
104        self.assertTrue(msg)
105        decomposable_children = response.context["decomposable_children"]
106        self.assertTrue(response.context["children"][0].link.child.id
107            in decomposable_children)
108
109
110    def test_try_decompose_bom_child_whit_no_links(self):
111        f=open("apps/document3D/data_test/valid_sans_information.stp")
112        myfile = File(f)
113        new_doc_file=self.document.add_file(myfile)
114        self.controller.attach_to_document(self.document.object)
115        response = self.get(self.base_url+"decompose/"+str(new_doc_file.id)+"/")
116        self.assertRedirects(response, self.base_url + "BOM-child/")
117
118
119    #verificar los links creados en las buenas coordenadas
120    def test_display_decompose_form_initial(self):
121        f=open("apps/document3D/data_test/test.stp")
122        myfile = File(f)
123        new_doc_file=self.document.add_file(myfile)
124        self.controller.attach_to_document(self.document.object)
125        response = self.get(self.base_url+"decompose/"+str(new_doc_file.id)+"/")
126        # TODO: check forms
127
128
129    def test_display_decompose_time_modification_diferent(self):
130        f=open("apps/document3D/data_test/test.stp")
131        myfile = File(f)
132        new_doc_file=self.document.add_file(myfile)
133        self.controller.attach_to_document(self.document.object)
134
135        data=self.update_data(new_doc_file,update_time=False)
136
137        data.update({u'last_modif_time': [u'%s-%s-%s %s:%s:%s'%             (self.document.mtime.year,(self.document.mtime.month),self.document.mtime.day,self.document.mtime.hour-1,self.document.mtime.minute,self.document.mtime.second)],
138           u'last_modif_microseconds' : [u'%s'%(self.document.mtime.microsecond-1)]
139           })
140        reponse_post = self.post(self.base_url+"decompose/"+str(new_doc_file.id)+"/",data)
141        self.assertEqual(reponse_post.context["extra_errors"],"The Document3D associated with the file STEP to decompose has been modified by another user while the forms were refilled:Please restart the process")
142
143
144
145    def test_display_decompose_time_modification_invalid(self):
146        f=open("apps/document3D/data_test/test.stp")
147        myfile = File(f)
148        new_doc_file=self.document.add_file(myfile)
149        self.controller.attach_to_document(self.document.object)
150
151        data=self.update_data(new_doc_file,update_time=False)
152        data.update({u'last_modif_time': [u'not_valid'],
153           u'last_modif_microseconds' : [u'not_valid']
154           })
155        reponse_post = self.post(self.base_url+"decompose/"+str(new_doc_file.id)+"/",data)
156        self.assertEqual(reponse_post.context["extra_errors"], INVALID_TIME_ERROR)
157
158
159    def test_display_decompose_file_locked(self):
160        f=open("apps/document3D/data_test/test.stp")
161        myfile = File(f)
162        new_doc_file=self.document.add_file(myfile)
163        self.document.lock(new_doc_file)
164        self.controller.attach_to_document(self.document.object)
165
166        data=self.update_data(new_doc_file)
167        response = self.client.post(self.base_url+"decompose/"+str(new_doc_file.id)+"/",data)
168        self.assertTemplateUsed(response, "error.html")
169
170    def test_display_decompose_Document_part_doc_links_Error(self):
171        f=open("apps/document3D/data_test/test.stp")
172        myfile = File(f)
173        new_doc_file=self.document.add_file(myfile)
174        self.controller.attach_to_document(self.document.object)
175        data=self.update_data(new_doc_file)
176        #u'reference': [u'PART_00001']
177
178        data.update({
179                "1-part-reference" : [u'2'],
180                "1-part-revision" : [u'2'],
181                "2-part-reference" : [u'2'],
182                "2-part-revision" : [u'2'],
183        })
184
185        reponse=self.post(self.base_url+"decompose/"+str(new_doc_file.id)+"/",data)
186        self.assertTrue(reponse.context["extra_errors"].startswith(u"Columns reference, type, revision are not unique"))
187
188
189    def test_display_decompose_Document3D_decomposer_Error(self):
190        f=open("apps/document3D/data_test/test.stp")
191        myfile = File(f)
192        new_doc_file=self.document.add_file(myfile)
193        self.controller.attach_to_document(self.document.object)
194        data=self.update_data(new_doc_file)
195        GeometryFile.objects.filter(stp=new_doc_file).delete()
196        url = u"%sdecompose/%d/" % (self.base_url, new_doc_file.id)
197        response = self.client.post(url, data)
198        self.assertTemplateUsed(response, "error.html")
199
200def decomposition_fromPOST_data(data,product,index,group,lifecycle,part_type):
201
202    if product.links:
203        for order , link in enumerate(product.links):
204            data.update({
205                    "%s-order"%index[0] : [u'%s'%((order+1)*10)],
206                    "%s-quantity"%index[0] : [u'%s'%link.quantity],
207                    "%s-unit"%index[0] : [u'-'],
208            })
209            if not link.product.visited:
210                data.update({
211                "%s-type_part"%index[0] : [u'%s'%part_type],
212                "%s-part-reference"%index[0] : [u'%s'%index[0]],
213                "%s-part-revision"%index[0] : [u'%s'%index[0]],
214                "%s-part-name"%index[0]     :  [u'%s'%index[0]],
215                "%s-part-lifecycle"%index[0] : [u'%s'%lifecycle] ,
216                "%s-part-group"%index[0] : [u'%s'%group] ,
217                "%s-document-reference"%index[0] : [u'%s'%index[0]],
218                "%s-document-revision"%index[0] : [u'%s'%index[0]],
219                "%s-document-name"%index[0]     :  [u'%s'%index[0]],
220                "%s-document-lifecycle"%index[0] : [u'%s'%lifecycle] ,
221                "%s-document-group"%index[0] :[u'%s'%group] ,
222                })
223                link.product.visited=True
224                index[0]+=1
225                decomposition_fromPOST_data(data,link.product,index,group,lifecycle,part_type)
226            else:
227                index[0]+=1
228
Note: See TracBrowser for help on using the repository browser.