def test_create_tier_config_request(self, post_mock):
     body_return = get_tier_config_request_contents
     post_mock.return_value = Response(True, body_return, 201)
     request = TierConfigRequestResource(config=self.config)
     tier_config_request = request.create(create_tier_config_request_body)
     post_mock.assert_called_with(
         headers={
             'Content-Type': 'application/json',
             'Authorization': 'ApiKey XXXX:YYYYY'
         },
         json=create_tier_config_request_body,
         timeout=300,
         url='http://localhost:8080/api/public/v1/tier/config-requests')
     assert tier_config_request.id == 'TCR-195-110-021-001'
 def test_inquire_tier_account_request(self, post_mock):
     post_mock.return_value = Response(True, '', 204)
     request = TierConfigRequestResource(config=self.config)
     id_tar = 'TAR-6458-9737-0065-004-001'
     tier_config_request = request.inquire(id_tar)
     assert post_mock.call_count == 1
     post_mock.assert_called_with(
         headers={
             'Content-Type': 'application/json',
             'Authorization': 'ApiKey XXXX:YYYYY'
         },
         timeout=300,
         url=('http://localhost:8080/api/public/v1/'
              'tier/config-requests/TAR-6458-9737-0065-004-001/inquire'))
     assert tier_config_request == ('', 204)
 def test_list_tier_config_request_ok(self, get_mock):
     get_mock.side_effect = [
         Response(True, list_tier_config_request_contents, 200)
     ]
     request = TierConfigRequestResource(config=self.config)
     tier_config_request = request.list()
     assert get_mock.call_count == 1
     get_mock.assert_has_calls([
         call(
             headers={
                 'Authorization': 'ApiKey XXXX:YYYYY',
                 'Content-Type': 'application/json'
             },
             params={'limit': 100},
             timeout=300,
             url='http://localhost:8080/api/public/v1/tier/config-requests')
     ])
     self.assertEqual(len(tier_config_request), 2, msg=None)
    def test_get_tier_config_request_ok(self, get_mock):

        get_mock.side_effect = [
            Response(True, '[' + get_tier_config_request_contents + ']', 200),
            Response(True, get_tier_config_request_contents, 200)
        ]
        request = TierConfigRequestResource(config=self.config)
        tier_config_request = request.get('TCR-6458-9737-0065-004-001')
        assert get_mock.call_count == 1
        self.assertEqual(tier_config_request.status, 'pending', msg=None)
        # 054922da-ceae-47de-8e5d-7a2950acbfe1
        url = 'http://localhost:8080/api/public/v1/tier/config-requests/TCR-6458-9737-0065-004-001'
        get_mock.assert_has_calls([
            call(headers={
                'Content-Type': 'application/json',
                'Authorization': 'ApiKey XXXX:YYYYY'
            },
                 timeout=300,
                 url=url)
        ])
        assert isinstance(tier_config_request, TierConfigRequest)
 def test_approve_tier_account_request(self, post_mock):
     body_request = {"template": {"id": "TP-1234-123-123"}}
     body_response = {
         "template": {
             "id": "TP-123-123-123",
             "representation": "Rendered"
         }
     }
     post_mock.return_value = Response(True, body_response, 200)
     request = TierConfigRequestResource(config=self.config)
     id_tar = 'TAR-6458-9737-0065-004-001'
     tier_config_request = request.approve(id_tar, 'TP-1234-123-123')
     assert post_mock.call_count == 1
     post_mock.assert_called_with(
         headers={
             'Content-Type': 'application/json',
             'Authorization': 'ApiKey XXXX:YYYYY'
         },
         timeout=300,
         json=body_request,
         url=('http://localhost:8080/api/public/v1/'
              'tier/config-requests/TAR-6458-9737-0065-004-001/approve'))
     assert tier_config_request == (body_response, 200)
 def test_fail_tar_unassign(self):
     request = TierConfigRequestResource()
     with pytest.raises(ValueError) as e:
         request.unassign(None)
     assert str(e.value) == 'Invalid ID'