Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xrecipe task to set creator to changelog fixes #2658 #2680

Merged
merged 2 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/experimenter/experiments/changelog_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
from experimenter.experiments.serializers.entities import ChangeLogSerializer


def update_experiment_with_change_log(old_experiment, changed_data):
def update_experiment_with_change_log(old_experiment, changed_data, user_email):

old_serialized_exp = ChangeLogSerializer(old_experiment).data
Experiment.objects.filter(id=old_experiment.id).update(**changed_data)
new_experiment = Experiment.objects.get(slug=old_experiment.slug)
new_serialized_exp = ChangeLogSerializer(new_experiment).data
normandy_user = settings.NORMANDY_DEFAULT_CHANGELOG_USER

if not user_email:
user_email = settings.NORMANDY_DEFAULT_CHANGELOG_USER
default_user, _ = get_user_model().objects.get_or_create(
email=normandy_user, username=normandy_user
email=user_email, username=user_email
)

generate_change_log(
Expand Down
13 changes: 9 additions & 4 deletions app/experimenter/experiments/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,20 @@ def update_recipe_ids_to_experiments():
recipe_data = normandy.get_recipe_list(experiment.slug)

if len(recipe_data):
recipe_ids = [r["id"] for r in recipe_data]
# sort to get oldest id to be primary
recipe_ids.sort()
sorted_recipe_data = sorted(recipe_data, key=lambda x: x.get("id"))
recipe_ids = [r["id"] for r in sorted_recipe_data]
changed_data = {
"normandy_id": recipe_ids[0],
"other_normandy_ids": recipe_ids[1:],
"status": Experiment.STATUS_ACCEPTED,
}
update_experiment_with_change_log(experiment, changed_data)
user_email = (
sorted_recipe_data[0]
.get("approved_revision", {})
.get("creator", {})
.get("email", "")
)
update_experiment_with_change_log(experiment, changed_data, user_email)

except (IntegrityError, KeyError, normandy.NormandyError) as e:
logger.info(f"Failed to update Experiment {experiment}: {e}")
Expand Down
12 changes: 10 additions & 2 deletions app/experimenter/experiments/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,13 @@ def test_update_ready_to_ship_experiment(self):
experiment = ExperimentFactory.create_with_status(
target_status=Experiment.STATUS_SHIP
)
mock_response_data = {"results": [{"id": 1}, {"id": 10}, {"id": 100}]}
mock_response_data = {
"results": [
{"id": 1, "approved_revision": {"creator": {"email": "dev@example.com"}}},
{"id": 10},
{"id": 100},
]
}
mock_response = mock.Mock()
mock_response.json = mock.Mock()
mock_response.json.return_value = mock_response_data
Expand All @@ -273,7 +279,9 @@ def test_update_ready_to_ship_experiment(self):

self.assertTrue(
experiment.changes.filter(
old_status=Experiment.STATUS_SHIP, new_status=Experiment.STATUS_ACCEPTED,
changed_by__email="dev@example.com",
old_status=Experiment.STATUS_SHIP,
new_status=Experiment.STATUS_ACCEPTED,
).exists()
)

Expand Down