def setUp(self) -> None: super().setUp() self.user_id = 5968705978 self.action = TopicUpdate( "topic.update", PermissionTestAdapter(superuser=self.user_id), DatabaseTestAdapter(old_style_testing=True), )
def setUp(self) -> None: super().setUp() self.action = TopicUpdate(PermissionTestAdapter(), DatabaseTestAdapter()) self.user_id = ( 5968705978 # This user has perm TOPIC_CAN_MANAGE for some meetings. )
class TopicUpdateActionPerformTester(BaseTopicUpdateActionTester): def setUp(self) -> None: super().setUp() self.action = TopicUpdate(PermissionTestAdapter(), DatabaseTestAdapter()) self.user_id = ( 5968705978 # This user has perm TOPIC_CAN_MANAGE for some meetings. ) 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_gaiThupu6a"}] 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 ) expected = [ { "events": [ { "type": "update", "fqid": get_fqid("topic/1312354708"), "fields": { "title": "title_ahbuQu9ooz", "text": "text_thuF7Ahxee", }, }, ], "information": {get_fqid("topic/1312354708"): ["Object updated"]}, "user_id": self.user_id, "locked_fields": {get_fqfield("topic/1312354708/deleted"): 1}, }, ] result = list(write_request_elements) self.assertEqual(result, 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("topic/1312354708"), "fields": { "title": "title_pai9oN2aec", "text": "text_oon2lai3Ie", "attachment_ids": self.attachments, }, }, { "type": "update", "fqid": get_fqid(f"mediafile/{self.attachments[0]}"), "fields": { "attachment_ids": [ get_fqid("topic/6259289755"), get_fqid("topic/1312354708"), ] }, }, { "type": "update", "fqid": get_fqid(f"mediafile/{self.attachments[1]}"), "fields": {"attachment_ids": [get_fqid("topic/1312354708")]}, }, ], "information": { get_fqid("topic/1312354708"): ["Object updated"], get_fqid(f"mediafile/{self.attachments[0]}"): [ "Object attached to topic" ], get_fqid(f"mediafile/{self.attachments[1]}"): [ "Object attached to topic" ], }, "user_id": self.user_id, "locked_fields": { get_fqfield("topic/1312354708/deleted"): 1, get_fqfield(f"mediafile/{self.attachments[0]}/attachment_ids"): 1, get_fqfield(f"mediafile/{self.attachments[1]}/attachment_ids"): 1, }, }, ] result = list(write_request_elements) self.assertEqual(result, expected) def test_perform_correct_3(self) -> None: write_request_elements = self.action.perform( self.valid_payload_3, user_id=self.user_id ) expected = [ { "events": [ { "type": "update", "fqid": get_fqid("topic/6259289755"), "fields": {"title": "title_Ashae0quei", "attachment_ids": []}, }, { "type": "update", "fqid": get_fqid("mediafile/3549387598"), "fields": {"attachment_ids": []}, }, ], "information": { get_fqid("topic/6259289755"): ["Object updated"], get_fqid("mediafile/3549387598"): [ "Object attachment to topic reset" ], }, "user_id": self.user_id, "locked_fields": { get_fqfield("topic/6259289755/deleted"): 1, get_fqfield("mediafile/3549387598/attachment_ids"): 1, }, }, ] result = list(write_request_elements) self.assertEqual(result, expected) def test_perform_correct_4(self) -> None: write_request_elements = self.action.perform( self.valid_payload_4, user_id=self.user_id ) expected = [ { "events": [ { "type": "update", "fqid": get_fqid("topic/6259289755"), "fields": {"attachment_ids": self.attachments}, }, { "type": "update", "fqid": get_fqid(f"mediafile/{self.attachments[1]}"), "fields": {"attachment_ids": [get_fqid("topic/6259289755")]}, }, ], "information": { get_fqid("topic/6259289755"): ["Object updated"], get_fqid(f"mediafile/{self.attachments[1]}"): [ "Object attached to topic" ], }, "user_id": self.user_id, "locked_fields": { get_fqfield("topic/6259289755/deleted"): 1, get_fqfield(f"mediafile/{self.attachments[1]}/attachment_ids"): 1, }, }, ] result = list(write_request_elements) self.assertEqual(result, expected) def test_perform_correct_5(self) -> None: write_request_elements = self.action.perform( self.valid_payload_5, user_id=self.user_id ) expected = [ { "events": [ { "type": "update", "fqid": get_fqid("topic/6259289755"), "fields": {"attachment_ids": [self.attachments[1]]}, }, { "type": "update", "fqid": get_fqid(f"mediafile/{self.attachments[0]}"), "fields": {"attachment_ids": []}, }, { "type": "update", "fqid": get_fqid(f"mediafile/{self.attachments[1]}"), "fields": {"attachment_ids": [get_fqid("topic/6259289755")]}, }, ], "information": { get_fqid("topic/6259289755"): ["Object updated"], get_fqid(f"mediafile/{self.attachments[0]}"): [ "Object attachment to topic reset" ], get_fqid(f"mediafile/{self.attachments[1]}"): [ "Object attached to topic" ], }, "user_id": self.user_id, "locked_fields": { get_fqfield("topic/6259289755/deleted"): 1, get_fqfield(f"mediafile/{self.attachments[0]}/attachment_ids"): 1, get_fqfield(f"mediafile/{self.attachments[1]}/attachment_ids"): 1, }, }, ] result = list(write_request_elements) self.assertEqual(result, expected)
class TopicUpdateActionUnitTester(BaseTopicUpdateActionTester): def setUp(self) -> None: super().setUp() self.action = TopicUpdate(PermissionTestAdapter(), DatabaseTestAdapter()) self.action.user_id = ( 5968705978 # This user has perm TOPIC_CAN_MANAGE for some meetings. ) 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_guaPee0goh"}] 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_prepare_dataset_1(self) -> None: dataset = self.action.prepare_dataset(self.valid_payload_1) self.assertEqual(dataset["position"], 1) self.assertEqual( dataset["data"], [{"instance": self.valid_payload_1[0], "relations": {}}], ) def test_prepare_dataset_2(self) -> None: dataset = self.action.prepare_dataset(self.valid_payload_2) self.assertEqual(dataset["position"], 1) self.assertEqual( dataset["data"], [ { "instance": self.valid_payload_2[0], "relations": { get_fqfield( f"mediafile/{self.attachments[0]}/attachment_ids" ): { "type": "add", "value": [ get_fqid("topic/6259289755"), get_fqid("topic/1312354708"), ], }, get_fqfield( f"mediafile/{self.attachments[1]}/attachment_ids" ): {"type": "add", "value": [get_fqid("topic/1312354708")]}, }, } ], ) def test_prepare_dataset_3(self) -> None: dataset = self.action.prepare_dataset(self.valid_payload_3) self.assertEqual(dataset["position"], 1) self.assertEqual( dataset["data"], [ { "instance": self.valid_payload_3[0], "relations": { get_fqfield( f"mediafile/{self.attachments[0]}/attachment_ids" ): {"type": "remove", "value": []}, }, } ], ) def test_prepare_dataset_4(self) -> None: dataset = self.action.prepare_dataset(self.valid_payload_4) self.assertEqual(dataset["position"], 1) self.assertEqual( dataset["data"], [ { "instance": self.valid_payload_4[0], "relations": { get_fqfield( f"mediafile/{self.attachments[1]}/attachment_ids" ): {"type": "add", "value": [get_fqid("topic/6259289755")]}, }, } ], ) def test_prepare_dataset_5(self) -> None: dataset = self.action.prepare_dataset(self.valid_payload_5) self.assertEqual(dataset["position"], 1) self.assertEqual( dataset["data"], [ { "instance": self.valid_payload_5[0], "relations": { get_fqfield( f"mediafile/{self.attachments[0]}/attachment_ids" ): {"type": "remove", "value": []}, get_fqfield( f"mediafile/{self.attachments[1]}/attachment_ids" ): {"type": "add", "value": [get_fqid("topic/6259289755")]}, }, } ], )