Exemplo n.º 1
0
    def test_create_batch_teams(self, teams=10):
        """
        Tests team creation.

        Covers:
            team.create_team
            team.get_team
            team.get_all_teams
        """
        tids = []
        for i in range(teams):
            team = base_team.copy()
            team["team_name"] += str(i)
            tids.append(api.team.create_team(team))

        assert len(set(tids)) == len(tids), "tids are not unique."

        assert len(api.team.get_all_teams()) == len(
            tids), "Not all teams were created."

        for i, tid in enumerate(tids):
            name = base_team['team_name'] + str(i)

            team_from_tid = api.team.get_team(tid=tid)
            team_from_name = api.team.get_team(name=name)

            assert team_from_tid == team_from_name, "Team lookup from tid and name are not the same."
Exemplo n.º 2
0
    def test_get_team_uids(self):
        """
        Tests the code that retrieves the list of uids on a team

        Covers:
            team.create_team
            user.create_simple_user_request
            team.get_team_uids
        """

        team = base_team.copy()
        tid = api.team.create_team(team)

        uids = []
        for i in range(api.config.get_settings()["max_team_size"]):
            test_user = base_user.copy()
            test_user['username'] += str(i)
            uid = api.user.create_simple_user_request(test_user)
            uids.append(uid)

            # join a real team
            api.team.join_team(team["team_name"], team["password"], uid)

        team_uids = api.team.get_team_uids(tid)
        assert len(team_uids) == api.config.get_settings()[
            "max_team_size"], "Team does not have correct number of members"
        assert sorted(uids) == sorted(
            team_uids), "Team does not have the correct members"
Exemplo n.º 3
0
    def test_create_user_request_team_size_validation(self):
        """
        Tests the team size restriction

        Covers:
            team.create_team
            user.create_user_request
        """

        team = base_team.copy()
        tid = api.team.create_team(team)

        uid = None
        for i in range(api.config.get_settings()["max_team_size"]):
            test_user = base_user.copy()
            test_user['username'] += str(i)
            uid = api.user.create_simple_user_request(test_user)
            # join a real team
            api.team.join_team(team["team_name"], team["password"], uid)

        with pytest.raises(InternalException):
            uid_fail = api.user.create_simple_user_request(base_user.copy())
            # join a real team
            api.team.join_team(team["team_name"], team["password"], uid_fail)
            assert False, "Team has too many users"

        api.user.disable_account(uid)

        #Should be able to add another user after disabling one.
        test_user = base_user.copy()
        test_user['username'] += "addition"
        uid = api.user.create_simple_user_request(test_user)
        api.team.join_team(team["team_name"], team["password"], uid)
Exemplo n.º 4
0
    def te_st_create_user_request_team_size_validation(self):
        """
        Tests the team size restriction

        Covers:
            team.create_team
            user.create_user_request
        """

        api.team.create_team(base_team.copy())

        uid = None
        for i in range(api.config.get_settings()["max_team_size"]):
            test_user = base_user.copy()
            test_user['username'] += str(i)
            uid = api.user.create_user_request(test_user)

        with pytest.raises(WebException):
            api.user.create_user_request(base_user.copy())
            assert False, "Team has too many users"

        api.user.disable_account(uid)

        #Should be able to add another user after disabling one.
        test_user = base_user.copy()
        test_user['username'] += "addition"
        api.user.create_user_request(test_user)
Exemplo n.º 5
0
    def test_create_simple_user_request_email_validation(self):
        """
        Tests the email validation during user registration.

        Covers:
            partially: user.create_simple_user_request
        """

        team = base_team.copy()
        api.team.create_team(team)

        invalid_email_user = base_user.copy()
        invalid_email_user["email"] = "not_an_email"

        with pytest.raises(Exception):
            api.user.create_simple_user_request(invalid_email_user)
            assert False, "Was able to register a user with something that doesn't look like an email."

        invalid_email_user["email"] = "[email protected]"

        with pytest.raises(WebException):
            api.user.create_simple_user_request(invalid_email_user)
            assert False, "Was able to register a user with invalid characters"

        valid_email_user = base_user.copy()
        assert api.user.create_simple_user_request(
            valid_email_user), "Was not able to register a valid email."
