def load(self, file_name): maillist_name = file_name.replace("_", " ") # create a Dummy mail list, so we can call the methods if self.mail_list is None: self.mail_list = MailList(-1, maillist_name) file = open(self.get_file_path(), "r") contents = file.read() file.close() lines = contents.split("\n") maillist_id = int(lines[0]) lines.pop(0) result = MailList(maillist_id, maillist_name) if lines == [""]: return result for unparsed_subscriber in lines: subscriber = unparsed_subscriber.split(" - ") result.add_subscriber(subscriber[0], subscriber[1]) return result
def load(self, file_name): maillist_name = file_name.replace("_", " ") # create a Dummy mail list, so we can call the methods if self.mail_list is None: self.mail_list = MailList(-1, maillist_name) cursor.execute('''CREATE TABLE IF NOT EXISTS maillist (list_id int, list_name text''') cursor.execute('''CREATE TABLE IF NOT EXISTS subscribers (sub_id int, name text, email text)''') cursor.execute('''CREATE TABLE IF NOT EXISTS m_to_s (list_id int, list_name text''') file = open(self.get_file_path(), "r") contents = file.read() file.close() lines = contents.split("\n") maillist_id = int(lines[0]) lines.pop(0) result = MailList(maillist_id, maillist_name) for unparsed_subscriber in lines: subscriber = unparsed_subscriber.split(" - ") if len(subscriber) >= 2: result.add_subscriber(subscriber[0], subscriber[1]) return result
def create_list_callback(self, arguments): name = " ".join(arguments) maillist = MailList(-1, name) maillist_adapter = MailListFileAdapter(self.db_path, maillist) maillist_adapter.save() self.lists[maillist.get_id()] = (maillist, maillist_adapter)
def test_get_id_after_three_instances(self): m1 = MailList(1, "Hack") m2 = MailList(2, "Hack") m3 = MailList(3, "Hack") self.assertEqual(1, m1.get_id()) self.assertEqual(2, m2.get_id()) self.assertEqual(3, m3.get_id())
def load(self, file_name): maillist_name = file_name.replace("_", " ") # create a Dummy mail list, so we can call the methods if self.mail_list is None: self.mail_list = MailList(-1, maillist_name) file = open(self.get_file_path(), "r") contents = file.read() file.close() lines = contents.split("\n") maillist_id = int(lines[0]) lines.pop(0) result = MailList(maillist_id, maillist_name) for unparsed_subscriber in lines: subscriber = unparsed_subscriber.split(" - ") result.add_subscriber(subscriber[0], subscriber[1]) return result
def setUp(self): # f**k static self.m = MailList(1, "Hack Bulgaria")
class MailListTest(unittest.TestCase): """docstring for MailListTest""" def setUp(self): # f**k static self.m = MailList(1, "Hack Bulgaria") def test_create_mail_list_get_name(self): self.assertEqual("Hack Bulgaria", self.m.get_name()) def test_add_subscriber(self): self.m.add_subscriber("Rado", "*****@*****.**") self.assertEqual(1, self.m.count()) def test_get_subscribers(self): self.m.add_subscriber("Rado", "*****@*****.**") expected = [("Rado", "*****@*****.**")] self.assertEqual(expected, self.m.get_subscribers()) def test_get_id(self): self.assertEqual(1, self.m.get_id()) def test_get_id_after_three_instances(self): m1 = MailList(1, "Hack") m2 = MailList(2, "Hack") m3 = MailList(3, "Hack") self.assertEqual(1, m1.get_id()) self.assertEqual(2, m2.get_id()) self.assertEqual(3, m3.get_id()) def test_add_subscriber_with_same_email_address(self): subscriber_email = "*****@*****.**" add1 = self.m.add_subscriber("Rado", subscriber_email) add2 = self.m.add_subscriber("Rado Rado", subscriber_email) self.assertEqual(1, self.m.count()) self.assertTrue(add1) self.assertFalse(add2) self.assertEqual(("Rado", subscriber_email), self.m.get_subscriber_by_email(subscriber_email)) def test_add_get_subscriber_by_email(self): self.m.add_subscriber("Rado", "*****@*****.**") result = self.m.get_subscriber_by_email("*****@*****.**") self.assertEqual(("Rado", "*****@*****.**"), result) def test_add_get_subscriber_by_email_when_not_there(self): self.assertIsNone(self.m.get_subscriber_by_email("*****@*****.**")) def test_update_subscriber_changing_name(self): self.m.add_subscriber("Rado rado", "*****@*****.**") self.m.update_subscriber("*****@*****.**", {"name": "Radoslav Georgiev"}) self.assertEqual("Radoslav Georgiev", self.m.get_subscriber_by_email("*****@*****.**")[0]) def test_update_subscriber_changing_email(self): self.m.add_subscriber("Rado rado", "*****@*****.**") self.m.update_subscriber("*****@*****.**", {"email": "*****@*****.**"}) self.assertEqual(("Rado rado", "*****@*****.**"), self.m.get_subscriber_by_email("*****@*****.**")) def test_update_subscriber_changing_name_and_email(self): self.m.add_subscriber("Rado rado", "*****@*****.**") self.m.update_subscriber("*****@*****.**", {"name": "Radoslav Georgiev", "email": "*****@*****.**"}) self.assertEqual(("Radoslav Georgiev", "*****@*****.**"), self.m.get_subscriber_by_email("*****@*****.**")) def test_remove_subscriber(self): self.m.add_subscriber("Rado rado", "*****@*****.**") self.m.remove_subscriber("*****@*****.**") self.assertEqual(0, self.m.count()) def test_remove_subscriber_when_not_there(self): self.assertIsNone(self.m.remove_subscriber("*****@*****.**"))
def setUp(self): self.maillist = MailList(1, 'new list')
class MailListTest(unittest.TestCase): """docstring for MailListTest""" def setUp(self): self.maillist = MailList(1, 'new list') def test_get_name(self): self.assertEqual('new list', self.maillist.get_name()) def test_add_user(self): self.maillist.add_user('Ivan', '*****@*****.**') expected_user = User('Ivan', '*****@*****.**') self.assertEqual(expected_user.take_name(), self.maillist.users[0].take_name()) self.assertEqual(expected_user.take_email(), self.maillist.users[0].take_email()) def test_print_with_something_in_it(self): self.maillist.add_user('Ivan', '*****@*****.**') self.maillist.add_user('Peho', '*****@*****.**') expected = '[1] Ivan - [email protected]\n[2] Peho - [email protected]' self.assertEqual(expected, self.maillist.print_()) def test_search_email_available(self): self.maillist.add_user('Ivan', '*****@*****.**') self.maillist.add_user('Peho', '*****@*****.**') check = '*****@*****.**' self.assertTrue(self.maillist.search_email(check)) def test_serach_email_unavailable(self): self.maillist.add_user('Ivan', '*****@*****.**') self.maillist.add_user('Peho', '*****@*****.**') check = '*****@*****.**' self.assertTrue(not self.maillist.search_email(check)) def test_name_available(self): self.maillist.add_user('Ivan', '*****@*****.**') self.maillist.add_user('Peho', '*****@*****.**') check = 'Peho' self.assertTrue(self.maillist.search_name(check)) def test_name_unavailable(self): self.maillist.add_user('Ivan', '*****@*****.**') self.maillist.add_user('Peho', '*****@*****.**') check = 'Georgi' self.assertFalse(self.maillist.search_name(check))
def goto_maillist(self): return MailList(self.driver)
class MailListTest(unittest.TestCase): """docstring for MailListTest""" def setUp(self): # f**k static self.m = MailList("Hack Bulgaria") def test_create_mail_list_get_name(self): self.assertEqual("Hack Bulgaria", self.m.get_name()) def test_add_subscriber(self): subscriber = Subscriber("Rado", "*****@*****.**") self.m.add_subscriber(subscriber) self.assertEqual(1, self.m.count()) def test_get_subscribers(self): subscriber = Subscriber("Rado", "*****@*****.**") self.m.add_subscriber(subscriber) expected = [("Rado", "*****@*****.**")] self.assertEqual(expected, self.m.get_subscribers()) def test_add_subscriber_with_same_email_address(self): subscriber_email = "*****@*****.**" subscriber_1 = Subscriber("Rado", subscriber_email) subscriber_2 = Subscriber("Rado Rado", subscriber_email) add1 = self.m.add_subscriber(subscriber_1) add2 = self.m.add_subscriber(subscriber_2) self.assertEqual(1, self.m.count()) self.assertTrue(add1) self.assertFalse(add2) subscriber = self.m.get_subscriber_by_email(subscriber_email) self.assertEqual("Rado", subscriber.get_name()) def test_add_get_subscriber_by_email(self): subscriber = Subscriber("Rado", "*****@*****.**") self.m.add_subscriber(subscriber) result = self.m.get_subscriber_by_email("*****@*****.**") self.assertEqual("Rado", result.get_name()) def test_add_get_subscriber_by_email_when_not_there(self): self.assertIsNone(self.m.get_subscriber_by_email("*****@*****.**")) def test_update_subscriber_changing_name(self): subscriber = Subscriber("Rado", "*****@*****.**") self.m.add_subscriber(subscriber) self.m.update_subscriber("*****@*****.**", {"name": "Radoslav Georgiev"}) sub = self.m.get_subscriber_by_email("*****@*****.**") self.assertEqual("Radoslav Georgiev", sub.get_name()) def test_update_subscriber_changing_email(self): subscriber = Subscriber("Rado", "*****@*****.**") self.m.add_subscriber(subscriber) self.m.update_subscriber("*****@*****.**", {"email": "*****@*****.**"}) self.assertEqual("*****@*****.**", self.m.get_subscriber_by_email("*****@*****.**").get_email()) def test_update_subscriber_changing_name_and_email(self): subscriber = Subscriber("Rado rado", "*****@*****.**") self.m.add_subscriber(subscriber) self.m.update_subscriber("*****@*****.**", {"name": "Radoslav Georgiev", "email": "*****@*****.**"}) self.assertEqual("Radoslav Georgiev", self.m.get_subscriber_by_email("*****@*****.**").get_name()) def test_remove_subscriber(self): subscriber = Subscriber("Rado", "*****@*****.**") self.m.add_subscriber(subscriber) self.m.remove_subscriber("*****@*****.**") self.assertEqual(0, self.m.count()) def test_remove_subscriber_when_not_there(self): self.assertIsNone(self.m.remove_subscriber("*****@*****.**"))
def create(self, list_name): m = MailList(self.next_id(), list_name) return m
def setUp(self): self.m = MailList("Hack Bulgaria")