예제 #1
0
def test_check_username(test_username, test_password, test_firstname,
                        test_gender):
    output = check_username(test_username)
    assert isinstance(output, tuple), "check_username must return " \
                                      "a tuple"
    assert len(output) == 2, "check_username must return flag " \
                             "and message as a tuple"
    valid, msg = output
    assert valid is True, f"'{empty_password}' is correct, " \
                          f"but check_username says it isn't"
    assert isinstance(msg, str), "check_username must return " \
                                 "a string as a message"

    create_new_user(test_username, test_password, test_firstname, test_gender,
                    "test_db")

    output = check_username(test_username, "test_db")
    assert isinstance(output, tuple), "check_username must return a tuple"
    assert len(output) == 2, "check_username must return flag and " \
                             "message as a tuple"
    valid, msg = output
    assert valid is False, f"'{empty_password}' already exists, " \
                           f"but check_username says it is correct"
    assert isinstance(msg, str), "check_username must return " \
                                 "a string as a message"
    delete_user(test_username, "test_db")
예제 #2
0
def test_create_new_user(test_username, test_password, test_firstname,
                         test_gender):
    create_new_user(test_username, test_password, test_firstname, test_gender,
                    "test_db")
    db_path = DB_FOLDER / "test_db"
    with open(db_path, "r") as f:
        username2info = json.load(f)
    assert test_username in username2info, f"'{test_username}' was not created"
    u = username2info[test_username]
    assert u["password"] == test_password, "password was saved incorrectly"
    assert u["firstname"] == test_firstname, "firstname was saved incorrectly"
    assert u["gender"] == test_gender, "gender was saved incorrectly"
    delete_user(test_username, "test_db")
예제 #3
0
def test_delete_user(test_username, test_password, test_firstname,
                     test_gender):
    test_username1 = test_username + "q"
    create_new_user(test_username, test_password, test_firstname, test_gender,
                    "test_db")
    create_new_user(test_username1, test_password, test_firstname, test_gender,
                    "test_db")

    delete_user(test_username, "test_db")
    db_path = DB_FOLDER / "test_db"
    with open(db_path, "r") as f:
        username2info = json.load(f)
    assert test_username not in username2info, f"'{test_username}' was not " \
                                               f"deleted from db"

    delete_user(test_username1, "test_db")
    assert not db_path.exists(), f"'{test_username1}' was not deleted from db"
예제 #4
0
    def handle_signup(self):
        username = self.line_edit_username.text()
        password = self.line_edit_password.text()
        firstname = self.line_edit_firstname.text()
        gender = self.gender
        create_user_flag = True

        messages = []
        valid_password, msg_password = check_password(password)
        if not valid_password:
            create_user_flag = False
            messages.append(_("Password:"******"Username:"******"Firstname:"))
            messages.append(self.transform_message(msg_firstname))

        if gender is None:
            create_user_flag = False
            messages.append(_("Gender:"))
            messages.append(
                self.transform_message(_("Please choose your gender")))

        if create_user_flag:
            create_new_user(username=username,
                            password=password,
                            firstname=firstname,
                            gender=gender)
            self.show_login_window.emit(self)
        else:
            msg_box = QMessageBox()
            msg_box.setText("\n".join(messages))
            msg_box.exec_()
예제 #5
0
def test_match_username_password(test_username, test_password, test_firstname,
                                 test_gender):
    create_new_user(test_username, test_password, test_firstname, test_gender,
                    "test_db")
    assert match_username_password(test_username, test_password, "test_db")
    delete_user(test_username, "test_db")
예제 #6
0
def test_user_exists(test_username, test_password, test_firstname,
                     test_gender):
    create_new_user(test_username, test_password, test_firstname, test_gender,
                    "test_db")
    assert user_exists(test_username, "test_db")
    delete_user(test_username, "test_db")