Exemplo n.º 6
0
    def test_create_batch_users(self):
        """
        Tests user creation.

        Covers:
            user.create_user
            user.get_all_users
            user.get_user
        """

        tid = api.team.create_team(base_team.copy())

        uids = []
        for i in range(api.team.max_team_users):
            name = "fred" + str(i)
            uids.append(
                api.user.create_user(name, name, name, name + "@gmail.com",
                                     name, tid))

        with pytest.raises(InternalException):
            name = "fred" + str(api.team.max_team_users)
            api.user.create_user(name, name, name, name + "@gmail.com", name,
                                 tid)

        for i, uid in enumerate(uids):
            name = "fred" + str(i)

            user_from_uid = api.user.get_user(uid=uid)
            user_from_name = api.user.get_user(name=name)

            assert user_from_uid == user_from_name, "User lookup from uid and name are not the same."
Exemplo n.º 7
0
    def test_create_user_request_email_validation(self):
        """
        Tests the email validation during user registration.

        Covers:
            partially: user.create_user_request
        """

        team = base_team.copy()
        api.team.create_team(team)

        invalid_email_user = base_user.copy()
        invalid_email_user["email"] = "not_an_email"

        with pytest.raises(Exception):
            api.user.create_user_request(invalid_email_user)
            assert False, "Was able to register a user with something that doesn't look like an email."

        invalid_email_user["email"] = "[email protected]"

        with pytest.raises(WebException):
            api.user.create_user_request(invalid_email_user)
            assert False, "Was able to register a user with invalid characters"

        valid_email_user = base_user.copy()
        assert api.user.create_user_request(
            valid_email_user), "Was not able to register a valid email."
Exemplo n.º 8
0
    def test_create_user_request_team_size_validation(self):
        """
        Tests the team size restriction

        Covers:
            team.create_team
            user.create_user_request
        """

        team = base_team.copy()
        tid = api.team.create_team(team)

        uid = None
        for i in range(api.config.get_settings()["max_team_size"]):
            test_user = base_user.copy()
            test_user['username'] += str(i)
            uid = api.user.create_simple_user_request(test_user)
            # join a real team
            api.team.join_team(team["team_name"], team["password"], uid)

        with pytest.raises(InternalException):
            uid_fail = api.user.create_simple_user_request(base_user.copy())
            # join a real team
            api.team.join_team(team["team_name"], team["password"], uid_fail)
            assert False, "Team has too many users"

        api.user.disable_account(uid)

        # Should be able to add another user after disabling one.
        test_user = base_user.copy()
        test_user['username'] += "addition"
        uid = api.user.create_simple_user_request(test_user)
        api.team.join_team(team["team_name"], team["password"], uid)
Exemplo n.º 9
0
    def test_change_password_user(self):
        """
        Tests password change functionality.

        Covers:
            user.update_password
            user.hash_password
        """

        tid = api.team.create_team(base_team.copy())
        uid = api.user.create_user("fred", "fred", "fred", "*****@*****.**",
                                   "HASH", tid)

        old_hash = api.user.get_user(uid=uid)["password_hash"]
        assert old_hash == "HASH", "Was unable to confirm password was stored correctly."

        api.user.update_password_request(
            {
                "new-password": "******",
                "new-password-confirmation": "HACK"
            }, uid)

        new_hash = api.user.get_user(uid=uid)["password_hash"]

        assert bcrypt.hashpw("HACK", new_hash) == new_hash, \
            "Password does not match hashed plaintext after changing it."

        with pytest.raises(WebException):
            api.user.update_password_request(
                {
                    "new-password": "",
                    "new-password-confirmation": ""
                }, uid)
            assert False, "Should not be able to update password to nothing."
Exemplo n.º 10
0
    def test_create_batch_teams(self, teams=10):
        """
        Tests team creation.

        Covers:
            team.create_team
            team.get_team
            team.get_all_teams
        """
        tids = []
        for i in range(teams):
            team = base_team.copy()
            team["team_name"] += str(i)
            tids.append(api.team.create_team(team))

        assert len(set(tids)) == len(tids), "tids are not unique."

        assert len(api.team.get_all_teams()) == len(
            tids), "Not all teams were created."

        for i, tid in enumerate(tids):
            name = base_team['team_name'] + str(i)

            team_from_tid = api.team.get_team(tid=tid)
            team_from_name = api.team.get_team(name=name)

            assert team_from_tid == team_from_name, "Team lookup from tid and name are not the same."
