def test_add_memo(): records = get_memos() n = len(records) add_new_memo("dated_memo", "2017-11-08T16:42:28+00:00", "this is another test") records = get_memos() m = len(records) assert n == m - 1
def test_humanize_sort(): collection.remove( {} ) memo1 = "This is memo1" date1 = arrow.utcnow().to('local') isoDate1 = date1.isoformat() record = { "type": "dated_memo", "date": isoDate1, "text": memo1 } collection.insert(record) memo2 = "This is memo2" date2 = date1.replace(days=-1).isoformat() record = { "type": "dated_memo", "date": date2, "text": memo2 } collection.insert(record) memo3 = "This is memo2" date3 = date1.replace(days=1).isoformat() record = { "type": "dated_memo", "date": date3, "text": memo3 } collection.insert(record) memos = get_memos() assert humanize_arrow_date(memos[0]['date']) == "Yesterday" assert humanize_arrow_date(memos[0]['text']) == "This is memo2" #just to show sorting assert humanize_arrow_date(memos[1]['date']) == "Today" assert humanize_arrow_date(memos[2]['date']) == "Tomorrow"
def test_humanize_sort(): collection.remove({}) memo1 = "This is memo1" date1 = arrow.utcnow().to('local') isoDate1 = date1.isoformat() record = {"type": "dated_memo", "date": isoDate1, "text": memo1} collection.insert(record) memo2 = "This is memo2" date2 = date1.replace(days=-1).isoformat() record = {"type": "dated_memo", "date": date2, "text": memo2} collection.insert(record) memo3 = "This is memo2" date3 = date1.replace(days=1).isoformat() record = {"type": "dated_memo", "date": date3, "text": memo3} collection.insert(record) memos = get_memos() assert humanize_arrow_date(memos[0]['date']) == "Yesterday" assert humanize_arrow_date( memos[0]['text']) == "This is memo2" #just to show sorting assert humanize_arrow_date(memos[1]['date']) == "Today" assert humanize_arrow_date(memos[2]['date']) == "Tomorrow"
def test_order_memo(): """ Tests our ordering logic behind our server. """ date1 = '2017-12-25T00:00:00+00:00' text1 = 'Christmas' date2 = '2017-11-23T00:00:00+00:00' text2 = 'Thanksgiving' date3 = '2017-09-22T00:00:00+00:00' text3 = 'School started' data_to_send1 = {'date': date1, 'text': text1} data_to_send2 = {'date': date2, 'text': text2} data_to_send3 = {'date': date3, 'text': text3} database.insert(data_to_send1) database.insert(data_to_send2) database.insert(data_to_send3) records = flask_main.get_memos() # Should be ordered old to new assert records[0]['date'] == '2017-09-22T00:00:00+00:00' assert records[1]['date'] == '2017-11-23T00:00:00+00:00' assert records[2]['date'] == '2017-12-25T00:00:00+00:00' database.remove() database.remove() database.remove()
def test_memo_sort(): records = get_memos() n = len(records) result = True i = 1 for memo in records: if memo['date'] > records[i][ 'date']: #If the memo date at records[i] is later than date @ records[i+1] result = False #Then the list isn't sorted by date i = i + 1 if i == n: break assert result == True
def test_get_memos(): """ Testing memos retrieval """ records = get_memos() assert len(records) > 0 #We inserted in last test so this should not be 0 #veryify the proper form of the dict for entry in records: assert entry['_id'] is not None assert entry['date'] is not None assert entry['text'] is not None
def test_get_memos(): collection.insert(TEST_MEMO.copy()) collection.insert({"type": "dated_memo", "date": TEST_MEMO['date'], "text": "Nosetest2" }) memos = flask_main.get_memos() found_test_1 = False found_test_2 = False for memo in memos: if memo['date'] == arrow.get(TEST_MEMO.copy()['date']).replace(tzinfo=tz.gettz("US/Pacific")).isoformat(): if memo['text'] == "Nosetest": found_test_1 = True elif memo['text'] == "Nosetest2": found_test_2 = True assert found_test_1 and found_test_2
def test_deletion(): memos = get_memos() id = memos[0]['_id'] #remove one entry from the collection remove_memos(id) #get number of entries left assert collection.count() == 2 id = memos[1]['_id'] #remove next remove_memos(id) assert collection.count() == 1 id = memos[2]['_id'] #remove next remove_memos(id) assert collection.count() == 0
def test_ListMemosSorted(): """ Test listing the memos from the database in sorted order by date. """ collection.remove({}) #empty collection out sorted_dates = ["2014-07-08", "2015-05-20", "2015-11-14", "2016-01-02", "2016-01-03", "2016-01-04", "2017-08-13"] sorted_text = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh"] AddNewDatedMemo("01/03/2016", "Fifth", collection) AddNewDatedMemo("11/14/2015", "Third", collection) AddNewDatedMemo("05/20/2015", "Second", collection) AddNewDatedMemo("07/08/2014", "First", collection) AddNewDatedMemo("08/13/2017", "Seventh", collection) AddNewDatedMemo("01/04/2016", "Sixth", collection) AddNewDatedMemo("01/02/2016", "Fourth", collection) records = get_memos(collection) #a list for i in range(0, len(records)): assert records[i]['date'].startswith(sorted_dates[i]) assert records[i]['text'] == sorted_text[i]
# Mongo database from pymongo import MongoClient import CONFIG import sys try: dbclient = MongoClient(CONFIG.MONGO_URL) db = dbclient.memos collection = db.dated except: print("Failure opening database. Is Mongo running? Correct password?") sys.exit(1) """ Check and see if dates are being humanized correctly/also shows sorting since get_memos() sorts date1 Which would be "Today" is pulled out of db in memos[1] position where as date2 which would be "Yesterday" is pulled out of db in memos[0] position Also no need to mess with times since I use date picker user can't select times """ def test_humanize_sort(): collection.remove({}) memo1 = "This is memo1" date1 = arrow.utcnow().to('local') isoDate1 = date1.isoformat() record = {"type": "dated_memo", "date": isoDate1, "text": memo1} collection.insert(record)
# Mongo database from pymongo import MongoClient import CONFIG import sys try: dbclient = MongoClient(CONFIG.MONGO_URL) db = dbclient.memos collection = db.dated except: print("Failure opening database. Is Mongo running? Correct password?") sys.exit(1) """ Check and see if dates are being humanized correctly/also shows sorting since get_memos() sorts date1 Which would be "Today" is pulled out of db in memos[1] position where as date2 which would be "Yesterday" is pulled out of db in memos[0] position Also no need to mess with times since I use date picker user can't select times """ def test_humanize_sort(): collection.remove( {} ) memo1 = "This is memo1" date1 = arrow.utcnow().to('local') isoDate1 = date1.isoformat() record = { "type": "dated_memo", "date": isoDate1, "text": memo1 }
def testListingMemos(self): listed_memos = flask_main.get_memos()