-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add uniqueness constraint and tests for DomainCategory model and CLI
* Added `unique=True` constraint to the `label` field in `DomainCategory` model to enforce uniqueness at the database level. * Modified `domains_create` CLI command to check for duplicates before creating a new domain category, providing feedback if the domain already exists. * Added tests for `DomainCategory` model to validate creation, retrieval, and handling of duplicate labels. * Enhanced `test_cli_createdomain` * closes inveniosoftware/invenio-app-rdm#2796
- Loading branch information
Showing
4 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2015-2018 CERN. | ||
# Copyright (C) 2024 KTH Royal Institute of Technology. | ||
# | ||
# Invenio is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
@@ -10,6 +11,7 @@ | |
"""Module tests.""" | ||
|
||
from invenio_accounts.cli import ( | ||
domains_create, | ||
roles_add, | ||
roles_create, | ||
roles_remove, | ||
|
@@ -156,3 +158,28 @@ def test_cli_activate_deactivate(app): | |
assert result.exit_code == 0 | ||
result = runner.invoke(users_deactivate, ["[email protected]"]) | ||
assert result.exit_code == 0 | ||
|
||
|
||
def test_cli_createdomain(app): | ||
"""Test create domain CLI.""" | ||
runner = app.test_cli_runner() | ||
|
||
# Create a domain successfully | ||
result = runner.invoke(domains_create, ["mailprovider"]) | ||
assert result.exit_code == 0 | ||
assert "Domain mailprovider created successfully" in result.output | ||
|
||
# Reject Creating the same domain again | ||
result = runner.invoke(domains_create, ["mailprovider"]) | ||
assert result.exit_code == 0 | ||
assert "Domain mailprovider already exists." in result.output | ||
|
||
# Create another domain successfully | ||
result = runner.invoke(domains_create, ["kth.se"]) | ||
assert result.exit_code == 0 | ||
assert "Domain kth.se created successfully" in result.output | ||
|
||
# Create a domain with a fancy case should be treated like others | ||
result = runner.invoke(domains_create, ["MailPrOvIdEr"]) | ||
assert result.exit_code == 0 | ||
assert "Domain mailprovider already exists." in result.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters