Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port last integration tests to python #2966

Merged
merged 6 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions _integration-test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import os
import subprocess
import time

import httpx
import pytest

Expand All @@ -10,8 +11,10 @@
TEST_PASS = "test123TEST"
TIMEOUT_SECONDS = 60


def pytest_addoption(parser):
parser.addoption("--customizations", default="disabled")
parser.addoption("--customizations", default="disabled")


@pytest.fixture(scope="session", autouse=True)
def configure_self_hosted_environment(request):
Expand All @@ -28,23 +31,23 @@
raise AssertionError("timeout waiting for self-hosted to come up")

if request.config.getoption("--customizations") == "enabled":
os.environ['TEST_CUSTOMIZATIONS'] = "enabled"
script_content = '''\
os.environ["TEST_CUSTOMIZATIONS"] = "enabled"
script_content = """\

Check warning on line 35 in _integration-test/conftest.py

View check run for this annotation

Codecov / codecov/patch

_integration-test/conftest.py#L34-L35

Added lines #L34 - L35 were not covered by tests
#!/bin/bash
touch /created-by-enhance-image
apt-get update
apt-get install -y gcc libsasl2-dev python-dev libldap2-dev libssl-dev
'''
"""

with open('sentry/enhance-image.sh', 'w') as script_file:
with open("sentry/enhance-image.sh", "w") as script_file:

Check warning on line 42 in _integration-test/conftest.py

View check run for this annotation

Codecov / codecov/patch

_integration-test/conftest.py#L42

Added line #L42 was not covered by tests
script_file.write(script_content)
# Set executable permissions for the shell script
os.chmod('sentry/enhance-image.sh', 0o755)
os.chmod("sentry/enhance-image.sh", 0o755)

Check warning on line 45 in _integration-test/conftest.py

View check run for this annotation

Codecov / codecov/patch

_integration-test/conftest.py#L45

Added line #L45 was not covered by tests

# Write content to the requirements.txt file
with open('sentry/requirements.txt', 'w') as req_file:
req_file.write('python-ldap\n')
os.environ['MINIMIZE_DOWNTIME'] = "1"
with open("sentry/requirements.txt", "w") as req_file:
req_file.write("python-ldap\n")
os.environ["MINIMIZE_DOWNTIME"] = "1"

Check warning on line 50 in _integration-test/conftest.py

View check run for this annotation

Codecov / codecov/patch

_integration-test/conftest.py#L48-L50

Added lines #L48 - L50 were not covered by tests
subprocess.run(["./install.sh"], check=True)
# Create test user
subprocess.run(
Expand All @@ -68,7 +71,8 @@
text=True,
)


@pytest.fixture()
def setup_backup_restore_env_variables():
os.environ['SENTRY_DOCKER_IO_DIR'] = os.path.join(os.getcwd(), 'sentry')
os.environ['SKIP_USER_CREATION'] = "1"
os.environ["SENTRY_DOCKER_IO_DIR"] = os.path.join(os.getcwd(), "sentry")
os.environ["SKIP_USER_CREATION"] = "1"
46 changes: 0 additions & 46 deletions _integration-test/custom-ca-roots/setup.sh

This file was deleted.

4 changes: 0 additions & 4 deletions _integration-test/custom-ca-roots/teardown.sh

This file was deleted.

5 changes: 3 additions & 2 deletions _integration-test/custom-ca-roots/test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import unittest

import requests


class CustomCATests(unittest.TestCase):
def test_valid_self_signed(self):
self.assertEqual(requests.get("https://self.test").text, 'ok')
self.assertEqual(requests.get("https://self.test").text, "ok")

def test_invalid_self_signed(self):
with self.assertRaises(requests.exceptions.SSLError):
requests.get("https://fail.test")


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
27 changes: 0 additions & 27 deletions _integration-test/ensure-sentry-admin-works.sh

This file was deleted.

64 changes: 54 additions & 10 deletions _integration-test/test_backup.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,69 @@
import subprocess
import os
import subprocess


def test_sentry_admin(setup_backup_restore_env_variables):
sentry_admin_sh = os.path.join(os.getcwd(), "sentry-admin.sh")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for porting this! :)

output = subprocess.run(
[sentry_admin_sh, "--help"], check=True, capture_output=True, encoding="utf8"
).stdout
assert "Usage: ./sentry-admin.sh" in output
assert "SENTRY_DOCKER_IO_DIR" in output

output = subprocess.run(
[sentry_admin_sh, "permissions", "--help"],
check=True,
capture_output=True,
encoding="utf8",
).stdout
assert "Usage: ./sentry-admin.sh permissions" in output


def test_backup(setup_backup_restore_env_variables):
# 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()
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)
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_backup_restore_env_variables):
# 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", "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", "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)
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,
)
Loading
Loading