def test_remove_account_NoExistAccount(self): temp_db_path_correct = "C:/Users/Admin/PycharmProjects/ta_app/DB_Files/accounts.csv" account2 = Account() account2.user = "******" account2.password = "******" account2.role = "TA" self.db_connection = DBConnection() self.assertTrue(self.db_connection.connect(temp_db_path_correct)) self.assertTrue(self.db_connection.is_connected) self.assertEqual(temp_db_path_correct, self.db_connection.db_path) self.assertTrue(self.db_connection.add_account(self.account_correct)) self.assertFalse(self.db_connection.remove_account(account2))
def setUp(self): self.super = Superuser() self.user = Account() self.ui = UI() self.user.set_user = "******" self.user.set_password = "******" self.user.set_role = "default_superuser"
def create_account(self, psuser="", pspassword="", psrole=""): if self.get_current_user() != 'default_superuser': return 'Failed to create account. Insufficient permissions' if psuser == "" or pspassword == "" or psrole == "": return 'Failed to create account. Invalid or missing argument' new_account = Account(psuser, pspassword, psrole) self.accountsDB.add_account(new_account) return 'Successfully created account'
def delete_account(self, psuser="", pspassword="", psrole=""): if self.get_current_user() != 'default_superuser': return 'Failed to delete account. Insufficient permissions' if psuser == '': return 'Failed to delete account. Invalid or missing argument' ac = Account(psuser, pspassword, psrole) result = self.accountsDB.remove_account(ac) if not result: return "Failed to delete account. User not found" return "Successfully deleted account"
def add_account(self, entry: Account) -> bool: """ :param entry: a data validated Account object that will entered into the DB :return: a boolean if the process was successful """ self.__dbObject = open(self.db_path, "a+") if self.db_object is None or entry is None or not self.__isConnected: return False self.db_object.write(entry.__str__() + "\n") self.__dbObject.close() return True
def setUp(self): self.account_correct = Account() self.account_correct.user = "******" self.account_correct.password = "******" self.account_correct.role = "TA" self.course_correct = Course() self.course_correct.name = "CS103" self.course_correct.section = "222" self.course_correct.days_of_week = ["M", "W", "F"] self.course_correct.start_time = "12:00" self.course_correct.end_time = "13:00" self.course_correct.lab_sections = "210"
def test_account8(self): ac = Account("user", "password", "Supervisor") ac.street_address = "street address" ac.email_address = "email address" ac.phone_number = "phone number" test7str = ac.__str__() self.assertEqual( test7str, "user, password, Supervisor, street address, email address, phone number" )
def remove_account(self, entry: Account) -> bool: """ :param entry: a data validated Account object to be deleted from the DB :return: """ if not self.__isConnected: return False self.__dbObject = open(self.db_path, "r") search_entry = entry.__str__() + "\n" account_list = self.db_object.readlines() if entry is None or search_entry not in account_list: return False self.db_object.close() # The file has to be reopened in the same method to perform the write operations self.__dbObject = open(self.db_path, "a") # this truncate operation empties a file, # I can't do a line specific remove/insert self.db_object.truncate(0) for account in account_list: if account != search_entry: self.db_object.write(account.__str__() + "\n") self.db_object.close() return True
def test_account1(self): ac = Account("test1User", "test1Password", "Supervisor") self.assertEqual(ac.user, "test1User")
def test_account7(self): ac = Account("test7User", "test7Password", "Supervisor") with self.assertRaises(ValueError): ac.role = "cabbage"
def test_account6(self): ac = Account("test6User", "test6Password", "Supervisor") with self.assertRaises(ValueError): ac.role = ""
def test_account5(self): ac = Account("test5User", "test5Password", "Supervisor") with self.assertRaises(ValueError): ac.password = ""
def test_account4(self): ac = Account("test4User", "test4Password", "Supervisor") with self.assertRaises(ValueError): ac.user = ""
def test_account3(self): ac = Account("test3User", "test3Password", "Supervisor") self.assertEqual(ac.role, "Supervisor")
def test_account2(self): ac = Account("test2User", "test2Password", "Supervisor") self.assertEqual(ac.password, "test2Password")