Exemplo n.º 11
0
    def test_change_password_user(self):
        """
        Tests password change functionality.

        Covers:
            user.update_password
            user.hash_password
        """

        tid = api.team.create_team(base_team.copy())
        uid = api.user.create_user("fred", "fred", "fred", "*****@*****.**",
                                   "HASH", tid)

        old_hash = api.user.get_user(uid=uid)["password_hash"]
        assert old_hash == "HASH", "Was unable to confirm password was stored correctly."

        api.user.update_password_request({
            "new-password": "******",
            "new-password-confirmation": "HACK"
        }, uid)

        new_hash = api.user.get_user(uid=uid)["password_hash"]

        assert bcrypt.hashpw(b'HACK', new_hash) == new_hash, \
            "Password does not match hashed plaintext after changing it."

        with pytest.raises(WebException):
            api.user.update_password_request({
                "new-password": "",
                "new-password-confirmation": ""
            }, uid)
            assert False, "Should not be able to update password to nothing."
Exemplo n.º 12
0
    def test_get_team_uids(self):
        """
        Tests the code that retrieves the list of uids on a team

        Covers:
            team.create_team
            user.create_simple_user_request
            team.get_team_uids
        """

        team = base_team.copy()
        tid = api.team.create_team(team)

        uids = []
        for i in range(api.config.get_settings()["max_team_size"]):
            test_user = base_user.copy()
            test_user['username'] += str(i)
            uid = api.user.create_simple_user_request(test_user)
            uids.append(uid)

            # join a real team
            api.team.join_team(team["team_name"], team["password"], uid)

        team_uids = api.team.get_team_uids(tid)
        assert len(team_uids) == api.config.get_settings(
        )["max_team_size"], "Team does not have correct number of members"
        assert sorted(uids) == sorted(
            team_uids), "Team does not have the correct members"
Exemplo n.º 13
0
    def test_create_user_request_team_size_validation(self):
        """
        Tests the team size restriction

        Covers:
            team.create_team
            user.create_user_request
        """

        api.team.create_team(base_team.copy())

        uid = None
        for i in range(api.team.max_team_users):
            test_user = base_user.copy()
            test_user['username'] += str(i)
            uid = api.user.create_user_request(test_user)

        with pytest.raises(WebException):
            api.user.create_user_request(base_user.copy())
            assert False, "Team has too many users"

        api.user.disable_account(uid)

        #Should be able to add another user after disabling one.
        test_user = base_user.copy()
        test_user['username'] += "addition"
        api.user.create_user_request(test_user)
Exemplo n.º 14
0
    def test_create_batch_users(self):
        """
        Tests user creation.

        Covers:
            user.create_user
            user.get_all_users
            user.get_user
        """

        tid = api.team.create_team(base_team.copy())

        uids = []
        for i in range(api.config.get_settings()["max_team_size"]):
            name = "fred" + str(i)
            uids.append(
                api.user.create_user(name, name, name, name + "@gmail.com",
                                     name, tid))

        with pytest.raises(InternalException):
            name = "fred" + str(api.config.get_settings()["max_team_size"])
            api.user.create_user(name, name, name, name + "@gmail.com", name,
                                 tid)

        for i, uid in enumerate(uids):
            name = "fred" + str(i)

            user_from_uid = api.user.get_user(uid=uid)
            user_from_name = api.user.get_user(name=name)

            assert user_from_uid == user_from_name, "User lookup from uid and name are not the same."
