def serialize_json_flavor_test():
    file_json = util.load_json_from_file('flavor_response.json')
    
    flavor = util.create_example_flavor()
    
    flavor_json = flavor.serialize(util.JSON_MIMETYPE)
    assert util.json_are_equal(flavor_json, file_json)
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 json_flavor_from_model_parser_test():
    payload = util.load_json_from_file('flavor_response.json')
    flavor = util.create_example_flavor()
    
    flavor_factory = _create_factory(util.JSON_MIMETYPE, Flavor)
    
    response = flavor_factory.from_model(flavor)
    assert util.json_are_equal(response, payload)
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 deserialize_wrong_mimetype_flavor_test():
    data = util.load_json_from_file('flavor_creation_request.json')
    
    try:
        Flavor.deserialize(util.WRONG_MIMETYPE, data)
        assert False
    except NotImplementedError as e:
        assert 'Unrecognized mimetype or model type' in str(e)
def deserialize_wrong_mimetype_infrastructure_test():
    data = util.load_json_from_file('infrastructure_request.json')
    
    try:
        Infrastructure.deserialize(util.WRONG_MIMETYPE, data)
        assert False
    except NotImplementedError as e:
        assert 'Unrecognized mimetype or model type' in str(e)
def json_error_from_model_parser_test():
    payload = util.load_json_from_file('exception_response.json')
    
    factory = ParserFactory()
    type_factory = factory.get_parser(util.JSON_MIMETYPE, FlavorSyncError)
    
    error = FlavorSyncError('Error message')
    
    response = type_factory.from_model(error)
    assert util.json_are_equal(response, payload)
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 deserialize_json_flavor_test():
    data = util.load_json_from_file('flavor_creation_request.json')
    flavor = Flavor.deserialize(util.JSON_MIMETYPE, json.dumps(data))
    _check_flavor_model_contents(flavor)
def flavor_collection_to_dict_test():
    expected_dict = util.load_json_from_file('flavor_collection_response.json')
    
    flavor_collection = util.create_example_flavor_collection()
    
    assert util.json_are_equal(expected_dict, flavor_collection.to_dict())
def deserialize_json_infrastructure_test():
    data = util.load_json_from_file('infrastructure_request.json')
    infrastructure = Infrastructure.deserialize(util.JSON_MIMETYPE, json.dumps(data))
    _check_infrastructure_model_contents(infrastructure)
def flavor_to_content_dict_test():
    data = util.load_json_from_file('flavor_response.json')
    
    flavor = util.create_example_flavor()
    
    assert util.json_are_equal(data['flavor'], flavor._to_content_dict())