lundi 3 juin 2019

Convert MagicMock object to something I can use in my test

I have this code in my test:

now = datetime.utcnow().strftime("%Y%m%d")
        extended_listing_mock_response_basic = {
            "IsTruncated": False,
            "Buckets": [
                {
                    "Name": "bucketnamefoo",
                    "CreationDate": str(now),
                    "LocationConstraint": "bar-standard"
                }
            ],
            "Owner": {
                "DisplayName": "ownerfoo",
                "ID": "idfoo"
            }
        }
        s = self.create_session()
        client = s.create_client('s3', region_name='us-east-1', aws_access_key_id='foo',
            aws_secret_access_key='bar')
        # Create a mock response.
        self.mock_response = Mock()
        self.mock_response = extended_listing_mock_response_basic
        request = client.list_buckets()

When I run it I get this error:

  File "/core/ibm_botocore/auth.py", line 349, in signature
    request.context['timestamp'][0:8])
  File "/core/ibm_botocore/auth.py", line 169, in _sign
    sig = hmac.new(key, msg.encode('utf-8'), sha256).digest()
  File "/Users/me/.pyenv/versions/2.7.8/lib/python2.7/hmac.py", line 136, in new
    return HMAC(key, msg, digestmod)
  File "/Users/me/.pyenv/versions/2.7.8/lib/python2.7/hmac.py", line 75, in __init__
    self.outer.update(key.translate(trans_5C))
TypeError: must be convertible to a buffer, not MagicMock

I tried request = client.list_buckets() but get the same error. How do I convert this to a type I can use?

Aucun commentaire:

Enregistrer un commentaire