Пример #1
0
 def setUp(self) -> None:
     super().setUp()
     self.user_id = 7826715669
     self.action = MotionUpdateMetadata(
         PermissionTestAdapter(superuser=self.user_id),
         DatabaseTestAdapter(old_style_testing=True),
     )
Пример #2
0
class MotionUpdateMetadataActionUnitTester(BaseMotionUpdateMetadataActionTester
                                           ):
    def setUp(self) -> None:
        super().setUp()
        user_id = 7826715669
        self.action = MotionUpdateMetadata(
            PermissionTestAdapter(superuser=user_id),
            DatabaseTestAdapter(old_style_testing=True),
        )
        self.action.user_id = user_id

    def test_validation_correct_1(self) -> None:
        self.action.validate(self.valid_payload_1)

    def test_validation_correct_2(self) -> None:
        self.action.validate(self.valid_payload_2)

    def test_prepare_dataset_1(self) -> None:
        dataset = self.action.prepare_dataset(self.valid_payload_1)
        instance = deepcopy(self.valid_payload_1[0])
        instance["last_modified"] = round(time.time())
        expected = [{
            "instance": instance,
            "relations": {
                get_fqfield("motion_category/8734727380/motion_ids"): {
                    "type": "remove",
                    "value": [],
                },
                get_fqfield("motion_block/4116433002/motion_ids"): {
                    "type": "remove",
                    "value": [],
                },
                get_fqfield("motion_block/4740630442/motion_ids"): {
                    "type": "add",
                    "value": [2995885358],
                },
            },
        }]
        self.assertEqual(dataset["data"], expected)

    def test_prepare_dataset_2(self) -> None:
        dataset = self.action.prepare_dataset(self.valid_payload_2)
        instance = deepcopy(self.valid_payload_2[0])
        instance["last_modified"] = round(time.time())
        expected = [{
            "instance": instance,
            "relations": {
                get_fqfield("user/7268025091/supported_motion_5562405520_ids"):
                {
                    "type": "add",
                    "value": [2995885358],
                },
            },
        }]
        self.assertEqual(dataset["data"], expected)
Пример #3
0
class MotionUpdateMetadataActionPerformTester(
        BaseMotionUpdateMetadataActionTester):
    def setUp(self) -> None:
        super().setUp()
        self.user_id = 7826715669
        self.action = MotionUpdateMetadata(
            PermissionTestAdapter(superuser=self.user_id),
            DatabaseTestAdapter(old_style_testing=True),
        )

    def test_perform_correct_1(self) -> None:
        write_request_elements = self.action.perform(self.valid_payload_1,
                                                     user_id=self.user_id)
        expected = [
            {
                "events": [
                    {
                        "type": "update",
                        "fqid": get_fqid("motion/2995885358"),
                        "fields": {
                            "last_modified": round(time.time()),
                            "category_id": None,
                            "block_id": 4740630442,
                        },
                    },
                    {
                        "type": "update",
                        "fqid": get_fqid("motion_block/4116433002"),
                        "fields": {
                            "motion_ids": []
                        },
                    },
                    {
                        "type": "update",
                        "fqid": get_fqid("motion_block/4740630442"),
                        "fields": {
                            "motion_ids": [2995885358]
                        },
                    },
                    {
                        "type": "update",
                        "fqid": get_fqid("motion_category/8734727380"),
                        "fields": {
                            "motion_ids": []
                        },
                    },
                ],
                "information": {
                    get_fqid("motion/2995885358"): ["Object updated"],
                    get_fqid("motion_block/4116433002"):
                    ["Object attachment to motion reset"],
                    get_fqid("motion_block/4740630442"):
                    ["Object attached to motion"],
                    get_fqid("motion_category/8734727380"):
                    ["Object attachment to motion reset"],
                },
                "user_id":
                self.user_id,
            },
        ]
        self.assertEqual(
            list(write_request_elements),
            expected,
        )

    def test_perform_correct_2(self) -> None:
        write_request_elements = self.action.perform(self.valid_payload_2,
                                                     user_id=self.user_id)
        expected = [{
            "events": [
                {
                    "type": "update",
                    "fqid": get_fqid("motion/2995885358"),
                    "fields": {
                        "last_modified": round(time.time()),
                        "supporter_ids": [7268025091],
                    },
                },
                {
                    "type": "update",
                    "fqid": get_fqid("user/7268025091"),
                    "fields": {
                        "supported_motion_5562405520_ids": [2995885358]
                    },
                },
            ],
            "information": {
                get_fqid("motion/2995885358"): ["Object updated"],
                get_fqid("user/7268025091"): ["Object attached to motion"],
            },
            "user_id":
            self.user_id,
        }]
        self.assertEqual(
            list(write_request_elements),
            expected,
        )

    def test_perform_no_permission_1(self) -> None:
        with self.assertRaises(PermissionDenied) as context_manager:
            self.action.perform(self.valid_payload_1, user_id=4796568680)
        self.assertEqual(
            context_manager.exception.message,
            "You are not allowed to perform action motion.update_metadata.",
        )