예제 #1
0
    def decline_test(self):
        ns_inv_data = self.ns_inv_data
        test_ns = Nodespace.get_existing_nodespace(PGDB_TEST, TestData.NODESPACE_1["nodespace_name"])
        admin_user = User.get_existing_user_by_email(PGDB_TEST, TestData.USER_ADMIN["email_addr"])
        ns_inv_data["nodespace_id"] = test_ns.nodespace_id
        ns_inv_data["creator"] = admin_user.user_id

        with AutoRollbackTransaction() as test_trans:
            ns_invitation = NodespaceInvitation.create_new_invitation(
                PGDB_TEST,
                ns_inv_data["nodespace_invitation_code"],
                ns_inv_data["invitee_email_addr"],
                ns_inv_data["nodespace_id"],
                ns_inv_data["initial_nodespace_privileges"],
                ns_inv_data["invitation_msg"],
                ns_inv_data["creator"],
            )

            decision_date_lb = DateTimeUtil.datetime_now_utc_aware()
            ns_invitation.decline_invitation(PGDB_TEST)
            ns_invitation = NodespaceInvitation.get_existing_invitation(
                PGDB_TEST, ns_inv_data["nodespace_invitation_code"]
            )
            assert ns_invitation.was_accepted == False
            assert decision_date_lb <= ns_invitation.decision_date <= DateTimeUtil.datetime_now_utc_aware()
예제 #2
0
def NodespacePrivilegeChecker_tests():
    ns_inv_data = TestData.NS_INV_HORATIO
    test_ns = Nodespace.get_existing_nodespace(PGDB_TEST, TestData.NODESPACE_1["nodespace_name"])
    admin_user = User.get_existing_user_by_email(PGDB_TEST, TestData.USER_ADMIN["email_addr"])

    ns_inv_data["nodespace_id"] = test_ns.nodespace_id
    ns_inv_data["creator"] = admin_user.user_id

    with AutoRollbackTransaction() as test_trans:
        ns_invitation = NodespaceInvitation.create_new_invitation(
            PGDB_TEST,
            ns_inv_data["nodespace_invitation_code"],
            ns_inv_data["invitee_email_addr"],
            ns_inv_data["nodespace_id"],
            ns_inv_data["initial_nodespace_privileges"],
            ns_inv_data["invitation_msg"],
            ns_inv_data["creator"],
        )
        new_user = ns_invitation.create_user_and_accept_invitation(
            DB_TUPLE_PT_NM,
            ns_inv_data["invitee_username"],
            ns_inv_data["invitee_password"],
            ns_inv_data["invitee_user_statement"],
        )
        assert not NodespacePrivilegeChecker.is_allowed_to_do(
            DB_TUPLE_PT_NM, NodespacePrivilegeChecker.ALTER_NODESPACE_ACCESS_ACTION, test_ns, new_user, False
        )
예제 #3
0
    def accept_test(self):
        ns_inv_data = self.ns_inv_data
        test_ns = Nodespace.get_existing_nodespace(PGDB_TEST, TestData.NODESPACE_1["nodespace_name"])
        admin_user = User.get_existing_user_by_email(PGDB_TEST, TestData.USER_ADMIN["email_addr"])
        ns_inv_data["nodespace_id"] = test_ns.nodespace_id
        ns_inv_data["creator"] = admin_user.user_id

        with AutoRollbackTransaction() as test_trans:
            ns_invitation = NodespaceInvitation.create_new_invitation(
                PGDB_TEST,
                ns_inv_data["nodespace_invitation_code"],
                ns_inv_data["invitee_email_addr"],
                ns_inv_data["nodespace_id"],
                ns_inv_data["initial_nodespace_privileges"],
                ns_inv_data["invitation_msg"],
                ns_inv_data["creator"],
            )
            ns_inv_data["nodespace_invitation_id"] = ns_invitation.nodespace_invitation_id
            ns_inv_data["nodespace_invitation_code"] = ns_invitation.nodespace_invitation_code

            assert ns_inv_data["nodespace_invitation_code"] is not None
            for field_name in NodespaceInvitation.FIELD_NAMES:
                if field_name not in ["creation_date"]:
                    assert ns_inv_data[field_name] == vars(ns_invitation)[field_name]

            ns_invitation = NodespaceInvitation.get_existing_invitation(
                PGDB_TEST, ns_inv_data["nodespace_invitation_code"]
            )

            for field_name in NodespaceInvitation.FIELD_NAMES:
                if field_name not in ["creation_date"]:
                    assert ns_inv_data[field_name] == vars(ns_invitation)[field_name]

            decision_date_lb = DateTimeUtil.datetime_now_utc_aware()
            ns_invitation.create_user_and_accept_invitation(
                DB_TUPLE_PT_NM,
                ns_inv_data["invitee_username"],
                ns_inv_data["invitee_password"],
                ns_inv_data["invitee_user_statement"],
            )
            assert ns_invitation.was_accepted == True
            assert decision_date_lb <= ns_invitation.decision_date <= DateTimeUtil.datetime_now_utc_aware()

            new_user = User.get_existing_user_by_email(PGDB_TEST, ns_inv_data["invitee_email_addr"])
            assert new_user.user_id == ns_invitation.user_id
            assert new_user.check_password(ns_inv_data["invitee_password"]) == True