def serialize_xml_flavor_test():
    data = util.load_clean_xml_payload('flavor_response.xml')
    
    flavor = util.create_example_flavor()
    
    flavor_xml = flavor.serialize(util.XML_MIMETYPE).decode('utf-8')
    assert flavor_xml in data
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 _check_flavor_dict_contents(dictionary):
    expected_flavor = util.create_example_flavor()
    
    assert expected_flavor.name in dictionary['name']
    assert expected_flavor.vcpus == dictionary['vcpus']
    assert expected_flavor.ram == dictionary['ram']
    assert expected_flavor.disk == dictionary['disk']
    assert expected_flavor.swap == dictionary['swap']
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 serialize_wrong_mimetype_flavor_test():
    flavor = util.create_example_flavor()
    
    try:
        flavor.serialize(util.WRONG_MIMETYPE)
        assert False
    except NotImplementedError as e:
        assert 'Unrecognized mimetype or model type' in str(e)
def _check_flavor_model_contents(model):
    expected_flavor = util.create_example_flavor()
    
    assert expected_flavor.name in model.name
    assert expected_flavor.vcpus == model.vcpus
    assert expected_flavor.ram == model.ram
    assert expected_flavor.disk == model.disk
    assert expected_flavor.swap == model.swap
def xml_flavor_from_model_parser_test():
    payload = util.load_clean_xml_payload('flavor_response.xml')
    
    flavor = util.create_example_flavor()
    
    flavor_factory = _create_factory(util.XML_MIMETYPE, Flavor)
    
    response = flavor_factory.from_model(flavor)
    assert response.decode("utf-8") in 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 flavor_collection_extend_list_test():
    flavor1 = util.create_example_flavor()
    flavor2 = util.create_secondary_example_flavor()
    
    flavor_collection1 = FlavorCollection([])
    flavor_collection2 = FlavorCollection([flavor1])
    flavor_collection3 = FlavorCollection([flavor2])
    
    flavors = [flavor1]
    flavor_collection1.extend(flavor_collection2)
    
    assert flavor_collection1.flavors == flavors
    
    flavors = [flavor1, flavor2]
    flavor_collection1.extend(flavor_collection3)
    
    assert flavor_collection1.flavors == flavors
def flavor_to_dict_test():
    expected_dict = util.load_json_from_file('flavor_response.json')
    
    flavor = util.create_example_flavor()
    
    assert util.json_are_equal(expected_dict, flavor.to_dict())
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())