def test_fetch_single(self): obj = DB() row = {'name': 'Ram', 'occupation': "python programming"} row_id = obj.insert_row(row) fr = obj.fetch_single(row_id) for key, value in fr.items(): self.assertEqual(value, row[key])
def test_delete_row(self): obj = DB() row = {'name': 'Ram', 'occupation': "python programming"} row_id = obj.insert_row(row) self.assertEqual(len(obj.data), 1) obj.delete_row(row_id) self.assertEqual(len(obj.data), 0)
def test_update_row(self): obj = DB() row = {'name': 'Ram', 'occupation': "python programming"} row_id = obj.insert_row(row) new_row = {'name': 'Ram', 'occupation': 'web development'} obj.update_row(row_id, new_row) d = obj.data[row_id] for key, value in d.items(): self.assertEqual(new_row[key], value)
def test_insert_row(self): obj = DB() row = {'name': 'Ram', 'occupation': "python programming"} self.assertEqual(len(obj.data), 0) row_id = obj.insert_row(row) self.assertEqual(len(obj.data), 1) d = obj.data[row_id] for key, value in d.items(): self.assertEqual(row[key], value)
def test_fetch_all(self): obj = DB() row = {'name': 'Ram', 'occupation': 'python'} row2 = {'name': 'Ramin djawadi', 'occupation': 'composer'} r1 = obj.insert_row(row) r2 = obj.insert_row(row2) rows = obj.fetch_all() self.assertEqual(len(rows), 2) for i in (r1, r2): self.assertIn(i, rows)
def import_from_file(self, input_file): quotes = json.load(input_file) db_path = self.get_config('DB_PATH') db_obj = DB(db_path) for quote in quotes: db_obj.insert_row(quote) db_obj.commit() db_obj.close() print("Imported from the given file")
def setUp(self): q = {'quote': 'Hello', 'author': 'Ram'} qo = Quote(**q) db = DB() db.insert_row(qo.__record__()) q = {'quote': 'Hi', 'author': 'Hari'} qo = Quote(**q) db.insert_row(qo.__record__()) q = {'quote': 'Hello', 'author': 'Ram'} qo = Quote(**q) q = {'quote': 'Dai', 'author': 'Deva'} qo = Quote(**q) db.insert_row(qo.__record__()) q = {'quote': 'Velakenna', 'author': 'Appa'} qo = Quote(**q) db.insert_row(qo.__record__()) self.db = db self.db.commit()
def test_commit(self): obj = DB() row = {'name': 'Ram', 'occupation': 'web development'} row_id = obj.insert_row(row) obj.commit() obj2 = DB() self.assertEqual(len(obj2.data), 1)
def add_quote(self): qargs = {} qargs['quote'] = get_multiline("Enter the quote:") qargs['author'] = input("Author:") qargs['source'] = input("Source(''): ") qargs = { key: value.strip() for key, value in qargs.items() if value.strip() } qobj = Quote(**qargs) db_path = self.get_config('DB_PATH') db_obj = DB(db_path) qobj.save_to_db(db_obj)
def export(self, output_file): db_path = self.get_config("DB_PATH") db_obj = DB(db_path) quotes = export_all_quotes(db_obj) json.dump(quotes, output_file, indent=4)
def test_init(self): obj = DB() self.assertEqual(len(obj.data), 0)