示例#1
0
class TopicDeleteActionWSGITesterNoPermission(BaseTopicDeleteActionTester):
    def setUp(self) -> None:
        super().setUp()
        self.user_id_no_permission = 9707919439
        self.application = create_test_application(
            user_id=self.user_id_no_permission,
            view_name="ActionView",
            superuser=0)
        self.client = Client(self.application)

    def test_wsgi_request_no_permission_1(self) -> None:
        response = self.client.post(
            "/",
            json=[{
                "action": "topic.delete",
                "data": self.valid_payload_1
            }],
        )
        self.assert_status_code(response, 403)

    def test_wsgi_request_no_permission_2(self) -> None:
        response = self.client.post(
            "/",
            json=[{
                "action": "topic.delete",
                "data": self.valid_payload_2
            }],
        )
        self.assert_status_code(response, 403)
示例#2
0
 def setUp(self) -> None:
     super().setUp()
     self.user_id = 5968705978
     self.application = create_test_application(user_id=self.user_id,
                                                view_name="ActionView",
                                                superuser=self.user_id)
     self.client = Client(self.application)
 def test_wsgi_request_correct_1(self) -> None:
     expected_write_data = json.dumps({
         "events": [
             {
                 "type": "update",
                 "fqid": "meeting/7816466305",
                 "fields": {
                     "name": "name_GeiduDohx0"
                 },
             },
         ],
         "information": {
             "meeting/7816466305": ["Object updated"]
         },
         "user_id":
         self.user_id,
         # "locked_fields": {"meeting/7816466305": 1},
         "locked_fields": {},
     })
     client = Client(
         create_test_application(
             user_id=self.user_id,
             view_name="ActionView",
             superuser=self.user_id,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ))
     response = client.post(
         "/",
         json=[{
             "action": "meeting.update",
             "data": self.valid_payload_1
         }],
     )
     self.assert_status_code(response, 200)
 def test_wsgi_request_update(self) -> None:
     expected_write_data = json.dumps({
         "events": [
             {
                 "type": "update",
                 "fqid": "agenda_item/3393211712",
                 "fields": {
                     "duration": 3600
                 },
             },
         ],
         "information": {
             "agenda_item/3393211712": ["Object updated"]
         },
         "user_id":
         self.user_id,
         "locked_fields": {},
     })
     client = Client(
         create_test_application(
             user_id=self.user_id,
             view_name="ActionView",
             superuser=self.user_id,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ), )
     response = client.post(
         "/",
         json=[{
             "action": "agenda_item.update",
             "data": self.valid_payload_update
         }],
     )
     self.assert_status_code(response, 200)
     self.assertIn("Actions handled successfully", str(response.data))
示例#5
0
 def setUp(self) -> None:
     super().setUp()
     self.user_id_no_permission = 9707919439
     self.application = create_test_application(
         user_id=self.user_id_no_permission,
         view_name="ActionView",
         superuser=0)
     self.client = Client(self.application)
 def test_wsgi_request_create(self) -> None:
     expected_write_data = json.dumps({
         "events": [
             {
                 "type": "create",
                 "fqid": "agenda_item/42",
                 "fields": {
                     "meeting_id": 7816466305,
                     "content_object_id": "topic/1312354708",
                     "type": 1,
                     "weight": 0,
                 },
             },
             {
                 "type": "update",
                 "fqid": "topic/1312354708",
                 "fields": {
                     "agenda_item_id": 42
                 },
             },
             {
                 "type": "update",
                 "fqid": "meeting/7816466305",
                 "fields": {
                     "agenda_item_ids": [42]
                 },
             },
         ],
         "information": {
             "agenda_item/42": ["Object created"],
             "meeting/7816466305": ["Object attached to agenda item"],
             "topic/1312354708": ["Object attached to agenda item"],
         },
         "user_id":
         self.user_id,
         "locked_fields": {
             "meeting/7816466305": 1,
             "topic/1312354708": 1
         },
     })
     client = Client(
         create_test_application(
             user_id=self.user_id,
             view_name="ActionView",
             superuser=self.user_id,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ), )
     response = client.post(
         "/",
         json=[{
             "action": "agenda_item.create",
             "data": self.valid_payload_create
         }],
     )
     self.assert_status_code(response, 200)
     self.assertIn("Actions handled successfully", str(response.data))
