Exemplo n.º 1
0
    def test_make_data_list(self):
        from presta.utils.presta_api import make_data_list

        # Test already existing values
        lines = [("1", {"quantity": "51"})]
        data = [("1", "25", "25", "iPod Nano", "Blue, 16Go", {"price": "41.806020", "quantity": "51"})]
        sync_type = "ID"
        res = make_data_list(data, sync_type, lines)
        self.assertEquals(res["result"], "success")
        self.assertEquals(res["response"], [])

        # Test new values
        lines = [("1", {"quantity": "52"})]
        res = make_data_list(data, sync_type, lines)
        self.assertEquals(res["result"], "success")
        self.assertEquals(res["response"], [("1", "25", {"quantity": "52"})])

        # Test error
        lines = []
        res = make_data_list(data, sync_type, lines)
        self.assertEquals(res["result"], "error")
        self.assertEquals(res["response"].keys()[0], "sync_type")
Exemplo n.º 2
0
 def prepare_data_for_update(self, lines):
     """Retrieves all the data, then generates data list for update"""
     from presta.utils.presta_api import make_data_list
     data_full = []
     page = 0
     while not self.api.finished:
         data, error_dict = self.get_data(page, 1000)
         if error_dict:
             return {'result': 'error', 'response': error_dict}
         page += 1
         data_full.extend(data)
     result = make_data_list(data_full, self.sync_type, lines)
     return result
Exemplo n.º 3
0
    def test_make_data_list(self):
        from presta.utils.presta_api import make_data_list
        # Test already existing values
        lines = [('1', {'quantity': '51'})]
        data = [('1', '25', '25', 'iPod Nano', 'Blue, 16Go', {
            'price': '41.806020',
            'quantity': '51'
        })]
        sync_type = 'ID'
        res = make_data_list(data, sync_type, lines)
        self.assertEquals(res['result'], 'success')
        self.assertEquals(res['response'], [])

        # Test new values
        lines = [('1', {'quantity': '52'})]
        res = make_data_list(data, sync_type, lines)
        self.assertEquals(res['result'], 'success')
        self.assertEquals(res['response'], [('1', '25', {'quantity': '52'})])

        # Test error
        lines = []
        res = make_data_list(data, sync_type, lines)
        self.assertEquals(res['result'], 'error')
        self.assertEquals(res['response'].keys()[0], 'sync_type')