コード例 #1
0
 def test_download_feed_invalid_date(self):
     feed_req_obj = Feed(FeedType.ITEM.value, FeedScope.BOOTSTRAP.value, '220', 'EBAY_US', 'Bearer v^1 ...',
                         download_location='../tests/test-data/', feed_date='2019-02-01')
     get_response = feed_req_obj.get()
     self.assertEquals(get_response.status_code, FAILURE_CODE)
     self.assertIsNotNone(get_response.message)
     self.assertIsNotNone(get_response.file_path, 'file_path is None in the response')
コード例 #2
0
 def test_default_values(self):
     feed_req_obj = Feed(None, None, '220', 'EBAY_US', 'v^1 ...')
     self.assertEquals(feed_req_obj.feed_type, FeedType.ITEM.value)
     self.assertEquals(feed_req_obj.feed_scope, FeedScope.DAILY.value)
     self.assertTrue(feed_req_obj.token.startswith('Bearer'), 'Bearer is missing from token')
     self.assertEquals(feed_req_obj.feed_date, get_formatted_date(feed_req_obj.feed_type))
     self.assertEquals(feed_req_obj.environment, Environment.PRODUCTION.value)
     self.assertEquals(feed_req_obj.download_location, DEFAULT_DOWNLOAD_LOCATION)
     self.assertEquals(feed_req_obj.file_format, FileFormat.GZIP.value)
コード例 #3
0
 def test_download_feed_daily_multiple_calls(self):
     feed_req_obj = Feed(FeedType.ITEM.value, FeedScope.BOOTSTRAP.value, self.test_category_2,
                         self.test_marketplace, self.test_token, download_location='../tests/test-data/')
     get_response = feed_req_obj.get()
     # store the file path for clean up
     self.file_paths.append(get_response.file_path)
     # assert the result
     self.assertEquals(get_response.status_code, SUCCESS_CODE)
     self.assertIsNotNone(get_response.message)
     self.assertIsNotNone(get_response.file_path, 'file has not been created')
     self.assertTrue(isfile(get_response.file_path), 'file_path is not pointing to a file. file_path: %s'
                     % get_response.file_path)
     # check the file size and name
     self.assertTrue(getsize(get_response.file_path) > PROD_CHUNK_SIZE, 'feed file is less than %s. file_path: %s'
                     % (PROD_CHUNK_SIZE, get_response.file_path))
     self.assertTrue(FeedPrefix.BOOTSTRAP.value in get_response.file_path,
                     'feed file name does not have %s in it. file_path: %s'
                     % (FeedPrefix.BOOTSTRAP.value, get_response.file_path))
     file_dir, file_name = split(abspath(get_response.file_path))
     self.assertEquals(abspath(feed_req_obj.download_location), file_dir)
コード例 #4
0
 def test_download_feed_daily(self):
     test_date = get_formatted_date(FeedType.ITEM, -4)
     feed_req_obj = Feed(FeedType.ITEM.value, FeedScope.DAILY.value, self.test_category_1,
                         self.test_marketplace, self.test_token, download_location='../tests/test-data/',
                         feed_date=test_date)
     get_response = feed_req_obj.get()
     # store the file path for clean up
     self.file_paths.append(get_response.file_path)
     # assert the result
     self.assertEquals(get_response.status_code, SUCCESS_CODE)
     self.assertIsNotNone(get_response.message)
     self.assertIsNotNone(get_response.file_path, 'file_path is None')
     self.assertTrue(isfile(get_response.file_path), 'file_path is not pointing to a file. file_path: %s'
                     % get_response.file_path)
     # check the file size and name
     self.assertTrue(getsize(get_response.file_path) > 0, 'feed file is empty. file_path: %s'
                     % get_response.file_path)
     self.assertTrue(FeedPrefix.DAILY.value in get_response.file_path,
                     'feed file name does not have %s in it. file_path: %s' %
                     (FeedPrefix.DAILY.value, get_response.file_path))
     file_dir, file_name = split(abspath(get_response.file_path))
     self.assertEquals(abspath(feed_req_obj.download_location), file_dir)
