Skip to content

Commit

Permalink
Merge branch 'dev' into jorlando/cleanup_slack_channel_part2
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyorlando authored Dec 6, 2024
2 parents 9ba1dc9 + 3977c6e commit ab9b41e
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 64 deletions.
58 changes: 0 additions & 58 deletions .github/workflows/expensive-e2e-tests.yml

This file was deleted.

6 changes: 6 additions & 0 deletions engine/apps/api/tests/test_alert_receive_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,12 @@ def test_alert_receive_channel_test_connection(
data = {
"integration": integration_config.slug,
"team": None,
"create_default_webhooks": True,
"alert_group_labels": {
"inheritable": {},
"custom": [],
"template": None,
},
}

# no test connection setup
Expand Down
4 changes: 4 additions & 0 deletions engine/apps/api/views/alert_receive_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
AlertReceiveChannelSerializer,
AlertReceiveChannelUpdateSerializer,
FilterAlertReceiveChannelSerializer,
IntegrationAlertGroupLabelsSerializer,
)
from apps.api.serializers.alert_receive_channel_connection import (
AlertReceiveChannelConnectedChannelSerializer,
Expand Down Expand Up @@ -309,7 +310,10 @@ def _test_connection(self, request, pk=None):
# check we have all the required information
serializer.is_valid(raise_exception=True)
if instance is None:
# pop extra fields so they are not passed to AlertReceiveChannel(**serializer.validated_data)
serializer.validated_data.pop("create_default_webhooks", None)
IntegrationAlertGroupLabelsSerializer.pop_alert_group_labels(serializer.validated_data)

# create in-memory instance to test with the (possible) unsaved data
instance = AlertReceiveChannel(**serializer.validated_data)
else:
Expand Down
5 changes: 3 additions & 2 deletions engine/apps/email/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ def message(self) -> AnymailInboundMessage | None:

messages = [event.message for event in events if isinstance(event, AnymailInboundEvent)]
if messages:
logger.info(f"Received inbound email message from ESP: {esp}")
return messages[0]
message: AnymailInboundMessage = messages[0]
logger.info(f"Received inbound email message from ESP: {esp}, is HTML: {message.html is not None}")
return message

logger.error("Failed to parse inbound email message")
return None
Expand Down
41 changes: 41 additions & 0 deletions engine/apps/public_api/tests/test_escalation_chain.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import httpretty
import pytest
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APIClient

from apps.api import permissions
from apps.auth_token.tests.helpers import setup_service_account_api_mocks


@pytest.mark.django_db
def test_get_escalation_chains(make_organization_and_user_with_token):
Expand Down Expand Up @@ -54,6 +58,43 @@ def test_create_escalation_chain(make_organization_and_user_with_token):
assert response.data == expected_data


@pytest.mark.django_db
@httpretty.activate(verbose=True, allow_net_connect=False)
def test_create_escalation_chain_via_service_account(
make_organization,
make_service_account_for_organization,
make_token_for_service_account,
make_team,
):
organization = make_organization(grafana_url="http://grafana.test")
team = make_team(organization=organization)
service_account = make_service_account_for_organization(organization)
token_string = "glsa_token"
make_token_for_service_account(service_account, token_string)

perms = {
permissions.RBACPermission.Permissions.ESCALATION_CHAINS_WRITE.value: ["*"],
}
setup_service_account_api_mocks(organization.grafana_url, perms)

client = APIClient()
url = reverse("api-public:escalation_chains-list")
data = {"name": "test", "team_id": team.public_primary_key}
response = client.post(
url,
data=data,
format="json",
HTTP_AUTHORIZATION=f"{token_string}",
HTTP_X_GRAFANA_URL=organization.grafana_url,
)
if not organization.is_rbac_permissions_enabled:
assert response.status_code == status.HTTP_403_FORBIDDEN
else:
assert response.status_code == status.HTTP_201_CREATED
escalation_chain = organization.escalation_chains.get(name="test")
assert escalation_chain.team == team


@pytest.mark.django_db
def test_change_name(make_organization_and_user_with_token):
organization, user, token = make_organization_and_user_with_token()
Expand Down
4 changes: 4 additions & 0 deletions engine/apps/user_management/models/service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def pk(self):
def current_team(self):
return None

@property
def available_teams(self):
return self.organization.teams

@property
def organization_id(self):
return self.organization.id
Expand Down
2 changes: 1 addition & 1 deletion engine/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ charset-normalizer==3.3.2
# requests
distlib==0.3.8
# via virtualenv
django==4.2.16
django==4.2.17
# via
# -c requirements.txt
# django-stubs
Expand Down
2 changes: 1 addition & 1 deletion engine/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ babel==2.12.1
beautifulsoup4==4.12.2
celery[redis]==5.3.1
cryptography==43.0.1
django==4.2.16
django==4.2.17
django-add-default-value==0.10.0
django-anymail[amazon-ses]==12.0
django-cors-headers==3.7.0
Expand Down
2 changes: 1 addition & 1 deletion engine/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ deprecated==1.2.14
# opentelemetry-api
# opentelemetry-exporter-otlp-proto-grpc
# opentelemetry-semantic-conventions
django==4.2.16
django==4.2.17
# via
# -r requirements.in
# django-add-default-value
Expand Down
3 changes: 2 additions & 1 deletion engine/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ banned-modules =
# --allow-hosts = allow connections to the given hostnames/IPs.
# - localhost = our tests on CI use localhost as the host to connect to databases running locally in docker container
# - oncall-dev-mariadb = if you're running things locally, with a MariaDB instance running, there's a good chance the hostname will be this
addopts = --dist no --no-migrations --color=yes --showlocals --disable-socket --allow-hosts=localhost,oncall-dev-mariadb
# pytest-socket is disabled for now as it's making tests hang on CI
addopts = --dist no --no-migrations --color=yes --showlocals
# https://pytest-django.readthedocs.io/en/latest/faq.html#my-tests-are-not-being-found-why
python_files = tests.py test_*.py *_tests.py

Expand Down

0 comments on commit ab9b41e

Please sign in to comment.