Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-vault
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-vault
Commits
18629579
Commit
18629579
authored
2 years ago
by
David Douard
Browse files
Options
Downloads
Patches
Plain Diff
Add a test for the vault db initialization command `swh db init vault`
parent
e5dfc237
No related branches found
Branches containing commit
Tags
v1.7.1
Tags containing commit
1 merge request
!160
Add a test for the vault db initialization command `swh db init vault`
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/vault/backend.py
+6
-1
6 additions, 1 deletion
swh/vault/backend.py
swh/vault/tests/test_cli.py
+54
-0
54 additions, 0 deletions
swh/vault/tests/test_cli.py
with
60 additions
and
1 deletion
swh/vault/backend.py
+
6
−
1
View file @
18629579
# Copyright (C) 2017-202
0
The Software Heritage developers
# Copyright (C) 2017-202
2
The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
...
...
@@ -77,6 +77,11 @@ class VaultBackend:
self
.
storage
=
get_storage
(
**
config
[
"
storage
"
])
self
.
smtp_server
=
smtplib
.
SMTP
(
**
config
.
get
(
"
smtp
"
,
{}))
if
"
db
"
not
in
self
.
config
:
raise
ValueError
(
"
The
'
db
'
configuration entry is missing
"
"
in the vault configuration file
"
)
db_conn
=
config
[
"
db
"
]
self
.
_pool
=
psycopg2
.
pool
.
ThreadedConnectionPool
(
config
.
get
(
"
min_pool_conns
"
,
1
),
...
...
This diff is collapsed.
Click to expand it.
swh/vault/tests/test_cli.py
+
54
−
0
View file @
18629579
...
...
@@ -10,7 +10,12 @@ import click
import
click.testing
import
pytest
from
swh.core.cli.db
import
db
as
swhdb
from
swh.core.db
import
BaseDb
from
swh.core.db.db_utils
import
swh_db_module
,
swh_db_version
from
swh.core.db.tests.test_cli
import
craft_conninfo
from
swh.model.swhids
import
CoreSWHID
from
swh.vault.backend
import
VaultBackend
from
swh.vault.cli
import
vault
as
vault_cli_group
from
swh.vault.cookers.base
import
BaseVaultCooker
from
swh.vault.in_memory_backend
import
InMemoryVaultBackend
...
...
@@ -104,3 +109,52 @@ def test_cook_directory(bundle_type, cooker_name_suffix, swhid_type, mocker):
cooker
.
cook
.
assert_called_once_with
()
assert
result
.
stdout_bytes
==
b
"
bundle content
"
def
test_cli_swh_vault_db_create_and_init_db
(
postgresql
,
tmp_path
):
"""
Test that
'
swh db init vault
'
works
"""
module_name
=
"
vault
"
conninfo
=
craft_conninfo
(
postgresql
,
"
new-db
"
)
cfgfile
=
tmp_path
/
"
config.yml
"
CFG
=
f
"""
vault:
cls: postgresql
db:
{
conninfo
}
cache:
cls: memory
storage:
cls: memory
scheduler:
cls: remote
url: mock://scheduler
"""
cfgfile
.
write_text
(
CFG
)
cli_runner
=
click
.
testing
.
CliRunner
()
# This creates the db and installs the necessary admin extensions
result
=
cli_runner
.
invoke
(
swhdb
,
[
"
create
"
,
module_name
,
"
--dbname
"
,
conninfo
])
assert
result
.
exit_code
==
0
,
f
"
Unexpected output:
{
result
.
output
}
"
result
=
cli_runner
.
invoke
(
swhdb
,
[
"
init-admin
"
,
module_name
,
"
--dbname
"
,
conninfo
])
assert
result
.
exit_code
==
0
,
f
"
Unexpected output:
{
result
.
output
}
"
# This initializes the schema and data
result
=
cli_runner
.
invoke
(
swhdb
,
[
"
-C
"
,
cfgfile
,
"
init
"
,
module_name
])
assert
result
.
exit_code
==
0
,
f
"
Unexpected output:
{
result
.
output
}
"
assert
swh_db_module
(
conninfo
)
==
"
vault
"
assert
swh_db_version
(
conninfo
)
==
VaultBackend
.
current_version
with
BaseDb
.
connect
(
conninfo
).
cursor
()
as
cur
:
cur
.
execute
(
"
select tablename from pg_tables where schemaname=
'
public
'"
)
tables
=
{
table
for
table
,
in
cur
.
fetchall
()}
assert
tables
==
{
"
dbmodule
"
,
"
dbversion
"
,
"
vault_bundle
"
,
"
vault_notif_email
"
,
"
vault_batch
"
,
"
vault_batch_bundle
"
,
}
This diff is collapsed.
Click to expand it.
Phabricator Migration user
@phabricator-migration
mentioned in merge request
!161 (closed)
·
2 years ago
mentioned in merge request
!161 (closed)
mentioned in merge request !161
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment