class ContentTestCase(unittest.TestCase): def setUp(self): self.content = Content() def test_instructions(self): assert re.match(r'#.*\n', self.content.instructions()) def test_read(self): data = '''{ "pools": [ { "pool": "rbd", "gateways": [ { "host": "igw1", "tpg": [ { "image": "archive", "initiator": "iqn" } ] } ] } ] }''' with tempfile.NamedTemporaryFile(suffix=".tmp") as tmpfile: tmpfile.write(data) tmpfile.flush() self.content.read(tmpfile.name) assert self.content.submitted @raises(IOError) def test_read_ioerror(self): self.content.read("missing_file") @raises(RuntimeError) def test_read_runtimeerror(self): # Double comma data = '''{ "auth": [ { "host": "" } ], , "pools": [ { "gateways": [ { "host": [], "tpg": [] } ] } ] }''' with tempfile.NamedTemporaryFile(suffix=".tmp") as tmpfile: tmpfile.write(data) tmpfile.flush() self.content.read(tmpfile.name) # test_validate works in test_read def test_validate_exception(self): assert self.content.validate("{,}") == False def test_verify_mandatory_keys_pools(self): try: self.content.verify_mandatory_keys("{}") except ValueError, e: assert re.match(r"Mandatory key 'pools' is missing", str(e))
def setUp(self): self.content = Content()