File: test_managedblockchain_invitations.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (118 lines) | stat: -rw-r--r-- 4,186 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import boto3
import pytest
from botocore.exceptions import ClientError

from moto import mock_aws

from . import helpers


class TestManagedBlockchainInvitations:
    mock = mock_aws()

    @classmethod
    def setup_class(cls):
        cls.mock.start()
        cls.conn = boto3.client("managedblockchain", region_name="us-east-1")
        response = cls.conn.create_network(
            Name="testnetwork1",
            Framework="HYPERLEDGER_FABRIC",
            FrameworkVersion="1.2",
            FrameworkConfiguration=helpers.default_frameworkconfiguration,
            VotingPolicy=helpers.default_votingpolicy,
            MemberConfiguration=helpers.default_memberconfiguration,
        )
        cls.network_id = response["NetworkId"]
        cls.member_id = response["MemberId"]

    @classmethod
    def teardown_class(cls):
        cls.mock.stop()

    def test_create_2_invitations(self):
        # Create proposal
        proposal_id = self.conn.create_proposal(
            NetworkId=self.network_id,
            MemberId=self.member_id,
            Actions=helpers.multiple_policy_actions,
        )["ProposalId"]

        # Get proposal details
        response = self.conn.get_proposal(
            NetworkId=self.network_id, ProposalId=proposal_id
        )
        assert response["Proposal"]["NetworkId"] == self.network_id
        assert response["Proposal"]["Status"] == "IN_PROGRESS"

        # Vote yes
        self.conn.vote_on_proposal(
            NetworkId=self.network_id,
            ProposalId=proposal_id,
            VoterMemberId=self.member_id,
            Vote="YES",
        )

        # Get the invitation
        response = self.conn.list_invitations()
        assert len(response["Invitations"]) == 2
        assert response["Invitations"][0]["NetworkSummary"]["Id"] == self.network_id
        assert response["Invitations"][0]["Status"] == "PENDING"
        assert response["Invitations"][1]["NetworkSummary"]["Id"] == self.network_id
        assert response["Invitations"][1]["Status"] == "PENDING"

    def test_reject_invitation(self):
        # Create proposal
        proposal_id = self.conn.create_proposal(
            NetworkId=self.network_id,
            MemberId=self.member_id,
            Actions=helpers.default_policy_actions,
        )["ProposalId"]

        # Get proposal details
        response = self.conn.get_proposal(
            NetworkId=self.network_id, ProposalId=proposal_id
        )
        assert response["Proposal"]["NetworkId"] == self.network_id
        assert response["Proposal"]["Status"] == "IN_PROGRESS"

        # Vote yes
        self.conn.vote_on_proposal(
            NetworkId=self.network_id,
            ProposalId=proposal_id,
            VoterMemberId=self.member_id,
            Vote="YES",
        )

        # Get the invitation
        response = self.conn.list_invitations()
        assert response["Invitations"][0]["NetworkSummary"]["Id"] == self.network_id
        assert response["Invitations"][0]["Status"] == "PENDING"
        invitation_id = response["Invitations"][0]["InvitationId"]

        # Reject - thanks but no thanks
        self.conn.reject_invitation(InvitationId=invitation_id)

        # Check the invitation status
        response = self.conn.list_invitations()
        assert response["Invitations"][0]["InvitationId"] == invitation_id
        assert response["Invitations"][0]["Status"] == "REJECTED"

    def test_reject_invitation_badinvitation(self):
        proposal_id = self.conn.create_proposal(
            NetworkId=self.network_id,
            MemberId=self.member_id,
            Actions=helpers.default_policy_actions,
        )["ProposalId"]

        self.conn.vote_on_proposal(
            NetworkId=self.network_id,
            ProposalId=proposal_id,
            VoterMemberId=self.member_id,
            Vote="YES",
        )

        with pytest.raises(ClientError) as ex:
            self.conn.reject_invitation(InvitationId="in-ABCDEFGHIJKLMNOP0123456789")
        err = ex.value.response["Error"]
        assert err["Code"] == "ResourceNotFoundException"
        assert "InvitationId in-ABCDEFGHIJKLMNOP0123456789 not found." in err["Message"]