def test_import_csv(self): """ Testing import_csv """ self.add_note("test") self.add_note("test2") self.assertEqual(notes.import_csv(["test", ], "couocu", -2.5), 1) self.assertEqual(notes.get(lambda x: x['nickname'] == "test")[0]['note'], -2.5) self.assertEqual(notes.get(lambda x: x['nickname'] == "test2")[0]['note'], 0)
def test_get_notes_in_note_category(self): note_categories.add("test") note_categories.add("test2") note_categories.add_notes(["test1", "test2"], "test") note_categories.add_notes(["test1"], "test2") self.assertEqual(list(note_categories.get_notes("test")), ["test1", "test2"]) self.assertEqual(list(notes.get(lambda x: x['nickname'] == "test1"))[0]['categories'], ["test", "test2"]) self.assertEqual(list(notes.get(lambda x: x['nickname'] == "test2"))[0]['categories'], ["test"])
def test_change_ecocups(self): """ Testing change_ecocups """ self.add_note("test0") notes.change_ecocups("test0", 5) note = notes.get()[0] self.assertEqual(note['ecocups'], 5) notes.change_ecocups("test0", -3) note = notes.get()[0] self.assertEqual(note['ecocups'], 2)
def test_get_notes_in_note_category(self): note_categories.add("test") note_categories.add("test2") note_categories.add_notes(["test1", "test2"], "test") note_categories.add_notes(["test1"], "test2") self.assertEqual(list(note_categories.get_notes("test")), ["test1", "test2"]) self.assertEqual( list(notes.get(lambda x: x['nickname'] == "test1"))[0] ['categories'], ["test", "test2"]) self.assertEqual( list(notes.get(lambda x: x['nickname'] == "test2"))[0] ['categories'], ["test"])
def test_change_photo(self): """ Testing change_photo """ self.add_note("test0") notes.change_photo("test0", "../tests/resources/coucou2.jpg") note = notes.get()[0] self.assertEqual(note['photo_path'], "coucou2.jpg") notes.change_photo("test0", "../tests/resources/coucou.jpg") note = notes.get()[0] self.assertEqual(note['photo_path'], "coucou.jpg") notes.change_photo("test0", "../tests/resources/coucou2.jpg") note = notes.get()[0] self.assertIn("coucou2", note['photo_path']) self.assertNotEqual("coucou2.jpg", note['photo_path'])
def test_overdraft(self): """ Testing overdraft support """ self.add_note("test0") note = notes.get()[0] self.assertEqual(note['overdraft_date'], None) self.add_transaction(["test0", ], -1) note = notes.get()[0] now = PyQt5.QtCore.QDateTime.currentDateTime() self.assertEqual(note['overdraft_date'], now.date()) self.add_transaction(["test0", ], 1) note = notes.get()[0] self.assertEqual(note['overdraft_date'], None)
def test_get_by_id(self): """ Testing get_by_id """ id_ = notes.add("test1", "test", "test", "*****@*****.**", "0600000000", '12/12/2001', '1A', '../tests/resources/coucou.jpg', True, False ) getted = notes.get(lambda x: x['id'] == id_)[0] self.assertEqual(getted, {'id': id_, 'nickname': 'test1', 'lastname': 'test', 'firstname': 'test', 'mail': '*****@*****.**', 'tel': '0600000000', 'birthdate': 1008111600, 'promo': '1A', 'note': 0.0, 'overdraft_date': None, 'ecocups': 0, 'photo_path': 'coucou.jpg', 'tot_cons': 0.0, 'tot_refill': 0.0, 'mails_inscription': False, 'stats_inscription': True, 'agios_inscription': True, 'hidden': False, 'categories': []}) self.assertTrue(os.path.isfile("img/coucou.jpg"))
def test_notes_stats(self): """ Testing notes stats """ id0 = self.add_note("test") self.add_transaction(['test'], 10) self.add_transaction(['test'], -9) api.notes.rebuild_cache() self.assertEqual(notes.get(lambda x: x["id"] == id0), [{'id': id0, 'nickname': 'test', 'lastname': 'test', 'firstname': 'test', 'mail': '*****@*****.**', 'tel': '0600000000', 'birthdate': 1008111600, 'promo': '1A', 'note': 1.0, 'tot_cons': -9.0, 'tot_refill': 10.0, 'overdraft_date': None, 'ecocups': 0, 'photo_path': '', 'mails_inscription': True, 'stats_inscription': True, 'agios_inscription': True, 'hidden': False, 'categories': []}])
def test_export_by_id(self): notes.add("test0", "test", "test", "*****@*****.**", "0600000000", '12/12/2001', '1A', '', True, True ) notes.add("test1", "test", "test", "*****@*****.**", "0600000000", '12/12/2001', '1A', '', True, True ) to_export = ["nickname", "firstname", "lastname", "note", "mail", "photo_path"] note = notes.get(lambda x: x['nickname'] == "test0")[0] csv = ", ".join(to_export) csv += "\n" + ",".join(str(note[value]) for value in to_export) self.assertEqual(csv, notes.export_by_nick(list(["test0"])))
def test_get_by_name(self): """ Testing get_by_name """ notes.add("test0", "test0", "test0", "*****@*****.**", "0600000000", '12/12/2001', '1A', '', True, True ) notes.add("test1", "test1", "test1", "*****@*****.**", "0600000000", '12/12/2001', '1A', '', True, True ) notes.add("pouette", "test", "test", "*****@*****.**", "0600000000", '12/12/2001', '1A', '', True, True ) res = notes.get(lambda x: 'test' in x["nickname"]) for i in range(2): self.assertIn({'id': i + 1, 'nickname': 'test' + str(i), 'lastname': 'test' + str(i), 'firstname': 'test' + str(i), 'mail': '*****@*****.**', 'tel': '0600000000', 'birthdate': 1008111600, 'promo': '1A', 'note': 0.0, 'overdraft_date': None, 'ecocups': 0, 'photo_path': '', 'tot_cons': 0.0, 'tot_refill': 0.0, 'mails_inscription': True, 'stats_inscription': True, 'agios_inscription': True, 'hidden': False, 'categories': []}, res)
def test_note_categories_in_notes(self): self.add_note("test") note_categories.add("cat1") note_categories.add("cat2") note_categories.add("cat3") note_categories.add_notes(["test"], "cat1") note_categories.add_notes(["test"], "cat2") notes.rebuild_cache() note = notes.get()[0] self.assertEqual(note['categories'], ["cat1", "cat2"])
def test_modif_note(self): """ Testing modifying a note. """ notes.add("test0", "test", "test", "*****@*****.**", "0600000000", "01/01/1994", '1A', '', True, True ) notes.add("crash", "crash", "crash", "*****@*****.**", "0600000000", "01/01/1994", '1A', '', True, True ) notes.change_values("test0", tel="0200000000", promo="3A") note = notes.get()[0] self.assertEqual(note["tel"], "0200000000") self.assertEqual(note["promo"], "3A") notes.change_values("test0", nickname="test1") notes.NOTES_FIELDS_CACHE = {} notes.rebuild_cache() note = notes.get(lambda x: x['nickname'] == "test1")[0] self.assertEqual(note["nickname"], "test1") self.assertEqual(note["tel"], "0200000000") self.assertEqual(note["promo"], "3A") self.assertFalse(notes.change_values("test1", nickname="crash")) note = notes.get(lambda x: x['nickname'] == "test1")[0] self.assertIsNotNone(note)
def test_export_csv(self): """ Testing csv export """ notes.add("test1", "test", "test", "*****@*****.**", "0600000000", '12/12/2001', '1A', '', True, True ) to_export = ["nickname", "firstname", "lastname", "note", "mail", "photo_path"] note = notes.get()[0] csv = ", ".join(to_export) csv += "\n" + ",".join(str(note[value]) for value in to_export) self.assertEqual(csv, notes.export(notes.get()))
def test_get_by_majors(self): """ Testing get majors """ id0 = notes.add("test0", "test0", "test0", "*****@*****.**", "0600000000", "24/12/1995", '1A', '', True, True ) notes.add("test1", "test1", "test1", "*****@*****.**", "0600000000", "24/12/1997", '1A', '', True, True ) self.assertEqual(notes.get(lambda x: x["birthdate"] < 851403600), [{'id': id0, 'nickname': 'test0', 'lastname': 'test0', 'firstname': 'test0', 'mail': '*****@*****.**', 'tel': '0600000000', 'birthdate': 819759600, 'promo': '1A', 'note': 0.0, 'tot_cons': 0.0, 'tot_refill': 0.0, 'overdraft_date': None, 'ecocups': 0, 'photo_path': '', 'mails_inscription': True, 'stats_inscription': True, 'agios_inscription': True, 'hidden': False, 'categories': []}])