Beispiel #1
0
    def test_get_all_passwords_by_user(self):
        user_id = self.test_user_one.user_id

        for i in range(5):
            password = Password(
                f'user{i}',
                f'password{i}',
                f'site{i}',
                user_id
            )
            self.password_repository.create_password(password)

        user_id = self.test_user_two.user_id

        for i in range(5, 10):
            password = Password(
                f'user{i}',
                f'password{i}',
                f'site{i}',
                user_id
            )
            self.password_repository.create_password(password)

        passwords_by_user_one = self.password_repository.get_all_passwords_by_user(self.test_user_one)

        self.assertEqual(len(passwords_by_user_one), 5)
        self.assertEqual(passwords_by_user_one[1].user_id, self.test_user_one.user_id)
    def tuple_to_password(self, password):
        """Apufunktio, joka muuttaa tuple-syötteen Password-olioksi

        Args:
            password: Tuple, joka sisältää halutun Password-olion kentät
        Returns:
            Password-olio, joka muodostetaan parametristä password
        """
        if not password:
            return None

        password_to_return = Password(password[1], password[2], password[3])
        password_to_return.set_user_id(password[4])

        return password_to_return
Beispiel #3
0
    def setUp(self):
        # Reset tables users, passwords
        self.password_repository = PasswordRepository(test_database_connection())
        self.user_repository = UserRepository(test_database_connection())
        self.password_repository.delete_all_passwords()
        self.user_repository.delete_all()

        self.test_user_one = User('testiuser', 'testiuser666', 1)
        self.test_user_two = User('secondtestuesr', 'testingggggg', 2)
        self.test_user_one = self.user_repository.create_user(self.test_user_one)
        self.test_user_two = self.user_repository.create_user(self.test_user_two)
        
        self.test_password_one = Password('matti', 'teppo', 'www.vauva.fi')
        self.test_password_two = Password('testpassword', 'testpassword2', 'www.coinbase.com')
        self.test_password_one.set_user_id(self.test_user_one.user_id)
        self.test_password_two.set_user_id(self.test_user_one.user_id)
    def test_add_new_password(self):
        user_for_password = self.user_repository.get_single_user(self.test_user_one)
        password_to_add = Password(
            "test_username",
            "test_pw",
            "test_site",
            user_for_password.user_id
        )
        added_password = self.password_service.add_new_password(password_to_add)

        self.assertEqual(added_password.user_id, user_for_password.user_id)
        self.assertEqual(added_password, password_to_add)
    def test_get_passwords_by_user(self):
        user_for_password = self.user_repository.get_single_user(self.test_user_one)

        for i in range(5):
            password_to_add = Password(
                f"test_username{i}",
                f"test_pw{i}",
                f"test_site{i}",
                user_for_password.user_id
            )
            self.password_service.add_new_password(password_to_add)

        passwords_by_user = self.password_service.get_passwords_by_user(user_for_password)

        self.assertEqual(len(passwords_by_user), 5)
        self.assertEqual(passwords_by_user[0].username, "test_username0")
Beispiel #6
0
    def test_get_all_users(self):
        user_id = self.test_user_one.user_id

        for i in range(5):
            password = Password(
                f'user{i}',
                f'password{i}',
                f'site{i}',
                user_id
            )
            self.password_repository.create_password(password)

        passwords = self.password_repository.get_all_passwords()

        self.assertEqual(len(passwords), 5)
        self.assertEqual(passwords[2].username, 'user2')
Beispiel #7
0
    def handle_add_new_password(self, site, username, password):
        """Lisää uuden salasanan järjestelmään

        Args:
            site: String, sivusto johon salasana sekä käyttäjänimi liittyvät
            username: String, käyttäjänimi sivustolle
            password: String, salasana sivustolle
        """
        if not site or not username or not password:
            return messagebox.showerror('Error', 'No empty fields allowed')

        user_id = self.user.user_id
        new_password = Password(username, password, site, user_id)
        result = self._password_service.add_new_password(new_password)

        messagebox.showinfo('Info', 'Password added')

        self.site_entry.delete(0, "end")
        self.username_entry.delete(0, "end")
        self.password_entry.delete(0, "end")

        return result
Beispiel #8
0
class TestPasswordRepository(unittest.TestCase):
    def setUp(self):
        # Reset tables users, passwords
        self.password_repository = PasswordRepository(test_database_connection())
        self.user_repository = UserRepository(test_database_connection())
        self.password_repository.delete_all_passwords()
        self.user_repository.delete_all()

        self.test_user_one = User('testiuser', 'testiuser666', 1)
        self.test_user_two = User('secondtestuesr', 'testingggggg', 2)
        self.test_user_one = self.user_repository.create_user(self.test_user_one)
        self.test_user_two = self.user_repository.create_user(self.test_user_two)
        
        self.test_password_one = Password('matti', 'teppo', 'www.vauva.fi')
        self.test_password_two = Password('testpassword', 'testpassword2', 'www.coinbase.com')
        self.test_password_one.set_user_id(self.test_user_one.user_id)
        self.test_password_two.set_user_id(self.test_user_one.user_id)

    def test_create_password(self):
        self.password_repository.create_password(self.test_password_one)
        passwords = self.password_repository.get_all_passwords()

        self.assertEqual(len(passwords), 1)
        self.assertEqual(passwords[0].username, self.test_password_one.username)

    def test_get_all_users(self):
        user_id = self.test_user_one.user_id

        for i in range(5):
            password = Password(
                f'user{i}',
                f'password{i}',
                f'site{i}',
                user_id
            )
            self.password_repository.create_password(password)

        passwords = self.password_repository.get_all_passwords()

        self.assertEqual(len(passwords), 5)
        self.assertEqual(passwords[2].username, 'user2')

    def test_get_all_passwords_by_user(self):
        user_id = self.test_user_one.user_id

        for i in range(5):
            password = Password(
                f'user{i}',
                f'password{i}',
                f'site{i}',
                user_id
            )
            self.password_repository.create_password(password)

        user_id = self.test_user_two.user_id

        for i in range(5, 10):
            password = Password(
                f'user{i}',
                f'password{i}',
                f'site{i}',
                user_id
            )
            self.password_repository.create_password(password)

        passwords_by_user_one = self.password_repository.get_all_passwords_by_user(self.test_user_one)

        self.assertEqual(len(passwords_by_user_one), 5)
        self.assertEqual(passwords_by_user_one[1].user_id, self.test_user_one.user_id)

    def test_tuple_to_password_returns_none_if_no_password_given(self):
        result = self.password_repository.tuple_to_password(None)

        self.assertIsNone(result)