Allow new cassettes to be recorded via fixture

This change allows the Betamax default workflow to be used via the
fixture. That workflow is:

- Write a test that uses Betamax but for which no cassette presently
  exists
- Run test which causes Betamax to create the cassette and record the
  interactions
- Re-run tests and ensure that no network activity has actually happened

Keystoneauth1's YamlJsonSerializer relied on yaml.safe_load to return
something other than None if a file was loaded. Unfortunately, if the
file is zero-length then it will return None which breaks the above
workflow.

Instead, let's check the return value and if it is not None, return it,
otherwise, simply return an empty dictionary as Betamax expects.

Change-Id: I5b7d01439f391e2ecb589850e90573c74cd38080
Closes-bug: #1670697
This commit is contained in:
Ian Cordasco 2017-03-07 08:16:23 -06:00
parent 3364703d3b
commit 6da2d42137
1 changed files with 6 additions and 2 deletions

View File

@ -89,6 +89,10 @@ class YamlJsonSerializer(betamax.serializers.base.BaseSerializer):
def deserialize(self, cassette_data):
try:
return yaml.safe_load(cassette_data)
deserialized = yaml.safe_load(cassette_data)
except yaml.error.YAMLError:
return {}
deserialized = None
if deserialized is not None:
return deserialized
return {}