Exemple #1
0
 def test_function_return_response_bad_request_if_non_mathing_data(self):
     kwargs = {
         'browTabName': 'users_table',
         'parent_id': "",
         'sendMail': "",
         'selRowIndex': '0',
         'model': 'FOLDER',
         'id': '1',
         'name': 'fred',
     }
     ajax_data = DummyAjaxRequest(**kwargs).ajax_data()
     request = self.client.request()
     request.POST = ajax_data
     request.session = {}
     response = ajaxSelRowIndexToSession(request)
     self.assertEqual(request.session, {})
     self.assertTrue(isinstance(response, HttpResponseBadRequest))
     expected = [
         b'ajaxSelRowIndexToSession: \n Bad data in request.POST: model name does not correspond to table name \n model=FOLDER \n browTabName=users_table'
     ]
     self.assertEqual(response._container, expected)
     expected = {
         'content-type': ('Content-Type', 'text/html; charset=utf-8')
     }
     self.assertEqual(response._headers, expected)
Exemple #2
0
    def test_function(self):
        kwargs = {
                    'browTabName' :'users_table',
                    'parent_id'   :"",
                    'sendMail'    :"",
                    'selRowIndex' :'0',
                    'model'       :'user',
                    'id'          :'1',
                    'name'        :'fred',
                }
        ajax_data = DummyAjaxRequest(**kwargs).ajax_data()
        request = self.client.request()
        request.POST = ajax_data
        request.session = {}
        response = ajaxSelRowIndexToSession(request)

        # Чи в сесію записано правильні дані?
        expected = {'Selections': {'users_table': {'': {'model': "user", 'id': "1", 'selRowIndex': '0'}}}}
        self.assertEqual(request.session, expected)
        self.assertTrue(isinstance(response, HttpResponse))

        # Чи ф-ція повертає правильний response?
        expected = [b'{"server_response": {"id": "1", "selRowIndex": "0", "model": "user"}}']
        self.assertEqual(json.loads(response._container[0].decode()) , json.loads(expected[0].decode()))
        expected = {'content-type': ('Content-Type', 'application/json')}
        self.assertEqual(response._headers, expected)
Exemple #3
0
 def test_function_return_response_bad_request_if_no_client_request(self):
     request = self.client.request()
     request.POST = {}
     request.session = {}
     response = ajaxSelRowIndexToSession(request)
     self.assertEqual(request.session, {})
     self.assertTrue(isinstance(response, HttpResponseBadRequest))
     expected = [b"ajaxSelRowIndexToSession: No 'client_request' in request.POST"]
     self.assertEqual(response._container, expected)
     expected = {'content-type': ('Content-Type', 'text/html; charset=utf-8')}
     self.assertEqual(response._headers, expected)
Exemple #4
0
 def test_function_return_response_bad_request_if_no_client_request(self):
     request = self.client.request()
     request.POST = {}
     request.session = {}
     response = ajaxSelRowIndexToSession(request)
     self.assertEqual(request.session, {})
     self.assertTrue(isinstance(response, HttpResponseBadRequest))
     expected = [
         b"ajaxSelRowIndexToSession: No 'client_request' in request.POST"
     ]
     self.assertEqual(response._container, expected)
     expected = {
         'content-type': ('Content-Type', 'text/html; charset=utf-8')
     }
     self.assertEqual(response._headers, expected)
Exemple #5
0
 def test_function_return_response_bad_request_if_non_mathing_data(self):
     kwargs = {
                 'browTabName' :'users_table',
                 'parent_id'   :"",
                 'sendMail'    :"",
                 'selRowIndex' :'0',
                 'model'       :'FOLDER',
                 'id'          :'1',
                 'name'        :'fred',
             }
     ajax_data = DummyAjaxRequest(**kwargs).ajax_data()
     request = self.client.request()
     request.POST = ajax_data
     request.session = {}
     response = ajaxSelRowIndexToSession(request)
     self.assertEqual(request.session, {})
     self.assertTrue(isinstance(response, HttpResponseBadRequest))
     expected = [b'ajaxSelRowIndexToSession: \n Bad data in request.POST: model name does not correspond to table name \n model=FOLDER \n browTabName=users_table']
     self.assertEqual(response._container, expected)
     expected = {'content-type': ('Content-Type', 'text/html; charset=utf-8')}
     self.assertEqual(response._headers, expected)
Exemple #6
0
    def test_function(self):
        kwargs = {
            'browTabName': 'users_table',
            'parent_id': "",
            'sendMail': "",
            'selRowIndex': '0',
            'model': 'user',
            'id': '1',
            'name': 'fred',
        }
        ajax_data = DummyAjaxRequest(**kwargs).ajax_data()
        request = self.client.request()
        request.POST = ajax_data
        request.session = {}
        response = ajaxSelRowIndexToSession(request)

        # Чи в сесію записано правильні дані?
        expected = {
            'Selections': {
                'users_table': {
                    '': {
                        'model': "user",
                        'id': "1",
                        'selRowIndex': '0'
                    }
                }
            }
        }
        self.assertEqual(request.session, expected)
        self.assertTrue(isinstance(response, HttpResponse))

        # Чи ф-ція повертає правильний response?
        expected = [
            b'{"server_response": {"id": "1", "selRowIndex": "0", "model": "user"}}'
        ]
        self.assertEqual(json.loads(response._container[0].decode()),
                         json.loads(expected[0].decode()))
        expected = {'content-type': ('Content-Type', 'application/json')}
        self.assertEqual(response._headers, expected)