示例#1
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
        )
示例#2
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()
示例#3
0
def setup_test_pgdb():
    # create the first user if they don't already exist
    admin_user = User.get_existing_user_by_email(PGDB_TEST, TestData.USER_ADMIN["email_addr"])
    if admin_user is None:
        admin_data = TestData.USER_ADMIN
        admin_user = User.create_new_user(
            DB_TUPLE_TEST,
            admin_data["email_addr"],
            admin_data["username"],
            admin_data["cleartext_password"],
            admin_data["user_statement"],
            admin_data["is_enabled"],
            admin_data["metaspace_privileges"],
            admin_data["creator"],
        )
        ns_data = TestData.NODESPACE_1
        Nodespace.create_new_nodespace(
            DB_TUPLE_TEST, ns_data["nodespace_name"], ns_data["nodespace_description"], admin_user.user_id
        )
示例#4
0
def Nodespace_test():
    ns_data = TestData.NS_ARSFT
    admin_user = User.get_existing_user_by_email(PGDB_TEST, TestData.USER_ADMIN["email_addr"])
    ns_data["creator"] = admin_user.user_id

    with AutoRollbackTransaction() as test_trans:
        ns = Nodespace.create_new_nodespace(
            DB_TUPLE_PT_NM, ns_data["nodespace_name"], ns_data["nodespace_description"], ns_data["creator"]
        )
        ns_data["nodespace_id"] = ns.nodespace_id

        for field_name in Nodespace.FIELD_NAMES:
            if field_name not in ["creation_date"]:
                assert ns_data[field_name] == vars(ns)[field_name]

        ns = Nodespace.get_existing_nodespace(PGDB_TEST, ns_data["nodespace_name"])

        for field_name in Nodespace.FIELD_NAMES:
            if field_name not in ["creation_date"]:
                assert ns_data[field_name] == vars(ns)[field_name]

        assert Nodespace.is_valid_nodespace_name("_named_like-a-private-pyth0n-var")
        assert not Nodespace.is_valid_nodespace_name("")
示例#5
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