示例#7
0
class TopicDeleteActionWSGITester(BaseTopicDeleteActionTester):
    def setUp(self) -> None:
        super().setUp()
        self.user_id = 5968705978
        self.application = create_test_application(user_id=self.user_id,
                                                   view_name="ActionView",
                                                   superuser=self.user_id)
        self.client = Client(self.application)

    def test_wsgi_request_empty(self) -> None:
        response = self.client.post("/",
                                    json=[{
                                        "action": "topic.delete",
                                        "data": [{}]
                                    }])
        self.assert_status_code(response, 400)
        self.assertIn(
            "data[0] must contain [\\'id\\'] properties",
            str(response.data),
        )

    def test_wsgi_request_fuzzy(self) -> None:
        response = self.client.post(
            "/",
            json=[{
                "action": "topic.delete",
                "data": [{
                    "wrong_field": "text_path4phahN"
                }],
            }],
        )
        self.assert_status_code(response, 400)
        self.assertIn(
            "data[0] must contain [\\'id\\'] properties",
            str(response.data),
        )

    def test_wsgi_request_correct_1(self) -> None:
        response = self.client.post(
            "/",
            json=[{
                "action": "topic.delete",
                "data": self.valid_payload_1
            }],
        )
        self.assert_status_code(response, 200)

    def test_wsgi_request_correct_2(self) -> None:
        response = self.client.post(
            "/",
            json=[{
                "action": "topic.delete",
                "data": self.valid_payload_2
            }],
        )
        self.assert_status_code(response, 200)
示例#8
0
 def test_wsgi_request_correct_1(self) -> None:
     client = Client(self.application)
     response = client.post(
         "/",
         json=[{
             "action": "motion.sort",
             "data": self.valid_payload_1
         }],
     )
     self.assert_status_code(response, 200)
 def test_wsgi_request_delete(self) -> None:
     expected_write_data = json.dumps({
         "events": [
             {
                 "type": "delete",
                 "fqid": "agenda_item/3393211712"
             },
             {
                 "type": "update",
                 "fqid": "topic/5756367535",
                 "fields": {
                     "agenda_item_id": None
                 },
             },
             {
                 "type": "update",
                 "fqid": "meeting/9079236097",
                 "fields": {
                     "agenda_item_ids": []
                 },
             },
         ],
         "information": {
             "agenda_item/3393211712": ["Object deleted"],
             "meeting/9079236097":
             ["Object attachment to agenda item reset"],
             "topic/5756367535": ["Object attachment to agenda item reset"],
         },
         "user_id":
         self.user_id,
         "locked_fields": {
             "agenda_item/3393211712": 1,
             "meeting/9079236097": 1,
             "topic/5756367535": 1,
         },
     })
     client = Client(
         create_test_application(
             user_id=self.user_id,
             view_name="ActionView",
             superuser=self.user_id,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ), )
     response = client.post(
         "/",
         json=[{
             "action": "agenda_item.delete",
             "data": self.valid_payload_delete
         }],
     )
     self.assert_status_code(response, 200)
     self.assertIn("Actions handled successfully", str(response.data))
示例#10
0
 def setUp(self) -> None:
     super().setUp()
     self.datastore_content = {
         get_fqfield("meeting/2393342057/topic_ids"): [],
         get_fqfield("meeting/4002059810/user_ids"): [5968705978],
         get_fqfield("mediafile/3549387598/meeting_ids"): [4002059810],
         get_fqfield("mediafile/3549387598/attachment_ids"):
         ["topic/6259289755"],
         get_fqfield("mediafile/7583920032/meeting_ids"): [4002059810],
         get_fqfield("meeting/3611987967/topic_ids"):
         [6375863023, 6259289755],
     }
     self.user_id = 5968705978
     self.application = create_test_application(user_id=self.user_id,
                                                view_name="ActionView",
                                                superuser=self.user_id)
     self.client = Client(self.application)
示例#11
0
 def test_wsgi_request_correct_1(self) -> None:
     expected_write_data = json.dumps({
         "events": [
             {
                 "type": "create",
                 "fqid": "committee/42",
                 "fields": {
                     "organisation_id": 1,
                     "name": "name_ieth5Ha1th"
                 },
             },
             {
                 "type": "update",
                 "fqid": "organisation/1",
                 "fields": {
                     "committee_ids": [5914213969, 42]
                 },
             },
         ],
         "information": {
             "committee/42": ["Object created"],
             "organisation/1": ["Object attached to committee"],
         },
         "user_id":
         self.user_id,
         "locked_fields": {
             "organisation/1": 1
         },
     })
     client = Client(
         create_test_application(
             user_id=self.user_id,
             view_name="ActionView",
             superuser=self.user_id,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ))
     response = client.post(
         "/",
         json=[{
             "action": "committee.create",
             "data": self.valid_payload_1
         }],
     )
     self.assert_status_code(response, 200)
