def edit_date_query(new_value, entry_id): """Update a row's date column with a new value. :param new_value: string that is date format :param entry_id: entry's primary key :return: edited entry """ q = Entry.update(date=new_value).where(Entry.id == entry_id).execute() return Entry.select().where(Entry.id == entry_id).get()
def edit_notes_query(new_value, entry_id): """Update a row's ntoes column with a new value. :param new_value: string :param entry_id: entry's primary key :return: edited entry """ q = Entry.update(notes=new_value).where(Entry.id == entry_id).execute() return Entry.select().where(Entry.id == entry_id).get()
def edit_time_query(new_value, entry_id): """Update a row's time_spent column with a new value. :param new_value: int :param entry_id: entry's primary key :return: edited entry """ q = Entry.update(time_spent=new_value).where( Entry.id == entry_id).execute() return Entry.select().where(Entry.id == entry_id).get()
def add_route(): """Add an entry""" Entry.create(user=get_user(), date=get_date(), title=get_title(), time_spent=get_time(), notes=get_notes()) clear_screen() input("The entry has been added!\n") return None
def setUpClass(cls): cls.test_db = SqliteDatabase(":memory:") test_db.bind_ctx(Entry) cls.test_db.connect() test_db.create_tables([Entry], safe=True) Entry.create( user='******', date='12/12/2002', title='Building additional pylons', time_spent=32, notes='' )
def del_entry(user_id): """Delte a row :param user_id: selected entry's primary key :return: None """ q = Entry.get(Entry.id == user_id) q.delete_instance() return None
def time_search(search): """Search the DB for all entries that match time spent. :param search: int containing user's search criteria :return: a list of the found entries """ entries = Entry.select().order_by( Entry.date.desc()).where(Entry.time_spent == (search)) return entries
def user_search(search): """Search the DB for all entries that match user. :param search: a string containing user's search criteria :return: a list of the found entries """ entries = Entry.select().order_by(Entry.date.desc()).where( Entry.user.contains(search)) return entries
def date_search(search): """Search the DB for all entries that match date(s) :param search: a string or list containing user's search criteria :return: a list of the found entries """ entries = [] if type(search) == list: for range_date in search: try: entries.append( Entry.select().where(Entry.date == range_date).get()) except Entry.DoesNotExist: continue return entries else: return Entry.select().where(Entry.date.contains(search))
def keyword_search(search): """Search the DB for all entries that match keyword. :param search: a string containing user's search criteria :return: a list of the found entries """ entries = [] for entry in Entry.select().order_by( Entry.date.desc()).where((Entry.title.contains(search)) | (Entry.notes.contains(search))): entries.append(entry) return entries
def test_edit_value(self, mock_input): result = edit_value(self.entry_id, 'Title', get_title, edit_title_query) compare = Entry.select().where(Entry.title.contains('Rolling in the dough')).get() self.assertEqual(result.id, compare.id)
def test_edit_time(self): result = edit_time_query(35, 1) compare = Entry.select().where(Entry.id == 1).get() self.assertEqual(result.id, compare.id)
def test_edit_notes(self): result = edit_notes_query('Tidying up!', 1) compare = Entry.select().where(Entry.id == 1).get() self.assertEqual(result.id, compare.id)
def test_date_list_search(self): result = date_search(['12/12/2002', '13/12/2002', '14/12/2002']) compare = Entry.select().where(Entry.date.contains('12/12/2002')) self.assertEqual(len(result), len(compare))
def test_edit_date(self): result = edit_date_query('12/10/2003', 1) compare = Entry.select().where(Entry.id == 1).get() self.assertEqual(result.id, compare.id)
def test_user_search(self): result = user_search('Jay') compare = Entry.select().where(Entry.user.contains('Jay')) self.assertEqual(len(result), len(compare))
def test_time_search(self): result = time_search(32) compare = Entry.select().where(Entry.time_spent == 32) self.assertEqual(len(result), len(compare))
def test_keyword_search(self): result = keyword_search('pylons') compare = Entry.select().where(Entry.title.contains('pylons')) self.assertEqual(len(result), len(compare))