Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyorlando committed Nov 2, 2024
1 parent fd18b66 commit 07ebce9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion engine/common/api_helpers/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_queryset(self):

def to_internal_value(self, slack_id: str):
try:
return self.get_queryset().get(slack_id=slack_id.upper())
return self.get_queryset().get(slack_id__iexact=slack_id)
except ObjectDoesNotExist:
raise ValidationError("Slack channel does not exist")
except (TypeError, ValueError, AttributeError):
Expand Down
18 changes: 11 additions & 7 deletions engine/common/tests/test_custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def test_org_does_not_have_slack_connected(
with pytest.raises(BadRequest) as excinfo:
serializer.is_valid(raise_exception=True)

assert "Slack isn't connected to this workspace" in str(excinfo.value)
assert excinfo.value.detail == "Slack isn't connected to this workspace"
assert excinfo.value.status_code == 400

@pytest.mark.django_db
def test_org_channel_doesnt_belong_to_org(
Expand Down Expand Up @@ -158,7 +159,7 @@ def test_org_channel_doesnt_belong_to_org(
with pytest.raises(serializers.ValidationError) as excinfo:
serializer.is_valid(raise_exception=True)

assert "Slack channel does not exist" in str(excinfo.value)
assert excinfo.value.detail == {"slack_channel_id": ["Slack channel does not exist"]}

@pytest.mark.django_db
def test_invalid_slack_channel(
Expand All @@ -182,7 +183,7 @@ def test_invalid_slack_channel(
with pytest.raises(serializers.ValidationError) as excinfo:
serializer.is_valid(raise_exception=True)

assert "Invalid Slack channel" in str(excinfo.value)
assert excinfo.value.detail == {"slack_channel_id": ["Slack channel does not exist"]}

@pytest.mark.django_db
def test_valid(
Expand All @@ -198,10 +199,13 @@ def test_valid(
organization = make_organization(slack_team_identity=slack_team_identity)
user = make_user_for_organization(organization)

serializer = self.MySerializer(
data={"slack_channel_id": slack_channel_id},
context={"request": self.MockRequest(user)},
)
context = {"request": self.MockRequest(user)}

serializer = self.MySerializer(data={"slack_channel_id": slack_channel_id}, context=context)
serializer.is_valid(raise_exception=True)
assert serializer.validated_data["slack_channel_id"] == slack_channel

# case insensitive
serializer = self.MySerializer(data={"slack_channel_id": slack_channel_id.lower()}, context=context)
serializer.is_valid(raise_exception=True)
assert serializer.validated_data["slack_channel_id"] == slack_channel

0 comments on commit 07ebce9

Please sign in to comment.