def test_serialization(self):
        now = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
        item = ArchiveItem(
            "global",
            "1",
            1,
            "hadithText",
            "Content",
            "comment",
            "*****@*****.**",
            "*****@*****.**",
            "corrected value",
            False,
            now,
        )

        assert item.serialize()
        assert item.serialize() == {
            "queue": "global",
            "id": "1",
            "urn": 1,
            "attr": "hadithText",
            "val": "Content",
            "comment": "comment",
            "submittedBy": "*****@*****.**",
            "modifiedBy": "*****@*****.**",
            "modifiedOn": now,
            "correctedVal": "corrected value",
            "approved": False,
        }
Exemplo n.º 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"))
Exemplo n.º 3
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'))
    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
    def write(self, item: ArchiveItem) -> None:
        """
        This will write an item into the archive table of dynamodb

        item: Dict
            item to be put into the archive
        """
        self.table.put_item(Item=item.serialize())
    def test_write(self):
        self.repository.write(
            ArchiveItem(
                "queue",
                "1",
                1,
                "hadithText",
                "val",
                "comment",
                "*****@*****.**",
                "guest",
                "ok",
                "corrected_val",
                False,
            ))

        assert len(self.repository.read(2)) == 2
    def test_write(self):
        self.repository.write(
            ArchiveItem("queue", "id", "urn", "attr", "val", "comment",
                        "*****@*****.**", "guest", "ok", "corrected_val", False))

        assert len(self.repository.read(2)) == 2