Skip to content

Commit fb2825b

Browse files
committed
improved testing
1 parent 185a039 commit fb2825b

File tree

8 files changed

+76
-50
lines changed

8 files changed

+76
-50
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ celerybeat.pid
120120
*.sage.py
121121

122122
# Environments
123-
.env
124123
.venv
125124
env/
126125
venv/
@@ -158,3 +157,6 @@ cython_debug/
158157
# and can be added to the global gitignore or merged into this file. For a more nuclear
159158
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160159
#.idea/
160+
161+
# Temp files
162+
temp/

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"python.testing.unittestArgs": [
3+
"-v",
4+
"-s",
5+
"./tests",
6+
"-p",
7+
"test_*.py"
8+
],
9+
"python.envFile": "${workspaceFolder}/tests/e2e/.env",
10+
"python.testing.pytestEnabled": false,
11+
"python.testing.unittestEnabled": true
12+
}

tests/e2e/.env

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
VAULTWARDEN_VERSION="testing"
2+
VAULTWARDEN_URL="http://localhost:8080"
3+
VAULTWARDEN_ADMIN_TOKEN="admin"
4+
VAULTWARDEN_INVITATIONS_ALLOWED="true"
5+
BITWARDEN_URL="http://localhost:8080"
6+
BITWARDEN_EMAIL="test-account@example.com"
7+
BITWARDEN_PASSWORD="test-account"
8+
BITWARDEN_CLIENT_ID="user.a8be340c-856b-481f-8183-2b7712995da2"
9+
BITWARDEN_CLIENT_SECRET="ag66paVUq4h7tBLbCbJOY5tJkQvUuT"
10+
BITWARDEN_TEST_ORGANIZATION="cda840d2-1de0-4f31-bd49-b30dacd7e8b0"
11+
BITWARDEN_DEVICE_ID="e54ba5f5-7d58-4830-8f2b-99194c70c14f"

tests/e2e/compose.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
vaultwarden:
3+
image: vaultwarden/server:${VAULTWARDEN_VERSION}
4+
container_name: python_vaultwarden_test
5+
ports:
6+
- "8080:80"
7+
volumes:
8+
- ./temp:/data
9+
environment:
10+
INVITATIONS_ALLOWED: ${VAULTWARDEN_INVITATIONS_ALLOWED}
11+
I_REALLY_WANT_VOLATILE_STORAGE: "true"
12+
ADMIN_TOKEN: ${VAULTWARDEN_ADMIN_TOKEN}
13+
restart: unless-stopped

tests/e2e/docker_helper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import shutil
3+
from time import sleep
4+
5+
def start_docker():
6+
shutil.copytree("tests/fixtures/server", "tests/e2e/temp/", dirs_exist_ok=True)
7+
os.system("docker compose -f tests/e2e/compose.yaml up -d")
8+
sleep(1)
9+
10+
def stop_docker():
11+
os.system("docker compose -f tests/e2e/compose.yaml down")
12+
try:
13+
shutil.rmtree("tests/e2e/temp")
14+
except FileNotFoundError:
15+
pass

tests/e2e/run_tests.sh

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/e2e/test_bitwarden.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@
44
from vaultwarden.clients.bitwarden import BitwardenAPIClient
55
from vaultwarden.models.bitwarden import get_organization
66

7+
from .docker_helper import start_docker, stop_docker
8+
79
# Get Bitwarden credentials from environment variables
810
url = os.environ.get("BITWARDEN_URL", None)
911
email = os.environ.get("BITWARDEN_EMAIL", None)
1012
password = os.environ.get("BITWARDEN_PASSWORD", None)
1113
client_id = os.environ.get("BITWARDEN_CLIENT_ID", None)
1214
client_secret = os.environ.get("BITWARDEN_CLIENT_SECRET", None)
1315
device_id = os.environ.get("BITWARDEN_DEVICE_ID", None)
14-
bitwarden = BitwardenAPIClient(
15-
url, email, password, client_id, client_secret, device_id
16-
)
1716

1817
# Get test organization id from environment variables
1918
test_organization = os.environ.get("BITWARDEN_TEST_ORGANIZATION", None)
2019

2120

2221
class BitwardenBasic(unittest.TestCase):
22+
def tearDownClass() -> None:
23+
stop_docker()
24+
2325
def setUp(self) -> None:
24-
self.organization = get_organization(bitwarden, test_organization)
26+
start_docker()
27+
self.bitwarden = BitwardenAPIClient(
28+
url, email, password, client_id, client_secret, device_id
29+
)
30+
self.organization = get_organization(self.bitwarden, test_organization)
2531
self.test_colls_names = self.organization.collections(as_dict=True)
2632
self.test_colls_ids = self.organization.collections()
2733
self.test_users = self.organization.users()
@@ -39,6 +45,9 @@ def setUp(self) -> None:
3945
"test-collection-2"
4046
).users()
4147

48+
def tearDown(self) -> None:
49+
stop_docker()
50+
4251
def test_get_organization_users(self):
4352
self.assertEqual(len(self.test_users), 2)
4453

tests/e2e/test_vaultwarden.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44

55
from vaultwarden.clients.vaultwarden import VaultwardenAdminClient
66

7+
from .docker_helper import start_docker, stop_docker
8+
79
# Get Vaultwarden Admin credentials from environment variables
810
url = os.environ.get("VAULTWARDEN_URL", None)
911
admin_token = os.environ.get("VAULTWARDEN_ADMIN_TOKEN", None)
1012

1113

1214
# TODO Add tests for VaultwardenAdminClient
1315
class VaultwardenAdminClientBasic(unittest.TestCase):
16+
def tearDownClass() -> None:
17+
stop_docker()
18+
1419
def setUp(self) -> None:
20+
start_docker()
1521
self.vaultwarden = VaultwardenAdminClient(
1622
url=url, admin_secret_token=admin_token
1723
)
24+
25+
def tearDown(self) -> None:
26+
stop_docker()

0 commit comments

Comments
 (0)