Пример #1
0
def test_AppHighLevel_plan_work():
    "AppHighLevel: test plan_work"
    from datetime import datetime
    from mob_map_dl.common import MapMeta
    from mob_map_dl.main import AppHighLevel

    print "Start"
    #Create source and destination lists
    src = [
        MapMeta("map1", "f/map1", 1, datetime(2000, 1, 1), "foo", "bar"),
        MapMeta("map2", "f/map2", 1, datetime(2000, 1, 1), "foo", "bar"),
        MapMeta("map3", "f/map3", 1, datetime(2000, 1, 1), "foo", "bar")
    ]
    dst = [
        MapMeta("map1", "f/map1", 1, datetime(2000, 1, 1), "foo", "bar"),
        MapMeta("map2", "f/map2", 1, datetime(1999, 1, 1), "foo", "bar")
    ]

    app = AppHighLevel()

    work = app.plan_work(src, dst, "only_missing")
    pprint(work)
    assert len(work) == 1
    assert work[0].disp_name == "map3"

    work = app.plan_work(src, dst, "replace_newer")
    pprint(work)
    assert len(work) == 2
    assert work[0].disp_name == "map2"
    assert work[1].disp_name == "map3"

    work = app.plan_work(src, dst, "replace_all")
    pprint(work)
    assert len(work) == 3
Пример #2
0
def test_AppHighLevel_plan_work():
    "AppHighLevel: test plan_work"
    from datetime import datetime
    from mob_map_dl.common import MapMeta
    from mob_map_dl.main import AppHighLevel
    
    print "Start"
    #Create source and destination lists
    src = [MapMeta("map1", "f/map1", 1, datetime(2000, 1, 1), "foo", "bar"),
           MapMeta("map2", "f/map2", 1, datetime(2000, 1, 1), "foo", "bar"),
           MapMeta("map3", "f/map3", 1, datetime(2000, 1, 1), "foo", "bar")]
    dst = [MapMeta("map1", "f/map1", 1, datetime(2000, 1, 1), "foo", "bar"),
           MapMeta("map2", "f/map2", 1, datetime(1999, 1, 1), "foo", "bar")]
    
    app = AppHighLevel()
    
    work = app.plan_work(src, dst, "only_missing")
    pprint(work)
    assert len(work) == 1
    assert work[0].disp_name == "map3"
    
    work = app.plan_work(src, dst, "replace_newer")
    pprint(work)
    assert len(work) == 2
    assert work[0].disp_name == "map2"
    assert work[1].disp_name == "map3"
    
    work = app.plan_work(src, dst, "replace_all")
    pprint(work)
    assert len(work) == 3
Пример #3
0
def test_AppHighLevel_find_mobile_devices():
    """
    AppHighLevel: test find_mobile_devices()
    
    No real test, but at least the code for the current algorithm is run.
    """
    from mob_map_dl.main import AppHighLevel
    
    print "Start"
    app = AppHighLevel()
    d = app.find_mobile_devices()
    print d
Пример #4
0
def test_AppHighLevel_find_mobile_devices():
    """
    AppHighLevel: test find_mobile_devices()
    
    No real test, but at least the code for the current algorithm is run.
    """
    from mob_map_dl.main import AppHighLevel

    print "Start"
    app = AppHighLevel()
    d = app.find_mobile_devices()
    print d
Пример #5
0
def test_AppHighLevel_download_install():
    "AppHighLevel: test get_filtered_map_list()"
    from mob_map_dl.main import AppHighLevel
    
    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m07")
    
    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)
    
    app.download_install(["*Monaco*", "*Faroe-islands*"], mode="only_missing")
    
    assert path.isfile(path.join(app_directory, "osmand", 
                                 "Faroe-islands_europe_2.obf.zip"))
    assert path.isfile(path.join(mobile_device, "osmand", 
                                 "Faroe-islands_europe_2.obf"))
Пример #6
0
def test_AppHighLevel_get_filtered_map_list():
    "AppHighLevel: test get_filtered_map_list()"
    from mob_map_dl.main import AppHighLevel

    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m01")
    app = AppHighLevel()
    app.create_low_level_components(app_directory=app_directory,
                                    mobile_device=mobile_device)

    #List maps on remote servers whose names contain the word "Monaco".
    maps = app.get_filtered_map_list(app.downloaders, ["*Monaco*"])
    pprint(maps)
    assert len(maps) == 1
    assert maps[0].disp_name == "osmand/Monaco_europe_2.obf"
    assert maps[0].full_name.find("download.osmand.net") > 0

    #List all locally downloaded maps.
    maps = app.get_filtered_map_list(app.local_managers, ["*"])
    pprint(maps)
    assert len(maps) == 3
    assert maps[0].disp_name == "oam/SouthAmerica_bermuda"
    assert maps[1].disp_name == "osmand/Jamaica_centralamerica_2.obf"
    assert maps[2].disp_name == "osmand/Monaco_europe_2.obf"
    assert maps[0].full_name.find("test_tmp/mob_map_dl") > 0

    #List all maps that are installed on the current device.
    maps = app.get_filtered_map_list(app.installers, ["*"])
    pprint(maps)
    assert len(maps) == 3
    assert maps[0].disp_name == "oam/SouthAmerica_bermuda"
    assert maps[1].disp_name == "osmand/Jamaica_centralamerica_2.obf"
    assert maps[2].disp_name == "osmand/Monaco_europe_2.obf"
    assert maps[0].full_name.find("test_tmp/TEST-DEVICE") > 0