示例#12
0
 def test_wsgi_request_correct_1(self) -> None:
     expected_write_data = json.dumps({
         "events": [
             {
                 "type": "create",
                 "fqid": "meeting/42",
                 "fields": {
                     "committee_id": 5914213969,
                     "name": "name_zusae6aD0a",
                 },
             },
             {
                 "type": "update",
                 "fqid": "committee/5914213969",
                 "fields": {
                     "meeting_ids": [7816466305, 3908439961, 42]
                 },
             },
         ],
         "information": {
             "meeting/42": ["Object created"],
             "committee/5914213969": ["Object attached to meeting"],
         },
         "user_id":
         self.user_id,
         "locked_fields": {
             "committee/5914213969": 1
         },
     })
     client = Client(
         create_test_application(
             user_id=self.user_id,
             view_name="ActionView",
             superuser=self.user_id,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ))
     response = client.post(
         "/",
         json=[{
             "action": "meeting.create",
             "data": self.valid_payload_1
         }],
     )
     self.assert_status_code(response, 200)
示例#13
0
 def test_wsgi_request_no_permission_2(self) -> None:
     expected_write_data = ""
     client = Client(
         create_test_application(
             user_id=self.user_id_no_permission,
             view_name="ActionView",
             superuser=0,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ))
     response = client.post(
         "/",
         json=[{
             "action": "meeting.delete",
             "data": self.invalid_payload_1
         }],
     )
     self.assert_status_code(response, 403)
示例#14
0
 def test_wsgi_request_empty(self) -> None:
     expected_write_data = ""
     client = Client(
         create_test_application(
             user_id=self.user_id,
             view_name="ActionView",
             superuser=self.user_id,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ))
     response = client.post("/",
                            json=[{
                                "action": "meeting.create",
                                "data": [{}]
                            }])
     self.assert_status_code(response, 400)
     self.assertIn(
         "data[0] must contain [\\'committee_id\\', \\'name\\'] properties",
         str(response.data),
     )
示例#15
0
 def test_wsgi_request_incorrect_2(self) -> None:
     expected_write_data = ""
     client = Client(
         create_test_application(
             user_id=self.user_id,
             view_name="ActionView",
             superuser=self.user_id,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ))
     response = client.post(
         "/",
         json=[{
             "action": "meeting.delete",
             "data": self.invalid_payload_1
         }],
     )
     self.assert_status_code(response, 400)
     self.assertIn(
         "You are not allowed to delete meeting 7816466305 as long as there are "
         "some required related objects.",
         str(response.data),
     )
示例#16
0
 def test_wsgi_request_fuzzy(self) -> None:
     expected_write_data = ""
     client = Client(
         create_test_application(
             user_id=self.user_id,
             view_name="ActionView",
             superuser=self.user_id,
             datastore_content=self.datastore_content,
             expected_write_data=expected_write_data,
         ))
     response = client.post(
         "/",
         json=[{
             "action": "committee.create",
             "data": [{
                 "wrong_field": "text_nobieH9ieS"
             }],
         }],
     )
     self.assert_status_code(response, 400)
     self.assertIn(
         "data[0] must contain [\\'organisation_id\\', \\'name\\'] properties",
         str(response.data),
     )