Exemplo n.º 15
0
    def test_create_simple_user_request_existing_team(self):
        """
        Tests the registration of users on existing teams.

        Covers:
            partially: user.create_simple_user_request
            team.get_team_uids
            team.create_team
        """

        team = base_team.copy()
        tid = api.team.create_team(team)
        assert tid, "Team was not created."

        # create a new user and join and existing team
        uid = api.user.create_simple_user_request(base_user.copy())
        assert uid == api.user.get_user(
            name=base_user["username"]
        )["uid"], "Good user created unsuccessfully."

        assert api.team.join_team(
            team["team_name"], team["password"],
            uid), "User unable to joining an existing team"

        with pytest.raises(InternalException):
            api.team.join_team(team["team_name"], team["password"], uid)
            assert False, "Was able to register and join the team twice."

        # attempt to join a non existent team
        with pytest.raises(InternalException):
            invalid_team_user = base_user.copy()
            invalid_team_user["username"] = "******"
            invalid_uid = api.user.create_simple_user_request(
                invalid_team_user)
            api.team.join_team("Totally Invalid", team["password"], uid)
            assert False, "Was able to join a team that doesn't exist."

        # attempt to join an existing team with an invalid password
        with pytest.raises(WebException):
            invalid_team_user = base_user.copy()
            invalid_team_user["username"] = "******"
            invalid_uid = api.user.create_simple_user_request(
                invalid_team_user)
            api.team.join_team(team["team_name"], "bad-password", uid)
            assert False, "Was able to join a team with an invalid password."

        team_uids = api.team.get_team_uids(tid)

        assert len(
            team_uids
        ) == 1, "Invalid teams were created though the tests passed."
        assert uid in team_uids, "User was not successfully placed into the existing team."
Exemplo n.º 16
0
    def test_create_simple_user_request_existing_team(self):
        """
        Tests the registration of users on existing teams.

        Covers:
            partially: user.create_simple_user_request
            team.get_team_uids
            team.create_team
        """

        team = base_team.copy()
        tid = api.team.create_team(team)
        assert tid, "Team was not created."

        # create a new user and join and existing team
        uid = api.user.create_simple_user_request(base_user.copy())
        assert uid == api.user.get_user(name=base_user["username"])[
            "uid"], "Good user created unsuccessfully."

        assert api.team.join_team(
            team["team_name"], team["password"],
            uid), "User unable to joining an existing team"

        with pytest.raises(InternalException):
            api.team.join_team(team["team_name"], team["password"], uid)
            assert False, "Was able to register and join the team twice."

        # attempt to join a non existent team
        with pytest.raises(InternalException):
            invalid_team_user = base_user.copy()
            invalid_team_user["username"] = "******"
            invalid_uid = api.user.create_simple_user_request(invalid_team_user)
            api.team.join_team("Totally Invalid", team["password"], uid)
            assert False, "Was able to join a team that doesn't exist."

        # attempt to join an existing team with an invalid password
        with pytest.raises(WebException):
            invalid_team_user = base_user.copy()
            invalid_team_user["username"] = "******"
            invalid_uid = api.user.create_simple_user_request(invalid_team_user)
            api.team.join_team(team["team_name"], "bad-password", uid)
            assert False, "Was able to join a team with an invalid password."

        team_uids = api.team.get_team_uids(tid)

        assert len(team_uids
                  ) == 1, "Invalid teams were created though the tests passed."
        assert uid in team_uids, "User was not successfully placed into the existing team."
Exemplo n.º 17
0
    def test_get_team(self):
        """
        Tests retrieving the team from a given uid.

        Covers:
            team.create_team
            user.create_user_request
            user.get_team
        """

        team = base_team.copy()
        tid = api.team.create_team(team)
        uid = api.user.create_user_request(base_user.copy())

        result_team = api.user.get_team(uid=uid)
        assert tid == result_team['tid'], "Unable to pair uid and tid."
Exemplo n.º 18
0
    def test_get_team(self):
        """
        Tests retrieving the team from a given uid.

        Covers:
            team.create_team
            user.create_user_request
            user.get_team
        """

        team = base_team.copy()
        tid = api.team.create_team(team)
        uid = api.user.create_user_request(base_user.copy())

        result_team = api.user.get_team(uid=uid)
        assert tid == result_team['tid'], "Unable to pair uid and tid."
Exemplo n.º 19
0
    def test_get_team(self):
        """
        Tests retrieving the team from a given uid.

        Covers:
            team.create_team
            user.create_user
            user.get_team
        """

        team = base_team.copy()
        tid = api.team.create_team(team)

        # user is now on an auto created individual team
        uid = api.user.create_simple_user_request(base_user.copy())
        # join a real team
        api.team.join_team(team["team_name"], team["password"], uid)
        result_team = api.user.get_team(uid=uid)
        assert tid == result_team['tid'], "Unable to pair uid and tid."
Exemplo n.º 20
0
    def test_get_team(self):
        """
        Tests retrieving the team from a given uid.

        Covers:
            team.create_team
            user.create_user
            user.get_team
        """

        team = base_team.copy()
        tid = api.team.create_team(team)

        # user is now on an auto created individual team
        uid = api.user.create_simple_user_request(base_user.copy())
        # join a real team
        api.team.join_team(team["team_name"], team["password"], uid)
        result_team = api.user.get_team(uid=uid)
        assert tid == result_team['tid'], "Unable to pair uid and tid."
