Exemplo n.º 1
0
def temp_directory_structure():
    # setup
    sim_db.rc.__rc__["FILE_LOCAL_DOWNLOADS_PATH"] = _parent_path
    sim_db.set_up_local_package_directory(_parent_path, True)

    # run tests
    yield

    # teardown
    shutil.rmtree(_parent_path)
Exemplo n.º 2
0
    def test_renames_when_num_cols_equals_num_names(self):
        svr_table = Table(data=[[1, 1], [1, 1]])
        svr_table.meta["comments"] = ["# name other"]

        renamed_tbl = sim_db.rename_table_colnames(svr_table)
        assert renamed_tbl.colnames[0] == "name"
        assert renamed_tbl.colnames[1] == "other"
Exemplo n.º 3
0
 def test_new_package_is_renamed_if_new_package_is_older(self):
     local_table = Table(names=["name", "date_modified"],
                         data=[["test_package"], ["2018-11-14"]])
     pkg_entry = Table(names=["name", "date_modified"],
                       data=[["test_package"], ["2018-11-09"]])
     new_local_table = sim_db.add_pkg_to_local_db(pkg_entry[0], local_table)
     assert new_local_table["name"][0] == "test_package"
     assert new_local_table["name"][1] == "test_package_2018-11-09"
Exemplo n.º 4
0
    def test_adds_row(self):
        local_table = Table(
            names=["name", "author", "date_added", "date_modified", "path"],
            data=[["test_package"], ["Kieran Leschinski"], ["2018-11-09"],
                  ["2018-11-09"], ["test_package.zip"]])
        len_local_table = len(local_table)
        pkg_entry = local_table[0]
        new_local_table = sim_db.add_pkg_to_local_db(pkg_entry, local_table)

        assert len(new_local_table) == len_local_table + 1
Exemplo n.º 5
0
 def test_returns_table_if_path_correct(self):
     svr_path = sim_db._svr_inst_db()
     assert type(sim_db.get_server_packages(svr_path)) == Table
     svr_path = sim_db._svr_psf_db()
     assert type(sim_db.get_server_packages(svr_path)) == Table
     svr_path = sim_db._svr_src_db()
     assert type(sim_db.get_server_packages(svr_path)) == Table
Exemplo n.º 6
0
 def test_returns_table_if_local_db_file_exists(self):
     local_dbs = sim_db.set_local_path_names(_parent_path)
     for path in local_dbs:
         db_tbl = sim_db.get_local_packages(path)
         assert isinstance(db_tbl, Table)
Exemplo n.º 7
0
def download_test_package():
    return sim_db.download_package("test_package")
Exemplo n.º 8
0
 def test_returns_none_if_package_not_it_table(self):
     svr_table = Table(names=["name", "path"],
                       data=[["test_package"], ["test_package.zip"]])
     assert sim_db.get_package_table_entry("bogus", svr_table) is None
Exemplo n.º 9
0
 def test_return_url_for_existing_package(self):
     svr_table = Table(names=["name", "path"],
                       data=[["test_package"], ["test_package.zip"]])
     path = sim_db.get_server_package_path("test_package", svr_table)
     assert path == "test_package.zip"
Exemplo n.º 10
0
 def test_returns_false_for_bogus_pkg_name(self):
     assert sim_db.check_package_exists("bogus") is False
Exemplo n.º 11
0
 def test_package_added_to_local_db(self):
     local_pkgs_before = sim_db.get_local_packages(sim_db._local_inst_db())
     sim_db.download_package("test_package")
     local_pkgs_after = sim_db.get_local_packages(sim_db._local_inst_db())
     assert len(local_pkgs_after) == len(local_pkgs_before) + 1
Exemplo n.º 12
0
 def test_package_file_exists_on_local_drive(self):
     local_filename = sim_db.download_package("test_package")
     assert os.path.exists(local_filename)
Exemplo n.º 13
0
 def test_raise_error_when_pkg_file_doesnt_exist(self):
     with pytest.raises(ValueError):
         sim_db.download_package("non_existent_pkg")
Exemplo n.º 14
0
 def test_raise_error_when_pkg_not_in_db(self):
     with pytest.raises(ValueError):
         sim_db.download_package("bogus")
Exemplo n.º 15
0
 def test_throws_error_if_local_db_file_path_is_bogus(self):
     local_db_path = "bogus.txt"
     with pytest.raises(ValueError):
         sim_db.get_local_packages(local_db_path)
Exemplo n.º 16
0
 def test_returns_none_for_wrong_path(self):
     svr_db_url = "www.my-server.bogus"
     assert sim_db.get_server_packages(svr_db_url) is None
Exemplo n.º 17
0
 def test_throws_exception_if_pkg_entry_isnt_astropy_row_class(self):
     local_table = Table(names=["name", "path"],
                         data=[["test_package"], ["test_package.zip"]])
     with pytest.raises(ValueError):
         sim_db.add_pkg_to_local_db("hello world!", local_table)
Exemplo n.º 18
0
    def test_throws_exception_when_not_enough_column_names(self):
        svr_table = Table(data=[[1, 1], [1, 1]])
        svr_table.meta["comments"] = ["# name"]

        with pytest.raises(Exception):
            sim_db.rename_table_colnames(svr_table)
Exemplo n.º 19
0
 def test_three_db_files_exist(self):
     for db_path in sim_db._local_paths():
         assert os.path.exists(db_path)
Exemplo n.º 20
0
 def test_returns_true_for_package_name(self):
     assert sim_db.check_package_exists("test_package") is True
Exemplo n.º 21
0
 def test_unzipped_folder_exists(self, download_test_package):
     local_filename = download_test_package
     sim_db.extract_package("test_package")
     assert os.path.exists(local_filename.replace(".zip", ""))
Exemplo n.º 22
0
 def test_returns_exception_if_package_path_is_broken(self):
     with pytest.raises(ValueError):
         sim_db.check_package_exists("non_existent_pkg")
Exemplo n.º 23
0
 def test_unzipped_folder_contains_files(self, download_test_package):
     local_filename = download_test_package
     sim_db.extract_package("test_package")
     num_files = len(os.listdir(local_filename.replace(".zip", "")))
     assert num_files > 0
Exemplo n.º 24
0
 def test_returns_none_if_package_not_in_dbs(self):
     svr_table = Table(names=["name", "path"],
                       data=[["test_package"], ["test_package.zip"]])
     path = sim_db.get_server_package_path("bogus", svr_table)
     assert path is None
Exemplo n.º 25
0
 def test_returns_url_with_right_data(self):
     svr_table = Table(names=["name", "path"],
                       data=[["test_package"], ["test_package.zip"]])
     return_tbl = sim_db.get_package_table_entry("test_package", svr_table)
     assert return_tbl["path"] == "test_package.zip"