Exemple #1
0
    def test_raw_query(self):
        bulk = SalesforceBulkipy(self.sessionId, self.endpoint)
        self.bulk = bulk

        job_id = bulk.create_query_job("Contact")
        self.jobs.append(job_id)
        self.assertIsNotNone(re.match("\w+", job_id))

        batch_id = bulk.query(job_id,
                              "Select Id,Name,Email from Contact Limit 1000")
        self.assertIsNotNone(re.match("\w+", batch_id))

        while not bulk.is_batch_done(job_id, batch_id):
            print("Job not done yet...")
            print(bulk.batch_status(job_id, batch_id))
            time.sleep(2)

        self.results = ""

        def save_results(tfile, **kwargs):
            print("in save results")
            self.results = tfile.read()

        flag = bulk.get_batch_results(job_id, batch_id, callback=save_results)
        self.assertTrue(flag)
        self.assertTrue(len(self.results) > 0)
        self.assertIn('"', self.results)
Exemple #2
0
    def test_csv_query(self):
        bulk = SalesforceBulkipy(self.sessionId, self.endpoint)
        self.bulk = bulk

        job_id = bulk.create_query_job("Account")
        self.jobs.append(job_id)
        self.assertIsNotNone(re.match("\w+", job_id))

        batch_id = bulk.query(job_id, "Select Id,Name,Description from Account Limit 10000")
        self.assertIsNotNone(re.match("\w+", batch_id))
        bulk.wait_for_batch(job_id, batch_id, timeout=120)

        self.results = None
        def save_results1(rows, **kwargs):
            self.results = rows

        flag = bulk.get_batch_results(job_id, batch_id, callback = save_results1, parse_csv=True)
        self.assertTrue(flag)
        results = self.results
        self.assertTrue(len(results) > 0)
        self.assertTrue(isinstance(results,list))
        self.assertEqual(results[0], ['Id','Name','Description'])
        self.assertTrue(len(results) > 3)

        self.results = None
        self.callback_count = 0
        def save_results2(rows, **kwargs):
            self.results = rows
            print rows
            self.callback_count += 1

        batch = len(results) / 3
        self.callback_count = 0
        flag = bulk.get_batch_results(job_id, batch_id, callback = save_results2, parse_csv=True, batch_size=batch)
        self.assertTrue(self.callback_count >= 3)
Exemple #3
0
    def test_csv_query(self):
        bulk = SalesforceBulkipy(self.sessionId, self.endpoint)
        self.bulk = bulk

        job_id = bulk.create_query_job("Account")
        self.jobs.append(job_id)
        self.assertIsNotNone(re.match("\w+", job_id))

        batch_id = bulk.query(
            job_id, "Select Id,Name,Description from Account Limit 10000")
        self.assertIsNotNone(re.match("\w+", batch_id))
        bulk.wait_for_batch(job_id, batch_id, timeout=120)

        results = bulk.get_all_results_for_batch(batch_id=batch_id,
                                                 job_id=job_id,
                                                 parse_csv=True)
        results = list(list(x) for x in results)

        self.assertTrue(len(results) > 0)
        self.assertEqual(results[0][0], ['Id', 'Name', 'Description'])
        self.assertTrue(len(results[0]) > 3)

        results = bulk.get_batch_result_iter(batch_id=batch_id,
                                             job_id=job_id,
                                             parse_csv=True)
        results = list(results)

        self.assertTrue(len(results) > 3)
        self.assertTrue(isinstance(results[0], dict))
        self.assertIn('Id', results[0])
        self.assertIn('Name', results[0])
        self.assertIn('Description', results[0])
Exemple #4
0
    def test_raw_query(self):
        bulk = SalesforceBulkipy(self.sessionId, self.endpoint)
        self.bulk = bulk

        job_id = bulk.create_query_job("Contact")
        self.jobs.append(job_id)
        self.assertIsNotNone(re.match("\w+", job_id))

        # test the job state method
        self.assertEqual(bulk.job_state(job_id=job_id), 'Open')

        batch_id = bulk.query(job_id,
                              "Select Id,Name,Email from Contact Limit 1000")
        self.assertIsNotNone(re.match("\w+", batch_id))

        while not bulk.is_batch_done(job_id, batch_id):
            print("Job not done yet...")
            print(bulk.batch_status(job_id, batch_id))
            time.sleep(2)

        results = bulk.get_all_results_for_batch(batch_id=batch_id,
                                                 job_id=job_id)
        results = list(list(x) for x in results)

        self.assertTrue(len(results) > 0)
        self.assertTrue(len(results[0]) > 0)
        self.assertIn('"', results[0][0])

        results = bulk.get_batch_result_iter(batch_id=batch_id, job_id=job_id)
        results = list(results)

        self.assertTrue(len(results) > 0)
        self.assertTrue(len(results[0]) > 0)
        self.assertIn('"', results[0][0])
Exemple #5
0
    def test_csv_upload(self):
        batches_count = 5
        object_type = 'Contact'
        bulk = SalesforceBulkipy(self.sessionId, self.endpoint)
        self.bulk = bulk

        job_id = bulk.create_insert_job(object_type)
        self.jobs.append(job_id)
        self.assertIsNotNone(re.match("\w+", job_id))

        batch_ids = []
        content = open("example.csv").read()

        for i in range(batches_count):
            batch_id = bulk.query(job_id, content)
            self.assertIsNotNone(re.match("\w+", batch_id))
            batch_ids.append(batch_id)

        for batch_id in batch_ids:
            bulk.wait_for_batch(job_id, batch_id, timeout=120)

        self.results = None

        def save_results1(rows, failed, remaining):
            self.results = rows

        for batch_id in batch_ids:
            flag = bulk.get_upload_results(job_id,
                                           batch_id,
                                           callback=save_results1)
            self.assertTrue(flag)
            results = self.results
            self.assertTrue(len(results) > 0)
            self.assertTrue(isinstance(results, list))
            # self.assertEqual(results[0], UploadResult('Id','Success','Created','Error'))
            self.assertEqual(len(results), 3)

        self.results = None
        self.callback_count = 0

        def save_results2(rows, failed, remaining):
            self.results = rows
            self.callback_count += 1

        batch = len(results) / 3
        self.callback_count = 0
        flag = bulk.get_upload_results(job_id,
                                       batch_id,
                                       callback=save_results2,
                                       batch_size=batch)
        self.assertTrue(self.callback_count >= 3)