import json import uuid from tests import BaseTestCase, FixtureLoader, mock, mock_for_user from unittest.mock import patch from models import models from tests.media_plan.fixtures.media_plan_review_fixture import fixture requesterMock = mock_for_user(3, "user-3@example.com", "sme-dna|9op0091d6cuhjp30fe6ffth34", name="User Admin") def mocked_email_send(*args, **kwargs): return [{"dev-marketing-user-1@example.com": uuid.uuid4(), "user-3@example.com": uuid.uuid4()}] @patch("auth.atlas.atlas_token_decoder.jwt.decode", mock.jwt_decode) class TestMediaPlanApproval(BaseTestCase): url = "/projects/{}/media-plans/{}/media-plan-review" def setUp(self): super().setUp() FixtureLoader(models=models).import_as_sql(fixture) @patch("notifications.notifications_center.NotificationsCenter.notify", new=mocked_email_send) @patch("auth.atlas.atlas_token_decoder.jwt.decode", requesterMock.jwt_decode) def make_approval_request(self, campaign_uuids, reviewer_ids): data = { "campaigns": [*campaign_uuids], "reviewers": [*reviewer_ids], } response = self.execute_post("/projects/500/media-plans/42/approval-request", data=json.dumps(data), headers=self.headers) self.assertEqual(response.status_code, 200) def test_get_media_plan_for_review(self): self.make_approval_request(["34ed4c22-e1f9-4184-a06d-f04cbdb97455"], [1]) response = self.execute_get(self.url.format(500, 42), headers=self.headers) data = response.json self.assertEqual(200, response.status_code) self.assertEqual(len(data), 1) self.assert_all() def test_doesnt_have_media_plan_for_review(self): response = self.execute_get(self.url.format(500, 42), headers=self.headers) data = response.json self.assertEqual(404, response.status_code) self.assertEqual(data['code'], 'not_found_campaigns_for_review') self.assert_all() def test_cant_review_campaign_out_of_requested_list(self): self.make_approval_request(["34ed4c22-e1f9-4184-a06d-f04cbdb97455"], [1]) self.make_approval_request(["34ed4c22-e1f9-4184-a06d-f04cbdb97411"], [3]) response = self.execute_get(self.url.format(500, 42), headers=self.headers) data = response.json self.assertEqual(200, response.status_code) self.assertEqual(len(data), 1) self.assert_all()