diff --git a/core/migrations/0006_notificationconfig_and_more.py b/core/migrations/0006_notificationconfig_and_more.py index d72a5f0..86a1412 100644 --- a/core/migrations/0006_notificationconfig_and_more.py +++ b/core/migrations/0006_notificationconfig_and_more.py @@ -1,15 +1,19 @@ # Generated by Django 4.2.3 on 2023-09-14 12:39 -import core.models import django.contrib.postgres.fields -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + +import core.models class Migration(migrations.Migration): dependencies = [ - ("core", "0005_rename_message_ts_notificationstatus_message_timestamp"), + ( + "core", + "0005_rename_message_ts_notificationstatus_message_timestamp", + ), ] operations = [ @@ -58,7 +62,8 @@ class Migration(migrations.Migration): model_name="notificationstatus", name="status", field=models.CharField( - choices=[("success", "Success"), ("error", "Error")], max_length=7 + choices=[("success", "Success"), ("error", "Error")], + max_length=7, ), ), migrations.AlterField( diff --git a/core/models.py b/core/models.py index a6b98a5..54f7fc9 100644 --- a/core/models.py +++ b/core/models.py @@ -2,10 +2,12 @@ from django.db import models from django.utils import timezone + class DateTimeWithoutTZField(models.DateTimeField): def db_type(self, connection): return "timestamp" + class NotificationFilters(models.TextChoices): AUTHOR = "author" BRANCH = "branch" diff --git a/core/slack_datastores.py b/core/slack_datastores.py index 337a18e..c201ffe 100644 --- a/core/slack_datastores.py +++ b/core/slack_datastores.py @@ -51,11 +51,11 @@ def save(self, installation: Installation): if is_naive(user_token_expires_at): user_token_expires_at = make_aware(user_token_expires_at) - # can have one installation per team id + # can have one installation per team id slack_installation = SlackInstallation.objects.filter( team_id=installation.team_id, ).first() - + if slack_installation is None: slack_installation = SlackInstallation() @@ -94,15 +94,14 @@ def save(self, installation: Installation): ) slack_installation.token_type = installation.token_type slack_installation.installed_at = installed_at - + try: slack_installation.save() self.save_bot(installation.to_bot()) - + except Exception as e: self._logger.error(f"Error saving installation: {e}") - def save_bot(self, bot: Bot): installed_at = bot.installed_at bot_token_expires_at = bot.bot_token_expires_at diff --git a/core/tests/test_resolvers.py b/core/tests/test_resolvers.py index 1269d66..0d22005 100644 --- a/core/tests/test_resolvers.py +++ b/core/tests/test_resolvers.py @@ -633,7 +633,7 @@ def test_file_coverage_report_resolver_count_is_zero( def test_help_resolver(): - client=MagicMock() + client = MagicMock() resolve_help( channel_id="random_channel_id", diff --git a/service_auth/actions.py b/service_auth/actions.py index f9ca0e1..2814426 100644 --- a/service_auth/actions.py +++ b/service_auth/actions.py @@ -107,7 +107,9 @@ def view_login_modal( slack_user_id = command["user_id"] channel_id = command["channel_id"] slack_state_jwt = jwt.encode( - {"user_id": slack_user_id, "channel_id": channel_id}, USER_ID_SECRET, algorithm="HS256" + {"user_id": slack_user_id, "channel_id": channel_id}, + USER_ID_SECRET, + algorithm="HS256", ) # create slack user diff --git a/service_auth/tests/conftest.py b/service_auth/tests/conftest.py index 2161834..0a6719f 100644 --- a/service_auth/tests/conftest.py +++ b/service_auth/tests/conftest.py @@ -8,4 +8,4 @@ os.environ["SLACK_CLIENT_ID"] = "292929292929.292929292929" os.environ["SLACK_CLIENT_SECRET"] = "random_client_secret" os.environ["SLACK_APP_ID"] = "292929292929" -os.environ["CODECOV_API"] = "https://codecov.io/api" \ No newline at end of file +os.environ["CODECOV_API"] = "https://codecov.io/api" diff --git a/service_auth/tests/test_views.py b/service_auth/tests/test_views.py index c99f966..746653c 100644 --- a/service_auth/tests/test_views.py +++ b/service_auth/tests/test_views.py @@ -105,7 +105,9 @@ def test_missing_slack_user(self, mock_post, mock_get): ) assert response.status_code == 404 - assert response.json() == {"detail": "Slack user not found random_test_id"} + assert response.json() == { + "detail": "Slack user not found random_test_id" + } @patch("requests.get") @patch("requests.post") diff --git a/service_auth/views.py b/service_auth/views.py index caa2309..b42960e 100644 --- a/service_auth/views.py +++ b/service_auth/views.py @@ -29,13 +29,13 @@ def get(self, request, format=None): state = request.GET.get("state") validate_gh_call_params(code, state) - user_id = jwt.decode( - state, USER_ID_SECRET, algorithms=["HS256"] - )["user_id"] + user_id = jwt.decode(state, USER_ID_SECRET, algorithms=["HS256"])[ + "user_id" + ] - channel_id = jwt.decode( - state, USER_ID_SECRET, algorithms=["HS256"] - )["channel_id"] + channel_id = jwt.decode(state, USER_ID_SECRET, algorithms=["HS256"])[ + "channel_id" + ] # Exchange the authorization code for an access token headers = {"Accept": "application/json"}