예제 #1
0
 def test_parseXHRClientRequest_raise_error_if_unknown_table(self):
     kwargs = {
                 'browTabName' :'TABLE',
                 'model'       :'folder',
             }
     ajax_data = DummyXHRrequest(**kwargs).ajax_data()
     request = self.client.request()
     request.POST = ajax_data
     with self.assertRaises(ValueError):
         parseXHRClientRequest(request.POST)
 def test_parseXHRClientRequest_raise_error_if_unknown_table(self):
     kwargs = {
         'browTabName': 'TABLE',
         'model': 'folder',
     }
     ajax_data = DummyXHRrequest(**kwargs).ajax_data()
     request = self.client.request()
     request.POST = ajax_data
     with self.assertRaises(ValueError):
         parseXHRClientRequest(request.POST)
 def get_XHR_data(self, request, rqst):
     # Розбираємо дані від клієнта:
     try:
         d = parseXHRClientRequest(request.META)
     except ValueError as err:
         # запит від клієнта містить невідповідні дані:
         print('get_XHR_data:', err.args)
         return None, None
     rqst = get_namespace_from_dict(d, rqst, True)
     # rqst.parent_id            = d.get('parent_id')
     # rqst.model                = d.get('model')
     # rqst.id                   = d.get('id')
     # rqst.name                 = d.get('name')
     # rqst.target_id            = d.get('target_id')
     # rqst.fileName             = d.get('fileName')
     # rqst.fileSize             = d.get('fileSize')
     # rqst.fileType             = d.get('fileType')
     # rqst.fileLastModifiedDate = d.get('fileLastModifiedDate')
     if rqst.model == "folder":
         element = Folder.objects.get(id=rqst.id)
     elif rqst.model == "report":
         element = Report.objects.get(id=rqst.id)
     else:
         return None, None
     if not element:
         rqst = None
     return element, rqst
예제 #4
0
 def get_XHR_data(self, request, rqst):
     # Розбираємо дані від клієнта:
     try:
         d = parseXHRClientRequest(request.META)
     except ValueError as err:
         # запит від клієнта містить невідповідні дані:
         print('get_XHR_data:', err.args)
         return None, None
     rqst = get_namespace_from_dict(d, rqst, True)
     # rqst.parent_id            = d.get('parent_id')
     # rqst.model                = d.get('model')
     # rqst.id                   = d.get('id')
     # rqst.name                 = d.get('name')
     # rqst.target_id            = d.get('target_id')
     # rqst.fileName             = d.get('fileName')
     # rqst.fileSize             = d.get('fileSize')
     # rqst.fileType             = d.get('fileType')
     # rqst.fileLastModifiedDate = d.get('fileLastModifiedDate')
     if rqst.model == "folder":
         element = Folder.objects.get(id=rqst.id)
     elif rqst.model == "report":
         element = Report.objects.get(id=rqst.id)
     else:
         return None, None
     if not element:
         rqst = None
     return element, rqst
 def test_parseXHRClientRequest_if_no_model(self):
     kwargs = {
         'browTabName': 'users_table',
     }
     ajax_data = DummyXHRrequest(**kwargs).ajax_data()
     request = self.client.request()
     request.POST = ajax_data
     expected = {
         'browTabName': 'users_table',
     }
     self.assertEqual(parseXHRClientRequest(request.POST), expected)
예제 #6
0
 def test_parseXHRClientRequest_if_no_model(self):
     kwargs = {
                 'browTabName' :'users_table',
             }
     ajax_data = DummyXHRrequest(**kwargs).ajax_data()
     request = self.client.request()
     request.POST = ajax_data
     expected = {
                 'browTabName' :'users_table',
             }
     self.assertEqual(parseXHRClientRequest(request.POST), expected)
 def test_parseXHRClientRequest_2(self):
     kwargs = {
         'browTabName': 'users_table',
         'parent_id': None,
         'sendMail': None,
         'selRowIndex': '0',
         'model': 'user',
         'id': '1',
         'name': 'fred',
     }
     ajax_data = DummyXHRrequest(**kwargs).ajax_data()
     request = self.client.request()
     request.POST = ajax_data
     expected = kwargs
     self.assertEqual(parseXHRClientRequest(request.POST), expected)
예제 #8
0
 def test_parseXHRClientRequest_2(self):
     kwargs = {
                 'browTabName' :'users_table',
                 'parent_id'   :None,
                 'sendMail'    :None,
                 'selRowIndex' :'0',
                 'model'       :'user',
                 'id'          :'1',
                 'name'        :'fred',
             }
     ajax_data = DummyXHRrequest(**kwargs).ajax_data()
     request = self.client.request()
     request.POST = ajax_data
     expected = kwargs
     self.assertEqual(parseXHRClientRequest(request.POST), expected)
 def test_parseXHRClientRequest(self):
     request = self.client.request()
     request.META = {
         'PYTHONIOENCODING':
         'UTF-8',
         'HTTP_X_CLIENT_REQUEST':
         '%7B%22browTabName%22%3A%22folders_contents%22%2C%22parent_id%22%3A%227%22%2C%22selRowIndex%22%3A%222%22%2C%22model%22%3A%22report%22%2C%22id%22%3A%22130%22%2C%22name%22%3A%22%D0%92%D1%96%D0%B4%D1%80%D1%8F%D0%B4%D0%B6%D0%B5%D0%BD%D0%BD%D1%8F.tif%22%7D',
     }
     expected = {
         'model': 'report',
         'browTabName': 'folders_contents',
         'selRowIndex': '2',
         'id': '130',
         'parent_id': '7',
         'name': 'Відрядження.tif'
     }
     self.assertEqual(parseXHRClientRequest(request.META), expected)
예제 #10
0
 def test_parseXHRClientRequest(self):
     request = self.client.request()
     request.META = {'PYTHONIOENCODING': 'UTF-8', 'HTTP_X_CLIENT_REQUEST': '%7B%22browTabName%22%3A%22folders_contents%22%2C%22parent_id%22%3A%227%22%2C%22selRowIndex%22%3A%222%22%2C%22model%22%3A%22report%22%2C%22id%22%3A%22130%22%2C%22name%22%3A%22%D0%92%D1%96%D0%B4%D1%80%D1%8F%D0%B4%D0%B6%D0%B5%D0%BD%D0%BD%D1%8F.tif%22%7D', }
     expected = {'model': 'report', 'browTabName': 'folders_contents', 'selRowIndex': '2', 'id': '130', 'parent_id': '7', 'name': 'Відрядження.tif'}
     self.assertEqual(parseXHRClientRequest(request.META), expected)