コード例 #5
0
 def __create_requests(self, token):
     if ConfigField.REQUESTS.value not in self.__config_json_obj:
         raise ConfigError('No \"%s\" field exists in the config file %s' %
                           (str(ConfigField.REQUESTS), self.file_path))
     for req in self.__config_json_obj[ConfigField.REQUESTS.value]:
         feed_obj = None
         feed_field = req.get(ConfigField.FEED_REQUEST.value)
         if feed_field:
             feed_obj = Feed(
                 feed_field.get(FeedField.TYPE.value),
                 feed_field.get(FeedField.SCOPE.value),
                 feed_field.get(FeedField.CATEGORY_ID.value),
                 feed_field.get(FeedField.MARKETPLACE_ID.value), token,
                 feed_field.get(FeedField.DATE.value),
                 feed_field.get(FeedField.ENVIRONMENT.value),
                 feed_field.get(FeedField.DOWNLOAD_LOCATION.value),
                 feed_field.get(FeedField.FILE_FORMAT.value))
         filter_request_obj = None
         filter_field = req.get(ConfigField.FILTER_REQUEST.value)
         if filter_field:
             filter_request_obj = FeedFilterRequest(
                 str(filter_field.get(FilterField.INPUT_FILE_PATH.value)),
                 filter_field.get(FilterField.ITEM_IDS.value),
                 filter_field.get(FilterField.LEAF_CATEGORY_IDS.value),
                 filter_field.get(FilterField.SELLER_NAMES.value),
                 filter_field.get(FilterField.GTINS.value),
                 filter_field.get(FilterField.EPIDS.value),
                 filter_field.get(FilterField.PRICE_LOWER_LIMIT.value),
                 filter_field.get(FilterField.PRICE_UPPER_LIMIT.value),
                 filter_field.get(
                     FilterField.ITEM_LOCATION_COUNTRIES.value),
                 filter_field.get(FilterField.INFERRED_EPIDS.value),
                 filter_field.get(FilterField.ANY_QUERY.value),
                 filter_field.get(FilterField.FILE_FORMAT.value))
         config_request_obj = ConfigRequest(feed_obj, filter_request_obj)
         self.requests.append(config_request_obj)
コード例 #6
0
start = time.time()
if args.filteronly:
    # create the filtered file
    feed_filter_obj = FeedFilterRequest(args.downloadlocation, args.itemf,
                                        args.lf, args.sellerf, args.gtinf,
                                        args.epidf, args.pricelf, args.priceuf,
                                        args.locf, args.iepidf, args.qf,
                                        args.format)
    filter_response = feed_filter_obj.filter()
    if filter_response.status_code != SUCCESS_CODE:
        print(filter_response.message)

else:
    # download the feed file if --filteronly option is not set
    feed_obj = Feed(FeedType.ITEM.value, args.scope, args.c1, args.mkt,
                    args.token, args.dt, args.env, args.downloadlocation,
                    args.format)
    get_response = feed_obj.get()
    if get_response.status_code != SUCCESS_CODE:
        logger.error(
            'Exception in downloading feed. Cannot proceed\nFile path: %s\n Error message: %s\n',
            get_response.file_path, get_response.message)
    else:
        # create the filtered file
        feed_filter_obj = FeedFilterRequest(get_response.file_path, args.itemf,
                                            args.lf, args.sellerf, args.gtinf,
                                            args.epidf, args.pricelf,
                                            args.priceuf, args.locf,
                                            args.iepidf, args.qf, args.format)
        filter_response = feed_filter_obj.filter()
        if filter_response.status_code != SUCCESS_CODE:
コード例 #7
0
 def test_none_token(self):
     feed_req_obj = Feed(FeedType.ITEM.value, FeedScope.BOOTSTRAP.value, '220', 'EBAY_US', None)
     get_response = feed_req_obj.get()
     self.assertEquals(get_response.status_code, FAILURE_CODE)
     self.assertIsNotNone(get_response.message)
     self.assertIsNone(get_response.file_path, 'file_path is not None in the response')
コード例 #8
0
from feed.feed_request import Feed

feed_obj = Feed(feed_type='item',
                feed_scope='ALL_ACTIVE',
                category_id='6000',
                marketplace_id='EBAY_US',
                token='none',
                environment='PRODUCTION')
feed_obj.get()