Пример #7
0
def test_AppHighLevel_download_file():
    "AppHighLevel: test download_file()"
    from mob_map_dl.main import AppHighLevel
    from mob_map_dl.common import MapMeta
    
    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m03")    
    file_meta = MapMeta(disp_name="osmand/Cape-verde_africa_2.obf", 
                        full_name="http://download.osmand.net/download.php?standard=yes&file=Cape-verde_africa_2.obf.zip", 
                        size=None, time=None, description=None, map_type=None)
    
    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)
    
    app.download_file(file_meta)
    
    assert path.isfile(path.join(app_directory, 
                                 "osmand/Cape-verde_africa_2.obf.zip"))
Пример #8
0
def test_AppHighLevel_filter_possible_work():
    from mob_map_dl.common import MapMeta
    from mob_map_dl.main import AppHighLevel
    
    print "Start"
    #Create application and device directories to initialize the application
    app_directory, mobile_device = create_writable_test_dirs("m02")
    #Create source and destination lists
    work = [MapMeta("osmand/map1", None, None, None, None, None),
            MapMeta("foo/map2", None, None, None, None, None),
            MapMeta("bar/map3", None, None, None, None, None)]
    
    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)
    
    good_work = app.filter_possible_work(work, app.local_managers)
    pprint(good_work)
    
    assert len(good_work) == 1
    assert good_work[0].disp_name == "osmand/map1"
Пример #9
0
def test_AppHighLevel_install_file():
    "AppHighLevel: test install_file()"
    from mob_map_dl.main import AppHighLevel
    from mob_map_dl.common import MapMeta
    
    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m04")
    file_meta = MapMeta(disp_name="osmand/Monaco_europe_2.obf", 
                        full_name=path.join(app_directory, 
                                            "osmand/Monaco_europe_2.obf.zip"), 
                        size=None, time=None, description=None, map_type=None)
    #Remove file that will be created though install algorithm
    os.remove(path.join(mobile_device, "osmand/Monaco_europe_2.obf"))
    
    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)
    
    app.install_file(file_meta)
    
    assert path.isfile(path.join(mobile_device, "osmand/Monaco_europe_2.obf"))  
Пример #10
0
def test_AppHighLevel_delete_file_local():
    "AppHighLevel: test install_file()"
    from mob_map_dl.main import AppHighLevel
    from mob_map_dl.common import MapMeta
    
    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m06")
    file_meta = MapMeta(disp_name="osmand/Monaco_europe_2.obf", 
                        full_name=None, size=None, time=None, 
                        description=None, map_type=None)
    delete_path = path.join(app_directory, "osmand/Monaco_europe_2.obf.zip")
    #Test that directory that we are going to delete really exists
    assert path.exists(delete_path)
    
    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)
    
    app.delete_file_local(file_meta)
    
    #test that file has really been deleted
    assert not path.exists(delete_path)
Пример #11
0
def test_AppHighLevel_get_filtered_map_list():
    "AppHighLevel: test get_filtered_map_list()"
    from mob_map_dl.main import AppHighLevel
    
    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m01")
    app = AppHighLevel()
    app.create_low_level_components(app_directory=app_directory, 
                                    mobile_device=mobile_device)
    
    #List maps on remote servers whose names contain the word "Monaco".
    maps = app.get_filtered_map_list(app.downloaders, ["*Monaco*"])
    pprint(maps)
    assert len(maps) == 1
    assert maps[0].disp_name == "osmand/Monaco_europe_2.obf"
    assert maps[0].full_name.find("download.osmand.net") > 0
    
    #List all locally downloaded maps.
    maps = app.get_filtered_map_list(app.local_managers, ["*"])
    pprint(maps)
    assert len(maps) == 3
    assert maps[0].disp_name == "oam/SouthAmerica_bermuda" 
    assert maps[1].disp_name == "osmand/Jamaica_centralamerica_2.obf" 
    assert maps[2].disp_name == "osmand/Monaco_europe_2.obf"
    assert maps[0].full_name.find("test_tmp/mob_map_dl") > 0
    
    #List all maps that are installed on the current device.
    maps = app.get_filtered_map_list(app.installers, ["*"])
    pprint(maps)
    assert len(maps) == 3
    assert maps[0].disp_name == "oam/SouthAmerica_bermuda"
    assert maps[1].disp_name == "osmand/Jamaica_centralamerica_2.obf" 
    assert maps[2].disp_name == "osmand/Monaco_europe_2.obf"
    assert maps[0].full_name.find("test_tmp/TEST-DEVICE") > 0
