def test_Processor_run_processor(test_case, gen_engine): insert_products(test_case['products'], gen_engine) product_db = Product_db(gen_engine) Processor.run_processor( test_case['msg'], 1, True ) products = product_db.get_products_for_status('PROCESSED') assert len(list(products)) == len(test_case['products'])
def test_export_data_to_csv(test_case, gen_engine): insert_products(test_case['products'], gen_engine) product_db = Product_db(gen_engine) products = product_db.get_products_for_status('PROCESSED') Indexer._test = True Indexer.export_data_to_csv('test.csv', products) with open('test.csv', 'r') as csvfile: result = csvfile.read() assert result == test_case['expected'][0] os.remove('test.csv')
def test_Processor_parser_and_update(test_case, gen_engine): insert_products(test_case['products'], gen_engine) arg = (test_case['products'][0]['id'], test_case['products'][0]['url']) Processor._test = True Processor.parser_and_update(arg) db_session = Session(bind=gen_engine) product = db_session.query(Product).get(test_case['products'][0]['id']) expected_product = { 'title': product.title, 'name': product.name, 'status': product.status.code } assert expected_product == test_case['expected']
def test_update_product(test_case, gen_engine): insert_products(test_case['products'], gen_engine) product_db = Product_db(gen_engine) product_db.update_product(**test_case['params']) db_session = Session(bind=gen_engine) product = db_session.query(Product).get(test_case['params']['key']) expected_product = { 'key': product.id, 'title': product.title, 'name': product.name, 'status': product.status.code } assert expected_product == test_case['params']
def test_Enqueuer_run_enqueuer(test_case, gen_engine): insert_products(test_case['products'], gen_engine) parser = argparse.ArgumentParser(prefix_chars='-+') parser.add_argument('+links_per_msg', type=int) parser.add_argument('++queue') parser.add_argument('+++test', type=bool) l = str(test_case['links_per_msg']) queue = test_case['queue_name'] args = parser.parse_args( ("+links_per_msg "+l+" ++queue "+queue+" +++test true").split() ) Enqueuer.run_enqueuer(args) conn = connection_queue(test_case['queue_name']) channel = conn.channel() channel = channel.queue_declare(queue=test_case['queue_name']) q_len = channel.method.message_count assert q_len == test_case['expected_msgs'] close_conn_queue(conn, queue=test_case['queue_name'])
def test_Processor_run_processor(test_case, gen_engine): insert_products(test_case['products'], gen_engine) product_db = Product_db(gen_engine) Processor.run_processor(test_case['msg'], 1, True) products = product_db.get_products_for_status('PROCESSED') assert len(list(products)) == len(test_case['products'])
def test_update_status_product(test_case, gen_engine): insert_products(test_case['products'], gen_engine) product_db = Product_db(gen_engine) product_db.update_status_products(test_case['keys'], test_case['status']) products = product_db.get_products_for_status(test_case['status']) assert len(list(products)) == test_case['expected_update']
def test_calculate_messages(test_case, gen_engine): insert_products(test_case['products'], gen_engine) product_db = Product_db(gen_engine) msgs = calculate_messages(product_db, test_case['links_per_msg']) assert len(msgs) == test_case['expected_msgs']