Esempio n. 1
0
class MotionUpdateMetadataActionUnitTester(BaseMotionUpdateMetadataActionTester
                                           ):
    def setUp(self) -> None:
        super().setUp()
        user_id = 7826715669
        self.action = MotionUpdateMetadata(
            "motion.update_metadate",
            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)
class MotionUpdateMetadataActionUnitTester(BaseMotionUpdateMetadataActionTester
                                           ):
    def setUp(self) -> None:
        super().setUp()
        self.action = MotionUpdateMetadata(PermissionTestAdapter(),
                                           DatabaseTestAdapter())
        self.action.user_id = (
            7826715669  # This user has perm MOTION_CAN_MANAGE for some meetings.
        )

    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)
        self.assertEqual(dataset["position"], 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)
        self.assertEqual(dataset["position"], 1)
        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)