Пример #12
0
def test_AppHighLevel_filter_possible_work():
    from mob_map_dl.common import MapMeta
    from mob_map_dl.main import AppHighLevel

    print "Start"
    #Create application and device directories to initialize the application
    app_directory, mobile_device = create_writable_test_dirs("m02")
    #Create source and destination lists
    work = [
        MapMeta("osmand/map1", None, None, None, None, None),
        MapMeta("foo/map2", None, None, None, None, None),
        MapMeta("bar/map3", None, None, None, None, None)
    ]

    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)

    good_work = app.filter_possible_work(work, app.local_managers)
    pprint(good_work)

    assert len(good_work) == 1
    assert good_work[0].disp_name == "osmand/map1"
Пример #13
0
def test_AppHighLevel_uninstall():
    "AppHighLevel: test get_filtered_map_list()"
    from mob_map_dl.main import AppHighLevel

    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m08")
    mob_file = path.join(mobile_device, "osmand", "Monaco_europe_2.obf")
    loc_file = path.join(app_directory, "osmand", "Monaco_europe_2.obf.zip")
    #Test if files that will be deleted exist
    assert path.isfile(mob_file)
    assert path.isfile(loc_file)

    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)

    app.uninstall(["*Monaco*"], delete_local=False)
    assert not path.isfile(mob_file)

    app.uninstall(["*Monaco*"], delete_local=True)
    assert not path.isfile(loc_file)
Пример #14
0
def test_AppHighLevel_download_install():
    "AppHighLevel: test get_filtered_map_list()"
    from mob_map_dl.main import AppHighLevel

    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m07")

    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)

    app.download_install(["*Monaco*", "*Faroe-islands*"], mode="only_missing")

    assert path.isfile(
        path.join(app_directory, "osmand", "Faroe-islands_europe_2.obf.zip"))
    assert path.isfile(
        path.join(mobile_device, "osmand", "Faroe-islands_europe_2.obf"))
Пример #15
0
def test_AppHighLevel_uninstall():
    "AppHighLevel: test get_filtered_map_list()"
    from mob_map_dl.main import AppHighLevel
    
    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m08")
    mob_file = path.join(mobile_device, "osmand", "Monaco_europe_2.obf")
    loc_file = path.join(app_directory, "osmand", "Monaco_europe_2.obf.zip")
    #Test if files that will be deleted exist
    assert path.isfile(mob_file)
    assert path.isfile(loc_file)
    
    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)
    
    app.uninstall(["*Monaco*"], delete_local=False)
    assert not path.isfile(mob_file)
    
    app.uninstall(["*Monaco*"], delete_local=True)
    assert not path.isfile(loc_file)
Пример #16
0
def test_AppHighLevel_install_file():
    "AppHighLevel: test install_file()"
    from mob_map_dl.main import AppHighLevel
    from mob_map_dl.common import MapMeta

    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m04")
    file_meta = MapMeta(disp_name="osmand/Monaco_europe_2.obf",
                        full_name=path.join(app_directory,
                                            "osmand/Monaco_europe_2.obf.zip"),
                        size=None,
                        time=None,
                        description=None,
                        map_type=None)
    #Remove file that will be created though install algorithm
    os.remove(path.join(mobile_device, "osmand/Monaco_europe_2.obf"))

    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)

    app.install_file(file_meta)

    assert path.isfile(path.join(mobile_device, "osmand/Monaco_europe_2.obf"))
Пример #17
0
def test_AppHighLevel_download_file():
    "AppHighLevel: test download_file()"
    from mob_map_dl.main import AppHighLevel
    from mob_map_dl.common import MapMeta

    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m03")
    file_meta = MapMeta(
        disp_name="osmand/Cape-verde_africa_2.obf",
        full_name=
        "http://download.osmand.net/download.php?standard=yes&file=Cape-verde_africa_2.obf.zip",
        size=None,
        time=None,
        description=None,
        map_type=None)

    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)

    app.download_file(file_meta)

    assert path.isfile(
        path.join(app_directory, "osmand/Cape-verde_africa_2.obf.zip"))
Пример #18
0
def test_AppHighLevel_delete_file_local():
    "AppHighLevel: test install_file()"
    from mob_map_dl.main import AppHighLevel
    from mob_map_dl.common import MapMeta

    print "Start"
    app_directory, mobile_device = create_writable_test_dirs("m06")
    file_meta = MapMeta(disp_name="osmand/Monaco_europe_2.obf",
                        full_name=None,
                        size=None,
                        time=None,
                        description=None,
                        map_type=None)
    delete_path = path.join(app_directory, "osmand/Monaco_europe_2.obf.zip")
    #Test that directory that we are going to delete really exists
    assert path.exists(delete_path)

    app = AppHighLevel()
    app.create_low_level_components(app_directory, mobile_device)

    app.delete_file_local(file_meta)

    #test that file has really been deleted
    assert not path.exists(delete_path)