Skip to content

Commit

Permalink
fix: create event streams with different default channel names (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsong-rh authored Feb 15, 2024
1 parent 0ceb8d2 commit bb44026
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/aap_eda/api/serializers/event_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class EventStreamCreateSerializer(serializers.ModelSerializer):
user = serializers.HiddenField(default=serializers.CurrentUserDefault())
source_args = YAMLSerializerField()
channel_name = serializers.CharField(
default=_get_default_channel_name(),
default=_get_default_channel_name,
validators=[
RegexValidator(
regex=r"^\w+$",
Expand Down
37 changes: 37 additions & 0 deletions tests/integration/api/test_event_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,43 @@ def test_create_event_stream(
assert source["name"] == "test_event_stream"


@pytest.mark.django_db
def test_create_event_stream_with_different_default_channel_names(
client: APIClient,
default_de: models.DecisionEnvironment,
):
models.Rulebook.objects.create(
name=PG_NOTIFY_TEMPLATE_RULEBOOK_NAME,
rulesets=PG_NOTIFY_TEMPLATE_RULEBOOK_DATA,
)

args = {"limit": 5, "delay": 1}
source_type = "ansible.eda.range"
data_in_1 = {
"name": "test_event_stream",
"source_type": f"{source_type}",
"source_args": f"{args}",
"decision_environment_id": default_de.id,
}
response = client.post(f"{api_url_v1}/event-streams/", data=data_in_1)
assert response.status_code == status.HTTP_201_CREATED

data_in_2 = {
"name": "test_event_stream_2",
"source_type": f"{source_type}",
"source_args": f"{args}",
"decision_environment_id": default_de.id,
}
response = client.post(f"{api_url_v1}/event-streams/", data=data_in_2)

assert response.status_code == status.HTTP_201_CREATED
assert models.EventStream.objects.count() == 2
assert (
models.EventStream.objects.first().channel_name
!= models.EventStream.objects.last().channel_name
)


@pytest.mark.django_db
def test_create_event_stream_with_credential(
client: APIClient,
Expand Down

0 comments on commit bb44026

Please sign in to comment.