示例#17
0
class TopicCreateActionWSGITester(BaseTopicCreateActionTester):
    def setUp(self) -> None:
        super().setUp()
        self.datastore_content = {
            get_fqfield("meeting/2393342057/topic_ids"): [],
            get_fqfield("meeting/4002059810/user_ids"): [5968705978],
            get_fqfield("mediafile/3549387598/meeting_ids"): [4002059810],
            get_fqfield("mediafile/3549387598/attachment_ids"):
            ["topic/6259289755"],
            get_fqfield("mediafile/7583920032/meeting_ids"): [4002059810],
            get_fqfield("meeting/3611987967/topic_ids"):
            [6375863023, 6259289755],
        }
        self.user_id = 5968705978
        self.application = create_test_application(user_id=self.user_id,
                                                   view_name="ActionView",
                                                   superuser=self.user_id)
        self.client = Client(self.application)

    def test_wsgi_request_empty(self) -> None:
        response = self.client.post("/",
                                    json=[{
                                        "action": "topic.create",
                                        "data": [{}]
                                    }])
        self.assert_status_code(response, 400)
        self.assertIn(
            "data[0] must contain [\\'meeting_id\\', \\'title\\'] properties",
            str(response.data),
        )

    def test_wsgi_request_fuzzy(self) -> None:
        response = self.client.post(
            "/",
            json=[{
                "action": "topic.create",
                "data": [{
                    "wrong_field": "text_TaenePha0e"
                }],
            }],
        )
        self.assert_status_code(response, 400)
        self.assertIn(
            "data[0] must contain [\\'meeting_id\\', \\'title\\'] properties",
            str(response.data),
        )

    def test_wsgi_request_correct_1(self) -> None:
        expected_write_data = json.dumps(  # noqa: F841
            {
                "events": [
                    {
                        "type": "create",
                        "fqid": "topic/42",
                        "fields": {
                            "meeting_id": 2393342057,
                            "title": "title_ooPhi9ZohC",
                            "text": "text_eeKoosahh4",
                            "agenda_item_id": 42,
                        },
                    },
                    {
                        "type": "update",
                        "fqid": "meeting/2393342057",
                        "fields": {"topic_ids": [42]},
                    },
                    {
                        "type": "create",
                        "fqid": "agenda_item/42",
                        "fields": {
                            "meeting_id": 2393342057,
                            "content_object_id": "topic/42",
                        },
                    },
                    {
                        "type": "update",
                        "fqid": "meeting/2393342057",
                        "fields": {"agenda_item_ids": [42]},
                    },
                ],
                "information": {
                    "topic/42": ["Object created"],
                    "meeting/2393342057": [
                        "Object attached to topic",
                        "Object attached to agenda item",
                    ],
                    "agenda_item/42": ["Object created"],
                },
                "user_id": self.user_id,
                "locked_fields": {"meeting/2393342057": 1},
            }
        )
        response = self.client.post(
            "/",
            json=[{
                "action": "topic.create",
                "data": self.valid_payload_1
            }],
        )
        self.assert_status_code(response, 200)
        self.assertIn("Action handled successfully", str(response.data))

    def test_wsgi_request_correct_2(self) -> None:
        expected_write_data = json.dumps(  # noqa: F841
            {
                "events": [
                    {
                        "type": "create",
                        "fqid": "topic/42",
                        "fields": {
                            "meeting_id": 4002059810,
                            "title": "title_pha2Eirohg",
                            "text": "text_CaekiiLai2",
                            "attachment_ids": self.attachments,
                            "agenda_item_id": 42,
                        },
                    },
                    {
                        "type": "update",
                        "fqid": f"mediafile/{self.attachments[0]}",
                        "fields": {"attachment_ids": ["topic/6259289755", "topic/42"]},
                    },
                    {
                        "type": "update",
                        "fqid": f"mediafile/{self.attachments[1]}",
                        "fields": {"attachment_ids": ["topic/42"]},
                    },
                    {
                        "type": "update",
                        "fqid": "meeting/4002059810",
                        "fields": {"topic_ids": [42]},
                    },
                    {
                        "type": "create",
                        "fqid": "agenda_item/42",
                        "fields": {
                            "meeting_id": 4002059810,
                            "content_object_id": "topic/42",
                        },
                    },
                    {
                        "type": "update",
                        "fqid": "meeting/4002059810",
                        "fields": {"agenda_item_ids": [42]},
                    },
                ],
                "information": {
                    "topic/42": ["Object created"],
                    f"mediafile/{self.attachments[0]}": ["Object attached to topic"],
                    f"mediafile/{self.attachments[1]}": ["Object attached to topic"],
                    "meeting/4002059810": [
                        "Object attached to topic",
                        "Object attached to agenda item",
                    ],
                    "agenda_item/42": ["Object created"],
                },
                "user_id": self.user_id,
                "locked_fields": {
                    f"mediafile/{self.attachments[0]}": 1,
                    f"mediafile/{self.attachments[1]}": 1,
                    "meeting/4002059810": 1,
                },
            }
        )
        response = self.client.post(
            "/",
            json=[{
                "action": "topic.create",
                "data": self.valid_payload_2
            }],
        )
        self.assert_status_code(response, 200)

    def test_wsgi_request_correct_3(self) -> None:
        expected_write_data = json.dumps(  # noqa: F841
            {
                "events": [
                    {
                        "type": "create",
                        "fqid": "topic/42",
                        "fields": {
                            "meeting_id": 3611987967,
                            "title": "title_eivaey2Aeg",
                            "agenda_item_id": 42,
                        },
                    },
                    {
                        "type": "update",
                        "fqid": "meeting/3611987967",
                        "fields": {"topic_ids": [6375863023, 6259289755, 42]},
                    },
                    {
                        "type": "create",
                        "fqid": "agenda_item/42",
                        "fields": {
                            "meeting_id": 3611987967,
                            "content_object_id": "topic/42",
                        },
                    },
                    {
                        "type": "update",
                        "fqid": "meeting/3611987967",
                        "fields": {"agenda_item_ids": [42]},
                    },
                ],
                "information": {
                    "topic/42": ["Object created"],
                    "meeting/3611987967": [
                        "Object attached to topic",
                        "Object attached to agenda item",
                    ],
                    "agenda_item/42": ["Object created"],
                },
                "user_id": self.user_id,
                "locked_fields": {"meeting/3611987967": 1},
            }
        )
        response = self.client.post(
            "/",
            json=[{
                "action": "topic.create",
                "data": self.valid_payload_3
            }],
        )
        self.assert_status_code(response, 200)
示例#18
0
 def create_client(self,
                   username: str = None,
                   password: str = None) -> Client:
     return Client(self.app, username, password)