def test_prepare_batch_request_with_params(self):
        batch_request = FacebookBatchRequest(access_token='fake_token',
                                             requests=[self.req1, self.req4])
        expected_batch = (
            '[{"headers": {"Conent-Type": "application/json"}, "method": "GET", "relative_url": "/v2.12/123?access_token=fake_token", "name": "0"}, '
            '{"headers": {"Conent-Type": "application/json"}, "method": "GET", "relative_url": "/v2.12/123?access_token=fake_token&fields=name%2C+descripti%C3%B3n", "name": "1"}]'
        )

        batch_request.prepare_batch_request()
        self.assertEqual(sorted(batch_request.post_params['batch']),
                         sorted(expected_batch))
        self.assertTrue(batch_request.post_params['include_headers'])
    def test_add_a_named_dict_of_requests(self):
        requests = {
            'first': self.req1,
            'second': self.req2,
            'third': self.req3,
        }
        batch_request = FacebookBatchRequest(requests=requests,
                                             access_token='fake_token')
        batch_request.prepare_batch_request()

        for request in batch_request:
            self.assertEqual(requests[request['name']], request['request'])
Beispiel #3
0
 def test_prepare_batch_request(self):
     batch_request = FacebookBatchRequest(
         access_token='fake_token',
         requests=[self.req1, self.req2, self.req3]
     )
     expected_batch = (
         '[{"headers": {"Conent-Type": "application/json"}, "method": "GET", "relative_url": "/v2.5/123?access_token=fake_token", "name": "0"}, '
         '{"body": "foo=bar", "headers": {}, "method": "POST", "relative_url": "/v2.5/123", "name": "1"}, '
         '{"access_token": "other_token", "headers": {}, "method": "DELETE", "relative_url": "/v2.5/123?access_token=other_token", "name": "2"}]'
     )
     batch_request.prepare_batch_request()
     self.assertEqual(sorted(batch_request.post_params['batch']), sorted(expected_batch))
     self.assertTrue(batch_request.post_params['include_headers'])
Beispiel #4
0
    def test_batch_request_with_files(self):
        request = FacebookRequest(
            endpoint='/foo',
            method='POST',
            params={
                'message': 'foo',
                'source': FacebookFile(
                    path='{base_path}/foo.txt'.format(
                        base_path=os.path.dirname(os.path.abspath(__file__))
                    ),
                )
            }
        )
        batch_request = FacebookBatchRequest(
            access_token='fake_token',
            requests=[request],
        )
        expected_batch = '[{"body": "message=foo", "attached_files": "%(attached_files)s", "name": "0", "relative_url": "/v2.5/foo", "headers": {}, "method": "POST"}]' % dict(attached_files=batch_request.requests[0].get('attached_files'))
        batch_request.prepare_batch_request()

        self.assertEqual(sorted(batch_request.post_params['batch']), sorted(expected_batch))