Beispiel #1
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"))
Beispiel #2
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 setUp(self):
     self.repository = ArchiveRepository("http://dynamodb-local:8000/",
                                         "us-west-2",
                                         "HadithCorrectionsArchive")
class TestArchiveRepository(unittest.TestCase):
    def setUp(self):
        self.repository = ArchiveRepository("http://*****:*****@email.com",
            "*****@*****.**",
            "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,
        }

    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 test_read(self):
        assert len(self.repository.read()) == 1

    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