def test_member_class(self):
        @dataclass
        class TestCase:
            name: str
            give_raw: dict

        tests = [
            TestCase(
                name='success',
                give_raw=dtapiresponses.user_member,
            ),
        ]

        for test in tests:
            member = disruptive.outputs.Member(test.give_raw)

            raw = test.give_raw

            assert member.member_id == raw['name'].split('/')[-1]
            assert member.display_name == raw['displayName']
            assert member.email == raw['email']
            assert member.roles == [r.split('/')[-1] for r in raw['roles']]
            assert member.status == raw['status']
            assert member.email == raw['email']
            assert member.account_type == raw['accountType']
            assert member.create_time == dttrans.to_datetime(raw['createTime'])
示例#2
0
    def test_unpack(self, request_mock):
        # Update the response data with Service Account data.
        res = dtapiresponses.service_account1
        request_mock.json = res

        # Call the appropriate endpoint.
        s = disruptive.ServiceAccount.get_service_account(
            'service_account_id',
            'project_id',
        )

        # Assert attributes unpacked correctly.
        assert s.service_account_id == res['name'].split('/')[-1]
        assert s.email == res['email']
        assert s.display_name == res['displayName']
        assert s.basic_auth_enabled == res['enableBasicAuth']
        assert s.create_time == dttrans.to_datetime(res['createTime'])
        assert s.update_time == dttrans.to_datetime(res['updateTime'])
    def __init__(self, service_account: dict) -> None:
        """
        Constructs the ServiceAccount object by unpacking the raw response.

        Parameters
        ----------
        service_account : dict
            Unmodified Service Account response dictionary.

        """

        # Inherit from Response parent.
        dtoutputs.OutputBase.__init__(self, service_account)

        # Unpack attributes from dictionary.
        self.service_account_id: str = service_account['name'].split('/')[-1]
        self.email: str = service_account['email']
        self.display_name: str = service_account['displayName']
        self.basic_auth_enabled: bool = service_account['enableBasicAuth']
        self.create_time: Optional[datetime] = \
            dttrans.to_datetime(service_account['createTime'])
        self.update_time: Optional[datetime] = \
            dttrans.to_datetime(service_account['updateTime'])
示例#4
0
    def test_key_attributes(self, request_mock):
        # Update the response data with Service Account data.
        res = dtapiresponses.key_without_secret
        request_mock.json = res

        # Call the appropriate endpoint.
        k = disruptive.ServiceAccount.get_key(
            'service_account_id',
            'key_id',
            'project_id',
        )

        # Assert attributes unpacked correctly.
        assert k.key_id == res['name'].split('/')[-1]
        assert k.create_time == dttrans.to_datetime(res['createTime'])
        assert k.secret is None
    def __init__(self, member: dict) -> None:
        """
        Constructs the Member object by unpacking the raw response.

        """

        # Inherit from Response parent.
        OutputBase.__init__(self, member)

        # Unpack attributes from dictionary.
        self.member_id = member['name'].split('/')[-1]
        self.display_name = member['displayName']
        self.roles = [r.split('/')[-1] for r in member['roles']]
        self.status = member['status']
        self.email = member['email']
        self.account_type = member['accountType']
        self.create_time = dttrans.to_datetime(member['createTime'])
    def __init__(self, key: dict) -> None:
        """
        Constructs the Key object by unpacking the raw key response.

        Parameters
        ----------
        key : dict
            Key response dictionary.

        """
        # Inherit from Response parent.
        dtoutputs.OutputBase.__init__(self, key)

        # Initialize secret, which is only not-None when created.
        self.secret: Optional[str] = None

        # Unpack attributes from dictionary.
        self.key_id: str = key['id']
        self.create_time: Optional[datetime] = \
            dttrans.to_datetime(key['createTime'])
        if 'secret' in key:
            self.secret = key['secret']
示例#7
0
 def test_to_datetime_already_datetime(self):
     inp = datetime(1970, 1, 1, tzinfo=timezone(timedelta(hours=2)))
     outp = datetime(1970, 1, 1, tzinfo=timezone(timedelta(hours=2)))
     assert dttrans.to_datetime(inp) == outp
示例#8
0
 def test_to_datetime_tz_offset(self):
     inp = '1970-01-01T00:00:00+02:00'
     outp = datetime(1970, 1, 1, tzinfo=timezone(timedelta(hours=2)))
     assert dttrans.to_datetime(inp) == outp
示例#9
0
 def test_to_datetime_tz_utc(self):
     inp = '1970-01-01T00:00:00Z'
     outp = datetime(1970, 1, 1, tzinfo=timezone(timedelta(hours=0)))
     assert dttrans.to_datetime(inp) == outp
示例#10
0
 def test_to_datetime_missing_tz(self):
     inp = '1970-01-01T00:00:00'
     with pytest.raises(dterrors.FormatError):
         dttrans.to_datetime(inp)
示例#11
0
 def test_to_datetime_none(self):
     inp = None
     outp = None
     assert dttrans.to_datetime(inp) == outp
示例#12
0
 def test_to_datetime_invalid_type(self):
     inp = {'timestamp': datetime(1970, 1, 1)}
     with pytest.raises(TypeError):
         dttrans.to_datetime(inp)