Skip to content

Commit

Permalink
Port backup tests to python (#2907)
Browse files Browse the repository at this point in the history
* port backup tests to python
  • Loading branch information
hubertdeng123 authored Mar 21, 2024
1 parent 8a5086d commit eba2282
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 74 deletions.
30 changes: 30 additions & 0 deletions _integration-test/backup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import subprocess
import os
import pytest

@pytest.fixture()
def setup_env():
os.environ['SENTRY_DOCKER_IO_DIR'] = os.path.join(os.getcwd(), 'sentry')
os.environ['SKIP_USER_CREATION'] = "1"

def test_backup(setup_env):
# Docker was giving me permissioning issues when trying to create this file and write to it even after giving read + write access
# to group and owner. Instead, try creating the empty file and then give everyone write access to the backup file
file_path = os.path.join(os.getcwd(), 'sentry', 'backup.json')
sentry_admin_sh = os.path.join(os.getcwd(), 'sentry-admin.sh')
open(file_path, 'a', encoding='utf8').close()
os.chmod(file_path, 0o666)
assert os.path.getsize(file_path) == 0
subprocess.run([sentry_admin_sh, "export", "global", "/sentry-admin/backup.json", "--no-prompt"], check=True)
assert os.path.getsize(file_path) > 0

def test_import(setup_env):
# Bring postgres down and recreate the docker volume
subprocess.run(["docker", "compose", "--ansi", "never", "stop", "postgres"], check=True)
subprocess.run(["docker", "compose", "--ansi", "never", "rm", "-f", "-v", "postgres"], check=True)
subprocess.run(["docker", "volume", "rm", "sentry-postgres"], check=True)
subprocess.run(["docker", "volume", "create", "--name=sentry-postgres"], check=True)
subprocess.run(["docker", "compose", "--ansi", "never", "run", "web", "upgrade", "--noinput"], check=True)
subprocess.run(["docker", "compose", "--ansi", "never", "up", "-d"], check=True)
sentry_admin_sh = os.path.join(os.getcwd(), 'sentry-admin.sh')
subprocess.run([sentry_admin_sh, "import", "global", "/sentry-admin/backup.json", "--no-prompt"], check=True)
47 changes: 47 additions & 0 deletions _integration-test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import subprocess
import os
import time
import httpx
import pytest

SENTRY_CONFIG_PY = "sentry/sentry.conf.py"
SENTRY_TEST_HOST = os.getenv("SENTRY_TEST_HOST", "http://localhost:9000")
TEST_USER = "[email protected]"
TEST_PASS = "test123TEST"
TIMEOUT_SECONDS = 60


@pytest.fixture(scope="session", autouse=True)
def configure_self_hosted_environment():
subprocess.run(["docker", "compose", "--ansi", "never", "up", "-d"], check=True)
for i in range(TIMEOUT_SECONDS):
try:
response = httpx.get(SENTRY_TEST_HOST, follow_redirects=True)
except httpx.ConnectionError:
time.sleep(1)
else:
if response.status_code == 200:
break
else:
raise AssertionError("timeout waiting for self-hosted to come up")

# Create test user
subprocess.run(
[
"docker",
"compose",
"exec",
"web",
"sentry",
"createuser",
"--force-update",
"--superuser",
"--email",
TEST_USER,
"--password",
TEST_PASS,
"--no-input",
],
check=True,
text=True,
)
36 changes: 0 additions & 36 deletions _integration-test/ensure-backup-restore-works.sh

This file was deleted.

36 changes: 0 additions & 36 deletions _integration-test/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,6 @@ def get_sentry_dsn(client: httpx.Client) -> str:
return sentry_dsn


@pytest.fixture(scope="session", autouse=True)
def configure_self_hosted_environment():
subprocess.run(["docker", "compose", "--ansi", "never", "up", "-d"], check=True)
for i in range(TIMEOUT_SECONDS):
try:
response = httpx.get(SENTRY_TEST_HOST, follow_redirects=True)
except httpx.ConnectionError:
time.sleep(1)
else:
if response.status_code == 200:
break
else:
raise AssertionError("timeout waiting for self-hosted to come up")

# Create test user
subprocess.run(
[
"docker",
"compose",
"exec",
"web",
"sentry",
"createuser",
"--force-update",
"--superuser",
"--email",
TEST_USER,
"--password",
TEST_PASS,
"--no-input",
],
check=True,
text=True,
)


@pytest.fixture()
def client_login():
client = httpx.Client()
Expand Down
4 changes: 2 additions & 2 deletions integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [[ "$test_option" == "--initial-install" ]]; then
echo "Testing initial install"
pytest --reruns 5 _integration-test/run.py
source _integration-test/ensure-customizations-not-present.sh
source _integration-test/ensure-backup-restore-works.sh
pytest _integration-test/backup.py
elif [[ "$test_option" == "--customizations" ]]; then
echo "Testing customizations"
$dc up -d
Expand All @@ -36,5 +36,5 @@ EOT
./install.sh
pytest --reruns 5 _integration-test/run.py
source _integration-test/ensure-customizations-work.sh
source _integration-test/ensure-backup-restore-works.sh
pytest _integration-test/backup.py
fi

0 comments on commit eba2282

Please sign in to comment.