def test_03_query_corp(self): Browser.dr.get(self.base_url) self.page.search_querydropdownbtn().click() self.page.search_querycropcodeinp().send_keys('001') self.page.search_selectcropstatusinput().click() self.page.crop_status_options()[1].click() self.page.serach_querybtn().click() with DB() as dbcur: sql = "select * from corp where code = '001';" count = dbcur.execute(sql) li_tr = self.page.query_corptr() logger.info(pytest.assume(len(li_tr) == count))
def parse(arg, DEBUG=False): # define DB db = DB(DEBUG) # load revisions from database and store in format # {id1: [revision1, revison2], id2: [rev3] ... } revisions = defaultdict(list, get_revisions(db)) # buffers for accumulating processed data before save insertList = [] updateList = [] # iterating through generator for row in reader(arg): uid = row['uid'] # creating hash from processed record # duplicates will have same hash, so we can ignore them row_hash = hash_from_dict(row) # check if hash in revisions if uid in revisions and row_hash in revisions[uid]: continue # write hash to our record, so we will able to extract in during next parse row['revisions'] = [row_hash] if uid in revisions: updateList.append(row) else: insertList.append(row) # add hash to revision, so we can omit following duplicates of current parse revisions[uid].append(row_hash) # save data to DB when localstorage reaches chunk size if CHANK_SIZE in [len(insertList), len(updateList)]: save(db, insertList, updateList) insertList.clear() updateList.clear() # saving the rest of the data (if any) to DB save(db, insertList, updateList)
result = db.products.update_one({'uid': item['uid']}, query) def get_revisions(db): products = db.products if products.count() > 0: return dict([(i['uid'], i['revisions']) for i in \ products.find({}, {'uid': 1, 'revisions': 1, '_id': 0})]) else: return {} def drop_table(db): db.products.drop() def create_index(db): db.products.create_index([('uid', ASCENDING)], unique=True) # You can use this script for clearing DB and creating indexes # python db.py 1 - testing DataBase # python db.py 0 - production DataBase if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("debug") args = parser.parse_args() arg = False if args.debug in ['0', 0, 'False', 'false', ''] else True drop_table(DB(arg)) create_index(DB(arg))