def serialize_json_infrastructure_test(): file_json = util.load_json_from_file('infrastructure_response.json') infrastructure = util.create_example_infrastructure() infrastructure_json = infrastructure.serialize(util.JSON_MIMETYPE) assert util.json_are_equal(infrastructure_json, file_json)
def serialize_xml_infrastructure_test(): data = util.load_clean_xml_payload('infrastructure_response.xml') infrastructure = util.create_example_infrastructure() infrastructure_xml = infrastructure.serialize(util.XML_MIMETYPE).decode('utf-8') assert infrastructure_xml in data
def _check_infrastructure_dict_contents(dictionary): expected_infrastructure = util.create_example_infrastructure() assert expected_infrastructure.name in dictionary['name'] assert expected_infrastructure.keystone_url in dictionary['keystone_url'] assert expected_infrastructure.username in dictionary['username'] assert expected_infrastructure.password in dictionary['password'] assert expected_infrastructure.tenant in dictionary['tenant']
def json_infrastructure_from_model_parser_test(): payload = util.load_json_from_file('infrastructure_response.json') infrastructure = util.create_example_infrastructure() infrastructure_factory = _create_factory(util.JSON_MIMETYPE, Infrastructure) response = infrastructure_factory.from_model(infrastructure) assert util.json_are_equal(response, payload)
def serialize_wrong_mimetype_infrastructure_test(): infrastructure = util.create_example_infrastructure() try: infrastructure.serialize(util.WRONG_MIMETYPE) assert False except NotImplementedError as e: assert 'Unrecognized mimetype or model type' in str(e)
def _check_infrastructure_model_contents(model): expected_infrastructure = util.create_example_infrastructure() assert expected_infrastructure.name in model.name assert expected_infrastructure.keystone_url in model.keystone_url assert expected_infrastructure.username in model.username assert expected_infrastructure.password in model.password assert expected_infrastructure.tenant in model.tenant
def xml_infrastructure_from_model_parser_test(): payload = util.load_clean_xml_payload('infrastructure_response.xml') infrastructure = util.create_example_infrastructure() infrastructure_factory = _create_factory(util.XML_MIMETYPE, Infrastructure) response = infrastructure_factory.from_model(infrastructure) assert response.decode("utf-8") in payload
def from_empty_openstack_flavor_list_test(): mordor = util.create_example_infrastructure() flavor_collection = FlavorCollection([]) converted_collection = FlavorCollection.from_openstack_flavor_list( [], mordor) assert util.json_are_equal( flavor_collection.to_dict(), converted_collection.to_dict())
def from_openstack_flavor_test(): data = util.load_json_from_file('flavor_response.json') openstackflavor = OpenStackFlavor(None, data['flavor']) infrastructure = util.create_example_infrastructure() flavor = util.create_example_flavor() converted_flavor = Flavor.from_openstack_flavor(openstackflavor, infrastructure) assert util.json_are_equal(flavor.to_dict(), converted_flavor.to_dict())
def from_openstack_flavor_list_test(): data = util.load_json_from_file('flavor_collection_response.json') for flavor in data['flavors']: del(flavor['nodes']) openstackflavors = [OpenStackFlavor(None, data['flavors'][0]), OpenStackFlavor(None, data['flavors'][1])] mordor = util.create_example_infrastructure() flavor_collection = util.create_example_flavor_collection(mordor) for flavor in flavor_collection.flavors: flavor.public = False converted_collection = FlavorCollection.from_openstack_flavor_list( openstackflavors, mordor) assert util.json_are_equal( flavor_collection.to_dict(), converted_collection.to_dict())
def infrastructure_to_dict_test(): expected_dict = {"infrastructure": {"name" : "Mordor"}} infrastructure = util.create_example_infrastructure() assert expected_dict == infrastructure.to_dict()
def infrastructure_to_content_dict_test(): infrastructure = util.create_example_infrastructure() assert 'Mordor' in infrastructure._to_content_dict()