Files
duty-teller/tests/test_config.py
Nikolay Tatarinov 28973489a5 Refactor project structure and enhance Docker configuration
- Updated `.dockerignore` to exclude test and development artifacts, optimizing the Docker image size.
- Refactored `main.py` to delegate execution to `duty_teller.run.main()`, simplifying the entry point.
- Introduced a new `duty_teller` package to encapsulate core functionality, improving modularity and organization.
- Enhanced `pyproject.toml` to define a script for running the application, streamlining the execution process.
- Updated README documentation to reflect changes in project structure and usage instructions.
- Improved Alembic environment configuration to utilize the new package structure for database migrations.
2026-02-18 13:03:14 +03:00

37 lines
1.3 KiB
Python

"""Tests for config.is_admin and config.can_access_miniapp."""
import duty_teller.config as config
def test_is_admin_true_when_in_admin_list(monkeypatch):
monkeypatch.setattr(config, "ADMIN_USERNAMES", {"admin1", "admin2"})
assert config.is_admin("admin1") is True
assert config.is_admin("ADMIN1") is True
assert config.is_admin("admin2") is True
def test_is_admin_false_when_not_in_list(monkeypatch):
monkeypatch.setattr(config, "ADMIN_USERNAMES", {"admin1"})
assert config.is_admin("other") is False
assert config.is_admin("") is False
def test_can_access_miniapp_allowed_username(monkeypatch):
monkeypatch.setattr(config, "ALLOWED_USERNAMES", {"user1"})
monkeypatch.setattr(config, "ADMIN_USERNAMES", set())
assert config.can_access_miniapp("user1") is True
assert config.can_access_miniapp("USER1") is True
def test_can_access_miniapp_admin_has_access(monkeypatch):
monkeypatch.setattr(config, "ALLOWED_USERNAMES", set())
monkeypatch.setattr(config, "ADMIN_USERNAMES", {"admin1"})
assert config.can_access_miniapp("admin1") is True
def test_can_access_miniapp_denied(monkeypatch):
monkeypatch.setattr(config, "ALLOWED_USERNAMES", {"user1"})
monkeypatch.setattr(config, "ADMIN_USERNAMES", set())
assert config.can_access_miniapp("other") is False
assert config.can_access_miniapp("") is False