Ejemplo n.º 1
0
 def test_no_query(self):
     filter_request = FeedFilterRequest(self.test_file_path)
     filter_response = filter_request.filter()
     self.assertEqual(filter_response.status_code, FAILURE_CODE)
     self.assertIsNotNone(filter_response.message)
     self.assertIsNone(filter_response.file_path)
     self.assertEqual(len(filter_response.applied_filters), 0)
Ejemplo n.º 2
0
 def test_dir_file_path(self):
     filter_request = FeedFilterRequest('../tests/test-data')
     filter_response = filter_request.filter()
     self.assertEqual(filter_response.status_code, FAILURE_CODE)
     self.assertIsNotNone(filter_response.message)
     self.assertIsNone(filter_response.file_path)
     self.assertEqual(len(filter_response.applied_filters), 0)
Ejemplo n.º 3
0
    def __test_apply_filters(self):
        filter_request = FeedFilterRequest(self.test_file_path,
                                           price_upper_limit=10,
                                           any_query=self.test_any_query)
        filter_response = filter_request.filter(keep_db=False)
        self.assertEqual(filter_response.status_code, SUCCESS_CODE)
        self.assertIsNotNone(filter_response.message)

        self.assertEqual(len(filter_request.queries), 2)
        self.assertEqual(len(filter_response.applied_filters), 2)

        self.assertTrue(filter_request.number_of_records > 0)
        self.assertTrue(filter_request.number_of_filtered_records > 0)

        self.assertIsNotNone(filter_request.filtered_file_path)
        self.assertTrue(isfile(filter_request.filtered_file_path))
        self.assertEqual(filter_request.filtered_file_path,
                         filter_response.file_path)
        # clean up
        remove(filter_request.filtered_file_path)
Ejemplo n.º 4
0
    help=
    'any other query to filter the feed file. See Python dataframe query format'
)

# parse the arguments
args = parser.parse_args()

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