예제 #1
0
 def setUp(self) -> None:
     super().setUp()
     self.user_id = 5968705978
     self.action = TopicCreate(
         PermissionTestAdapter(superuser=self.user_id),
         DatabaseTestAdapter(old_style_testing=True),
     )
예제 #2
0
class TopicCreateActionUnitTester(BaseTopicCreateActionTester):
    def setUp(self) -> None:
        super().setUp()
        user_id = 5968705978
        self.action = TopicCreate(
            PermissionTestAdapter(superuser=user_id),
            DatabaseTestAdapter(old_style_testing=True),
        )
        self.action.user_id = user_id

    def test_validation_empty(self) -> None:
        payload: ActionPayload = []
        with self.assertRaises(ActionException):
            self.action.validate(payload)

    def test_validation_empty_2(self) -> None:
        payload: ActionPayload = [{}]
        with self.assertRaises(ActionException):
            self.action.validate(payload)

    def test_validation_fuzzy(self) -> None:
        payload = [{"wrong_field": "text_Kiofee1ieV"}]
        with self.assertRaises(ActionException):
            self.action.validate(payload)

    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_validation_correct_3(self) -> None:
        self.action.validate(self.valid_payload_3)

    def test_validation_invalid_1(self) -> None:
        invalid_payload = [{
            "meeting_id":
            3611987967,
            "title":
            "title_yae0Ohph4e",
            "unknown_property_aiseCah6ah":
            "unknown_property_iagh4paoWi",
        }]
        with self.assertRaises(ActionException):
            self.action.validate(invalid_payload)

    def test_prepare_dataset_1(self) -> None:
        dataset = self.action.prepare_dataset(self.valid_payload_1)
        result = dataset["data"]
        expected = [{
            "instance": self.valid_payload_1[0],
            "new_id": 42,
            "relations": {
                get_fqfield("meeting/2393342057/topic_ids"): {
                    "type": "add",
                    "value": [42],
                },
            },
        }]
        self.assertEqual(result, expected)

    def test_prepare_dataset_2(self) -> None:
        dataset = self.action.prepare_dataset(self.valid_payload_2)
        self.assertEqual(
            dataset["data"],
            [{
                "instance": self.valid_payload_2[0],
                "new_id": 42,
                "relations": {
                    get_fqfield("meeting/4002059810/topic_ids"): {
                        "type": "add",
                        "value": [42],
                    },
                    get_fqfield(f"mediafile/{self.attachments[0]}/attachment_ids"):
                    {
                        "type":
                        "add",
                        "value": [
                            get_fqid("topic/6259289755"),
                            get_fqid("topic/42"),
                        ],
                    },
                    get_fqfield(f"mediafile/{self.attachments[1]}/attachment_ids"):
                    {
                        "type": "add",
                        "value": [get_fqid("topic/42")]
                    },
                },
            }],
        )

    def test_prepare_dataset_3(self) -> None:
        dataset = self.action.prepare_dataset(self.valid_payload_3)
        self.assertEqual(
            dataset["data"],
            [{
                "instance": self.valid_payload_3[0],
                "new_id": 42,
                "relations": {
                    get_fqfield("meeting/3611987967/topic_ids"): {
                        "type": "add",
                        "value": [6375863023, 6259289755, 42],
                    },
                },
            }],
        )
예제 #3
0
class TopicCreateActionPerformTester(BaseTopicCreateActionTester):
    def setUp(self) -> None:
        super().setUp()
        self.user_id = 5968705978
        self.action = TopicCreate(
            PermissionTestAdapter(superuser=self.user_id),
            DatabaseTestAdapter(old_style_testing=True),
        )

    def test_perform_empty(self) -> None:
        payload: ActionPayload = []
        with self.assertRaises(ActionException):
            self.action.perform(payload, user_id=self.user_id)

    def test_perform_empty_2(self) -> None:
        payload: ActionPayload = [{}]
        with self.assertRaises(ActionException):
            self.action.perform(payload, user_id=self.user_id)

    def test_perform_fuzzy(self) -> None:
        payload = [{"wrong_field": "text_Ieh5aiwora"}]
        with self.assertRaises(ActionException):
            self.action.perform(payload, user_id=self.user_id)

    def test_perform_correct_1(self) -> None:
        write_request_elements = self.action.perform(self.valid_payload_1,
                                                     user_id=self.user_id)
        result = list(write_request_elements)
        self.assertTrue(len(result) == 2)

    def test_perform_correct_2(self) -> None:
        write_request_elements = self.action.perform(self.valid_payload_2,
                                                     user_id=self.user_id)
        result = list(write_request_elements)
        self.assertTrue(len(result) == 2)

    def test_perform_correct_3(self) -> None:
        write_request_elements = self.action.perform(self.valid_payload_3,
                                                     user_id=self.user_id)
        result = list(write_request_elements)
        self.assertTrue(len(result) == 2)

    def test_perform_no_permission_1(self) -> None:
        with self.assertRaises(PermissionDenied):
            self.action.perform(self.valid_payload_1, user_id=4796568680)

    def test_perform_no_permission_2(self) -> None:
        with self.assertRaises(PermissionDenied):
            self.action.perform(self.valid_payload_2, user_id=4796568680)

    def test_perform_no_permission_3(self) -> None:
        with self.assertRaises(PermissionDenied):
            self.action.perform(self.valid_payload_3, user_id=4796568680)