Skip to content

Commit

Permalink
Added @pytest.mark.webtest to all tests using internet connection
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg committed Jun 21, 2023
1 parent 44759cf commit c135649
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion scopesim/tests/tests_server/test_database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
import os
import sys
from tempfile import TemporaryDirectory
from urllib3.exceptions import HTTPError

Expand All @@ -13,6 +12,7 @@
from scopesim import rc


@pytest.mark.webtest
def test_package_list_loads():
pkgs = db.get_server_package_list()
assert isinstance(pkgs, dict)
Expand All @@ -25,12 +25,15 @@ def test_get_package_name():
assert pkg_name == "Packagename"


@pytest.mark.webtest
def test_get_all_latest():
all_pkg = db.get_all_package_versions()
assert dict(db.get_all_latest(all_pkg))["test_package"].endswith(".dev")


@pytest.mark.webtest
class TestGetZipname:
# TODO: This could use some kind of mock to avoid server access
all_pkg = db.get_all_package_versions()

def test_gets_stable(self):
Expand All @@ -49,22 +52,27 @@ def test_throws_for_nonexisting_release(self):


class TestGetServerFolderContents:
@pytest.mark.webtest
def test_downloads_locations(self):
pkgs = list(db.get_server_folder_contents("locations"))
assert len(pkgs) > 0

@pytest.mark.webtest
def test_downloads_telescopes(self):
pkgs = list(db.get_server_folder_contents("telescopes"))
assert len(pkgs) > 0

@pytest.mark.webtest
def test_downloads_instruments(self):
pkgs = list(db.get_server_folder_contents("instruments"))
assert len(pkgs) > 0

@pytest.mark.webtest
def test_finds_armazones(self):
pkgs = list(db.get_server_folder_contents("locations"))
assert "Armazones" in pkgs[0]

@pytest.mark.webtest
def test_throws_for_wrong_url_server(self):
original_url = rc.__config__["!SIM.file.server_base_url"]
rc.__config__["!SIM.file.server_base_url"] = "https://scopesim.univie.ac.at/bogus/"
Expand All @@ -74,16 +82,19 @@ def test_throws_for_wrong_url_server(self):


class TestGetServerElements:
@pytest.mark.webtest
def test_throws_an_error_if_url_doesnt_exist(self):
with pytest.raises(ValueError):
dbex.get_server_elements(url="www.bogus.server")

@pytest.mark.webtest
def test_returns_folders_if_server_exists(self):
url = rc.__config__["!SIM.file.server_base_url"]
pkgs = dbex.get_server_elements(url)
assert all([loc in pkgs for loc in
["locations/", "telescopes/", "instruments/"]])

@pytest.mark.webtest
def test_returns_files_if_zips_exist(self):
url = rc.__config__["!SIM.file.server_base_url"]
dir = "instruments/"
Expand All @@ -92,15 +103,18 @@ def test_returns_files_if_zips_exist(self):


class TestListPackages:
@pytest.mark.webtest
def test_lists_all_packages_without_qualifier(self):
pkgs = db.list_packages()
assert "Armazones" in pkgs
assert "MICADO" in pkgs

@pytest.mark.webtest
def test_lists_only_packages_with_qualifier(self):
pkgs = db.list_packages("Armazones")
assert np.all(["Armazones" in pkg for pkg in pkgs])

@pytest.mark.webtest
def test_throws_for_nonexisting_pkgname(self):
with pytest.raises(ValueError):
db.list_packages("bogus")
Expand All @@ -110,6 +124,7 @@ class TestDownloadPackage:
"""
Old download function, for backwards compatibility
"""
@pytest.mark.webtest
def test_downloads_package_successfully(self):
pkg_path = "instruments/test_package.zip"

Expand All @@ -126,6 +141,7 @@ def test_downloads_package_successfully(self):


class TestDownloadPackages:
@pytest.mark.webtest
def test_downloads_stable_package(self):
with TemporaryDirectory() as tmpdir:
db.download_packages(["test_package"], release="stable",
Expand All @@ -139,6 +155,7 @@ def test_downloads_stable_package(self):
version_dict = yaml.full_load(f)
assert version_dict["release"] == "stable"

@pytest.mark.webtest
def test_downloads_latest_package(self):
with TemporaryDirectory() as tmpdir:
db.download_packages("test_package", release="latest",
Expand All @@ -149,6 +166,7 @@ def test_downloads_latest_package(self):

assert version_dict["release"] == "dev"

@pytest.mark.webtest
def test_downloads_specific_package(self):
release = "2022-04-09.dev"
with TemporaryDirectory() as tmpdir:
Expand All @@ -160,6 +178,7 @@ def test_downloads_specific_package(self):

assert version_dict["version"] == release

@pytest.mark.webtest
def test_downloads_github_version_of_package_with_semicolon(self):
release = "github:728761fc76adb548696205139e4e9a4260401dfc"
with TemporaryDirectory() as tmpdir:
Expand All @@ -169,6 +188,7 @@ def test_downloads_github_version_of_package_with_semicolon(self):

assert os.path.exists(filename)

@pytest.mark.webtest
def test_downloads_github_version_of_package_with_at_symbol(self):
release = "github@728761fc76adb548696205139e4e9a4260401dfc"
with TemporaryDirectory() as tmpdir:
Expand All @@ -180,6 +200,7 @@ def test_downloads_github_version_of_package_with_at_symbol(self):


class TestDownloadGithubFolder:
@pytest.mark.webtest
def test_downloads_current_package(self):
with TemporaryDirectory() as tmpdir:
# tmpdir = "."
Expand All @@ -189,6 +210,7 @@ def test_downloads_current_package(self):

assert os.path.exists(filename)

@pytest.mark.webtest
def test_downloads_with_old_commit_hash(self):
with TemporaryDirectory() as tmpdir:
url = "https://github.com/AstarVienna/irdb/tree/728761fc76adb548696205139e4e9a4260401dfc/ELT"
Expand All @@ -198,6 +220,7 @@ def test_downloads_with_old_commit_hash(self):
assert os.path.exists(filename)


@pytest.mark.webtest
def test_old_download_package_signature():
with TemporaryDirectory() as tmpdir:
db.download_package(["instruments/test_package.zip"], save_dir=tmpdir)
Expand Down

0 comments on commit c135649

Please sign in to comment.