Пример #1
0
    def test_upload_feedback(client):
        # Given
        feedback = GCSFeedbackSubmitter(bucket_name="feedback")

        metadata = {
            "feedback_count": 1,
            "feedback_submission_date": "2021-03-23",
            "form_type": "H",
            "language_code": "cy",
            "region_code": "GB-ENG",
            "tx_id": "12345",
        }

        payload = {
            "feedback-type": "Feedback type",
            "feedback-text": "Feedback text",
        }

        payload.update(metadata)

        # When
        feedback_upload = feedback.upload(metadata, json_dumps(payload))

        # Then
        bucket = client.return_value.get_bucket.return_value
        blob = bucket.blob.return_value

        assert blob.metadata["feedback_count"] == 1
        assert blob.metadata["feedback_submission_date"] == "2021-03-23"
        assert blob.metadata["form_type"] == "H"
        assert blob.metadata["language_code"] == "cy"
        assert blob.metadata["tx_id"] == "12345"
        assert blob.metadata["region_code"] == "GB-ENG"

        blob_contents = blob.upload_from_string.call_args[0][0]

        assert (
            blob_contents ==
            b'{"feedback-type": "Feedback type", "feedback-text": "Feedback text", '
            b'"feedback_count": 1, "feedback_submission_date": "2021-03-23", '
            b'"form_type": "H", "language_code": "cy", "region_code": "GB-ENG", "tx_id": "12345"}'
        )
        assert feedback_upload is True
Пример #2
0
def setup_feedback(application):
    if application.config["EQ_FEEDBACK_BACKEND"] == "gcs":
        bucket_name = application.config.get("EQ_GCS_FEEDBACK_BUCKET_ID")

        if not bucket_name:
            raise Exception("Setting EQ_GCS_FEEDBACK_BUCKET_ID Missing")

        application.eq["feedback_submitter"] = GCSFeedbackSubmitter(
            bucket_name=bucket_name)

    elif application.config["EQ_FEEDBACK_BACKEND"] == "log":
        application.eq["feedback_submitter"] = LogFeedbackSubmitter()
    else:
        raise Exception("Unknown EQ_FEEDBACK_BACKEND")