Exemplo n.º 21
0
    def test_get_team_uids(self):
        """
        Tests the code that retrieves the list of uids on a team

        Covers:
            team.create_team
            user.create_user_request
            team.get_team_uids
        """

        tid = api.team.create_team(base_team.copy())

        uids = []
        for i in range(api.team.max_team_users):
            test_user = base_user.copy()
            test_user['username'] += str(i)
            uids.append(api.user.create_user_request(test_user))

        team_uids = api.team.get_team_uids(tid)
        assert len(team_uids) == api.team.max_team_users, "Team does not have correct number of members"
        assert sorted(uids) == sorted(team_uids), "Team does not have the correct members"
Exemplo n.º 22
0
    def test_create_user_request_existing_team(self):
        """
        Tests the registration of users on existing teams.

        Covers:
            partially: user.create_user_request
            team.get_team_uids
            team.create_team
        """

        tid = api.team.create_team(base_team.copy())
        assert tid, "Team was not created."

        uid = api.user.create_user_request(base_user.copy())
        assert uid == api.user.get_user(
            name=base_user["username"]
        )["uid"], "Good user created unsuccessfully."

        with pytest.raises(WebException):
            api.user.create_user_request(base_user.copy())
            assert False, "Was able to register and join the team twice."

        with pytest.raises(WebException):
            invalid_team_user = base_user.copy()
            invalid_team_user["team-name-existing"] = "Totally Invalid"
            api.user.create_user_request(invalid_team_user)
            assert False, "Was able to join a team that doesn't exist."

        with pytest.raises(WebException):
            invalid_team_user = base_user.copy()
            invalid_team_user["team-password-existing"] = "Not correct"
            api.user.create_user_request(invalid_team_user)
            assert False, "Was able to join a team with an invalid password."

        team_uids = api.team.get_team_uids(tid)

        assert uid in team_uids, "User was not successfully placed into the existing team."
        assert len(
            team_uids
        ) == 1, "Invalid teams were created though the tests passed."
Exemplo n.º 23
0
    def test_create_user_request_existing_team(self):
        """
        Tests the registration of users on existing teams.

        Covers:
            partially: user.create_user_request
            team.get_team_uids
            team.create_team
        """

        tid = api.team.create_team(base_team.copy())
        assert tid, "Team was not created."

        uid = api.user.create_user_request(base_user.copy())
        assert uid == api.user.get_user(name=base_user["username"])["uid"], "Good user created unsuccessfully."

        with pytest.raises(WebException):
            api.user.create_user_request(base_user.copy())
            assert False, "Was able to register and join the team twice."

        with pytest.raises(WebException):
            invalid_team_user = base_user.copy()
            invalid_team_user["username"] = "******"
            invalid_team_user["team-name-existing"] = "Totally Invalid"
            api.user.create_user_request(invalid_team_user)
            assert False, "Was able to join a team that doesn't exist."

        with pytest.raises(WebException):
            invalid_team_user = base_user.copy()
            invalid_team_user["username"] = "******"
            invalid_team_user["team-password-existing"] = "Not correct"
            api.user.create_user_request(invalid_team_user)
            assert False, "Was able to join a team with an invalid password."

        team_uids = api.team.get_team_uids(tid)

        assert len(team_uids) == 1, "Invalid teams were created though the tests passed."
        assert uid in team_uids, "User was not successfully placed into the existing team."
Exemplo n.º 24
0
    def test_get_team_uids(self):
        """
        Tests the code that retrieves the list of uids on a team

        Covers:
            team.create_team
            user.create_user_request
            team.get_team_uids
        """

        tid = api.team.create_team(base_team.copy())

        uids = []
        for i in range(api.team.max_team_users):
            test_user = base_user.copy()
            test_user['username'] += str(i)
            uids.append(api.user.create_user_request(test_user))

        team_uids = api.team.get_team_uids(tid)
        assert len(
            team_uids
        ) == api.team.max_team_users, "Team does not have correct number of members"
        assert sorted(uids) == sorted(
            team_uids), "Team does not have the correct members"