Beispiel #1
0
def archive_correction(queue_name: str,
                       correction_id: str,
                       version: int,
                       username: str,
                       moderator_comment: str = '',
                       corrected_val: str = None,
                       approved: bool = False):
    archive_repository = ArchiveRepository(
        app.config['DYNAMODB_ENDPOINT_URL'], app.config['REGION'],
        app.config['DYNAMODB_TABLE_ARCHIVE'])

    try:
        correction = read_correction(queue_name, correction_id, version)
        if not correction:
            return not_found(correction_id)

        entry = dict(
            **correction, **{
                'modifiedBy': username,
                'moderatorComment': moderator_comment,
                'correctedVal': corrected_val,
                'approved': approved
            })
        archive_repository.write(ArchiveItem.deserialize(entry))
        delete_correction(queue_name, correction_id, version)
    except ClientError as e:
        return jsonify(
            create_response_message(False, e.response['Error']['Message']))

    return jsonify(create_response_message(True, 'Success'))
Beispiel #2
0
def archive_correction(
    queue_name: str,
    correction_id: str,
    version: int,
    username: str,
    corrected_val: str = None,
    approved: bool = False,
):
    archive_repository = ArchiveRepository(
        app.config["DYNAMODB_ENDPOINT_URL"],
        app.config["REGION"],
        app.config["DYNAMODB_TABLE_ARCHIVE"],
    )

    try:
        correction = read_correction(queue_name, correction_id, version)
        if not correction:
            return not_found(correction_id)

        entry = dict(
            **correction,
            **{
                "modifiedBy": username,
                "correctedVal": corrected_val,
                "approved": approved,
            },
        )
        archive_repository.write(ArchiveItem.deserialize(entry))
        delete_correction(queue_name, correction_id, version)
    except ClientError as e:
        return jsonify(create_response_message(False, e.response["Error"]["Message"]))

    return jsonify(create_response_message(True, "Success"))
    def test_deserialization(self):
        now = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
        data = {
            "queue": "global",
            "id": "1",
            "urn": 1,
            "attr": "hadithText",
            "val": "Content",
            "comment": "comment",
            "submittedBy": "*****@*****.**",
            "modifiedBy": "*****@*****.**",
            "correctedVal": "corrected value",
            "approved": False,
            "modifiedOn": now,
        }

        item = ArchiveItem.deserialize(data)
        assert item.queue == "global"
        assert item.id == "1"
        assert item.urn == 1
        assert item.attr == "hadithText"
        assert item.val == "Content"
        assert item.comment == "comment"
        assert item.submitted_by == "*****@*****.**"
        assert item.modified_by == "*****@*****.**"
        assert item.corrected_val == "corrected value"
        assert item.is_approved == False
        assert item.modified_on == now