mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 16:51:11 +03:00
Merge pull request #2743 from ryanpetrello/survey_spec_stream
include survey_spec in activity stream Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
commit
932a1c6386
@ -3117,6 +3117,15 @@ class JobTemplateSerializer(JobTemplateMixin, UnifiedJobTemplateSerializer, JobO
|
||||
return summary_fields
|
||||
|
||||
|
||||
class JobTemplateWithSpecSerializer(JobTemplateSerializer):
|
||||
'''
|
||||
Used for activity stream entries.
|
||||
'''
|
||||
|
||||
class Meta:
|
||||
model = JobTemplate
|
||||
fields = ('*', 'survey_spec')
|
||||
|
||||
|
||||
class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
|
||||
|
||||
@ -3618,6 +3627,16 @@ class WorkflowJobTemplateSerializer(JobTemplateMixin, LabelsListMixin, UnifiedJo
|
||||
return vars_validate_or_raise(value)
|
||||
|
||||
|
||||
class WorkflowJobTemplateWithSpecSerializer(WorkflowJobTemplateSerializer):
|
||||
'''
|
||||
Used for activity stream entries.
|
||||
'''
|
||||
|
||||
class Meta:
|
||||
model = WorkflowJobTemplate
|
||||
fields = ('*', 'survey_spec')
|
||||
|
||||
|
||||
class WorkflowJobSerializer(LabelsListMixin, UnifiedJobSerializer):
|
||||
|
||||
class Meta:
|
||||
|
@ -396,7 +396,7 @@ model_serializer_mapping = {
|
||||
Credential: CredentialSerializer,
|
||||
Team: TeamSerializer,
|
||||
Project: ProjectSerializer,
|
||||
JobTemplate: JobTemplateSerializer,
|
||||
JobTemplate: JobTemplateWithSpecSerializer,
|
||||
Job: JobSerializer,
|
||||
AdHocCommand: AdHocCommandSerializer,
|
||||
NotificationTemplate: NotificationTemplateSerializer,
|
||||
@ -404,7 +404,7 @@ model_serializer_mapping = {
|
||||
CredentialType: CredentialTypeSerializer,
|
||||
Schedule: ScheduleSerializer,
|
||||
Label: LabelSerializer,
|
||||
WorkflowJobTemplate: WorkflowJobTemplateSerializer,
|
||||
WorkflowJobTemplate: WorkflowJobTemplateWithSpecSerializer,
|
||||
WorkflowJobTemplateNode: WorkflowJobTemplateNodeSerializer,
|
||||
WorkflowJob: WorkflowJobSerializer,
|
||||
OAuth2AccessToken: OAuth2TokenSerializer,
|
||||
|
@ -15,9 +15,9 @@ from awx.main.models import (
|
||||
)
|
||||
|
||||
# other AWX
|
||||
from awx.main.utils import model_to_dict
|
||||
from awx.main.utils import model_to_dict, model_instance_diff
|
||||
from awx.main.utils.common import get_allowed_fields
|
||||
from awx.api.serializers import InventorySourceSerializer
|
||||
from awx.main.signals import model_serializer_mapping
|
||||
|
||||
# Django
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
@ -26,11 +26,6 @@ from django.contrib.auth.models import AnonymousUser
|
||||
from crum import impersonate
|
||||
|
||||
|
||||
model_serializer_mapping = {
|
||||
InventorySource: InventorySourceSerializer
|
||||
}
|
||||
|
||||
|
||||
class TestImplicitRolesOmitted:
|
||||
'''
|
||||
Test that there is exactly 1 "create" entry in the activity stream for
|
||||
@ -220,8 +215,24 @@ def test_modified_not_allowed_field(somecloud_type):
|
||||
activity_stream_registrar, but did not add its serializer to
|
||||
the model->serializer mapping.
|
||||
'''
|
||||
from awx.main.signals import model_serializer_mapping
|
||||
from awx.main.registrar import activity_stream_registrar
|
||||
|
||||
for Model in activity_stream_registrar.models:
|
||||
assert 'modified' not in get_allowed_fields(Model(), model_serializer_mapping), Model
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_survey_spec_create_entry(job_template, survey_spec_factory):
|
||||
start_count = job_template.activitystream_set.count()
|
||||
job_template.survey_spec = survey_spec_factory('foo')
|
||||
job_template.save()
|
||||
assert job_template.activitystream_set.count() == start_count + 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_survey_create_diff(job_template, survey_spec_factory):
|
||||
old = JobTemplate.objects.get(pk=job_template.pk)
|
||||
job_template.survey_spec = survey_spec_factory('foo')
|
||||
before, after = model_instance_diff(old, job_template, model_serializer_mapping)['survey_spec']
|
||||
assert before == '{}'
|
||||
assert json.loads(after) == survey_spec_factory('foo')
|
||||
|
Loading…
Reference in New Issue
Block a user