def test_activity_published_article(self, mock_sqs_message, mock_sqs_connect, mock_set_monitor_property, mock_emit_monitor_event): directory = TempDirectory() mock_sqs_connect.return_value = FakeSQSConn(directory) mock_sqs_message.return_value = FakeSQSMessage(directory) data = test_data.PostEIFBridge_data(True, u'2012-12-13T00:00:00Z') #When success = self.activity_PostEIFBridge.do_activity(data) fake_sqs_queue = FakeSQSQueue(directory) data_written_in_test_queue = fake_sqs_queue.read(test_data.PostEIFBridge_test_dir) #Then self.assertEqual(True, success) self.assertEqual(json.dumps(test_data.PostEIFBridge_message), data_written_in_test_queue) mock_set_monitor_property.assert_has_calls( [call(settings_mock, data["article_id"], "path", data['article_path'], "text", version="1") ,call(settings_mock, data["article_id"], "publication-status", "published", "text", version="1")]) mock_emit_monitor_event.assert_called_with(settings_mock, data["article_id"], data["version"], data["run"], "Post EIF Bridge", "end", "Finished Post EIF Bridge " + data["article_id"])
def test_activity(self, fake_session_mock, fake_s3_mock, fake_key_mock, mock_sqs_message, mock_sqs_connect): directory = TempDirectory() for testdata in self.do_activity_passes: fake_session_mock.return_value = FakeSession( test_data.PreparePost_session_example(testdata["update_date"])) mock_sqs_connect.return_value = FakeSQSConn(directory) mock_sqs_message.return_value = FakeSQSMessage(directory) fake_s3_mock.return_value = FakeS3Connection() self.activity_PreparePostEIF.logger = mock.MagicMock() self.activity_PreparePostEIF.set_monitor_property = mock.MagicMock( ) self.activity_PreparePostEIF.emit_monitor_event = mock.MagicMock() success = self.activity_PreparePostEIF.do_activity( test_data.PreparePostEIF_data) fake_sqs_queue = FakeSQSQueue(directory) data_written_in_test_queue = fake_sqs_queue.read( test_data.PreparePostEIF_test_dir) self.assertEqual(True, success) self.assertEqual(json.dumps(testdata["message"]), data_written_in_test_queue) output_json = json.loads( directory.read(test_data.PreparePostEIF_test_dir)) expected = testdata["expected"] self.assertDictEqual(output_json, expected)
def test_activity(self, fake_session_mock, fake_s3_mock, fake_key_mock, mock_sqs_message, mock_sqs_connect): directory = TempDirectory() for testdata in self.do_activity_passes: fake_session_mock.return_value = FakeSession(test_data.PreparePost_session_example( testdata["update_date"])) mock_sqs_connect.return_value = FakeSQSConn(directory) mock_sqs_message.return_value = FakeSQSMessage(directory) fake_s3_mock.return_value = FakeS3Connection() self.activity_PreparePostEIF.logger = mock.MagicMock() self.activity_PreparePostEIF.set_monitor_property = mock.MagicMock() self.activity_PreparePostEIF.emit_monitor_event = mock.MagicMock() success = self.activity_PreparePostEIF.do_activity(test_data.PreparePostEIF_data) fake_sqs_queue = FakeSQSQueue(directory) data_written_in_test_queue = fake_sqs_queue.read(test_data.PreparePostEIF_test_dir) self.assertEqual(True, success) self.assertEqual(json.dumps(testdata["message"]), data_written_in_test_queue) output_json = json.loads(directory.read(test_data.PreparePostEIF_test_dir)) expected = testdata["expected"] self.assertDictEqual(output_json, expected)
def test_activity_published_article_no_update_date(self, mock_sqs_message, mock_sqs_connect): directory = TempDirectory() mock_sqs_connect.return_value = FakeSQSConn(directory) mock_sqs_message.return_value = FakeSQSMessage(directory) self.activity_PostEIFBridge.set_monitor_property = mock.MagicMock() self.activity_PostEIFBridge.emit_monitor_event = mock.MagicMock() success = self.activity_PostEIFBridge.do_activity(test_data.PostEIFBridge_data(True, None)) fake_sqs_queue = FakeSQSQueue(directory) data_written_in_test_queue = fake_sqs_queue.read(test_data.PostEIFBridge_test_dir) self.assertEqual(True, success) self.assertEqual(json.dumps(test_data.PostEIFBridge_message_no_update_date), data_written_in_test_queue)
def test_activity_published_article_no_update_date(self, mock_sqs_message, mock_sqs_connect): directory = TempDirectory() mock_sqs_connect.return_value = FakeSQSConn(directory) mock_sqs_message.return_value = FakeSQSMessage(directory) self.activity_PostEIFBridge.set_monitor_property = mock.MagicMock() self.activity_PostEIFBridge.emit_monitor_event = mock.MagicMock() success = self.activity_PostEIFBridge.do_activity( test_data.PostEIFBridge_data(True, None)) fake_sqs_queue = FakeSQSQueue(directory) data_written_in_test_queue = fake_sqs_queue.read( test_data.PostEIFBridge_test_dir) self.assertEqual(True, success) self.assertEqual( json.dumps(test_data.PostEIFBridge_message_no_update_date), data_written_in_test_queue)
def test_activity(self, status_code, response_update_date, update_json, expected_update_date, mock_sqs_message, mock_sqs_connect, mock_requests_put): directory = TempDirectory() mock_sqs_connect.return_value = FakeSQSConn(directory) mock_sqs_message.return_value = FakeSQSMessage(directory) mock_requests_put.return_value = classes_mock.FakeResponse(status_code, update_json) success = self.activity_ApprovePublication.do_activity( activity_data.ApprovePublication_data(response_update_date)) fake_sqs_queue = FakeSQSQueue(directory) data_written_in_test_queue = fake_sqs_queue.read(activity_data.ApprovePublication_test_dir) self.assertEqual(True, success) output_json = json.loads(directory.read(activity_data.ApprovePublication_test_dir)) expected = activity_data.ApprovePublication_json_output_return_example(expected_update_date) self.assertDictEqual(output_json, expected)
def test_activity_published_article(self, mock_sqs_message, mock_sqs_connect, mock_set_monitor_property, mock_emit_monitor_event): directory = TempDirectory() mock_sqs_connect.return_value = FakeSQSConn(directory) mock_sqs_message.return_value = FakeSQSMessage(directory) data = test_data.PostEIFBridge_data(True, u'2012-12-13T00:00:00Z') #When success = self.activity_PostEIFBridge.do_activity(data) fake_sqs_queue = FakeSQSQueue(directory) data_written_in_test_queue = fake_sqs_queue.read( test_data.PostEIFBridge_test_dir) #Then self.assertEqual(True, success) self.assertEqual(json.dumps(test_data.PostEIFBridge_message), data_written_in_test_queue) mock_set_monitor_property.assert_has_calls([ call(settings_mock, data["article_id"], "path", data['article_path'], "text", version="1"), call(settings_mock, data["article_id"], "publication-status", "published", "text", version="1") ]) mock_emit_monitor_event.assert_called_with( settings_mock, data["article_id"], data["version"], data["run"], "Post EIF Bridge", "end", "Finished Post EIF Bridge " + data["article_id"])