diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 00000000..1d2bcadc --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,56 @@ +name: Deploy to Server + +on: + push: + branches: + - main + - develop + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up SSH + uses: webfactory/ssh-agent@v0.5.0 + with: + ssh-private-key: ${{ secrets.SERVER_SSH_KEY }} + + - name: Add server to known hosts + run: | + ssh-keyscan -H v3.dscrs.site >> ~/.ssh/known_hosts + + - name: Configure Git + run: | + git config --global user.email "gitea-actions@dscrs.site" + git config --global user.name "Gitea Actions" + + - name: Prepare deployment + run: | + git init + git add . + git commit -m "Prepare for deployment: $(date +'%Y-%m-%d %H:%M:%S')" + + - name: Deploy to Server + env: + SERVER_HOST: v3.dscrs.site + SERVER_USER: dokku + APP_NAME: core + run: | + git remote add dokku dokku@$SERVER_HOST:$APP_NAME + git push dokku HEAD:main -f + + - name: Notify Deployment + if: success() + run: | + echo "Deployment to $APP_NAME successful" + + - name: Handle Deployment Failure + if: failure() + run: | + echo "Deployment failed" + exit 1 diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index 92b1d8a6..027d255a 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -24,13 +24,13 @@ jobs: with: branch: 'main' git_remote_url: 'ssh://dokku@v2.discours.io:22/discoursio-api' - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + ssh_private_key: ${{ secrets.PROD_PRIVATE_KEY }} - name: Push to v3.dscrs.site branch if: github.ref == 'refs/heads/dev' uses: dokku/github-action@master with: branch: 'dev' - git_remote_url: 'ssh://dokku@v3.dscrs.site:22/core' + git_remote_url: 'ssh://dokku@staging.discours.io:22/core' ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} git_push_flags: '--force' diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml new file mode 100644 index 00000000..72978587 --- /dev/null +++ b/.gitea/workflows/tests.yml @@ -0,0 +1,65 @@ +name: Notification Module Tests + +on: + push: + branches: + - main + - develop + - 'feature/*' + pull_request: + branches: + - main + - develop + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.9', '3.10', '3.11'] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y python3-dev libpq-dev + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install poetry + poetry config virtualenvs.create false + poetry install --no-interaction --no-ansi + + - name: Run type checking + run: | + pip install mypy + mypy orm/notification.py + + - name: Run tests + run: | + pip install pytest + pytest tests/test_notification.py -v + + - name: Lint with ruff + run: | + pip install ruff + ruff check orm/notification.py + ruff format --check orm/notification.py + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + files: ./coverage.xml + flags: unittests + env_vars: OS,PYTHON + name: codecov-umbrella + fail_ci_if_error: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..fc4240b2 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,40 @@ +name: Notification Module Tests + +on: + push: + branches: [ main, develop, feature/* ] + pull_request: + branches: [ main, develop ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.9, 3.10, 3.11] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements.dev.txt + + - name: Run mypy type checking + run: mypy orm/notification.py + + - name: Run pytest for notification module + run: | + pytest tests/test_notification.py -v + + - name: Lint with ruff + run: | + ruff check orm/notification.py + ruff format --check orm/notification.py diff --git a/tests/test_notification.py b/tests/test_notification.py new file mode 100644 index 00000000..5e9d675f --- /dev/null +++ b/tests/test_notification.py @@ -0,0 +1,40 @@ +import pytest + +from orm.notification import ( + NotificationStatus, + NotificationKind, + NotificationEntity, + NotificationAction, +) + +def test_notification_status(): + """Тестирование перечисления статусов уведомлений.""" + assert NotificationStatus.UNREAD == NotificationStatus.from_string("UNREAD") + assert NotificationStatus.READ == NotificationStatus.from_string("READ") + + with pytest.raises(ValueError): + NotificationStatus.from_string("INVALID_STATUS") + +def test_notification_kind(): + """Тестирование перечисления типов уведомлений.""" + assert NotificationKind.COMMENT == NotificationKind.from_string("COMMENT") + assert NotificationKind.MENTION == NotificationKind.from_string("MENTION") + + with pytest.raises(ValueError): + NotificationKind.from_string("INVALID_KIND") + +def test_notification_entity(): + """Тестирование перечисления сущностей уведомлений.""" + assert NotificationEntity.TOPIC == NotificationEntity.from_string("topic") + assert NotificationEntity.SHOUT == NotificationEntity.from_string("shout") + + with pytest.raises(ValueError): + NotificationEntity.from_string("INVALID_ENTITY") + +def test_notification_action(): + """Тестирование перечисления действий уведомлений.""" + assert NotificationAction.CREATE == NotificationAction.from_string("create") + assert NotificationAction.UPDATE == NotificationAction.from_string("update") + + with pytest.raises(ValueError): + NotificationAction.from_string("INVALID_ACTION")