File size: 51,944 Bytes
de7c780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee39a70
de7c780
 
ee39a70
de7c780
 
 
 
 
 
 
ee39a70
de7c780
 
ee39a70
de7c780
 
 
 
 
 
 
ee39a70
de7c780
 
ee39a70
de7c780
 
 
 
 
 
 
 
ee39a70
de7c780
 
 
 
 
 
 
ee39a70
de7c780
 
ee39a70
de7c780
 
 
 
 
 
 
ee39a70
de7c780
 
ee39a70
de7c780
 
 
 
 
 
 
ee39a70
de7c780
 
ee39a70
 
 
de7c780
 
 
 
 
 
 
ee39a70
de7c780
 
ee39a70
de7c780
 
 
 
 
 
 
ee39a70
 
de7c780
ee39a70
de7c780
 
 
 
 
 
 
ee39a70
 
de7c780
ee39a70
de7c780
 
 
 
 
 
 
ee39a70
 
de7c780
ee39a70
de7c780
12defec
 
 
 
 
 
 
ee39a70
12defec
 
 
ee39a70
 
12defec
 
 
ee39a70
de7c780
12defec
 
 
 
 
 
ee39a70
12defec
ee39a70
de7c780
12defec
 
 
 
 
 
 
ee39a70
12defec
 
 
 
ee39a70
12defec
ee39a70
12defec
 
 
ee39a70
12defec
 
 
 
 
 
 
ee39a70
12defec
 
 
ee39a70
 
12defec
 
 
ee39a70
 
12defec
 
 
 
 
 
 
 
ee39a70
12defec
 
 
 
ee39a70
12defec
ee39a70
 
12defec
 
 
ee39a70
 
12defec
061aa4e
 
 
 
 
 
 
 
ee39a70
061aa4e
 
 
 
ee39a70
061aa4e
 
 
 
 
 
 
 
ee39a70
061aa4e
 
 
 
ee39a70
061aa4e
 
 
 
 
 
 
 
ee39a70
061aa4e
 
ee39a70
061aa4e
 
 
 
 
 
 
 
ee39a70
061aa4e
 
 
 
ee39a70
061aa4e
 
 
 
 
 
 
ee39a70
061aa4e
ee39a70
061aa4e
 
 
 
 
 
 
ee39a70
061aa4e
 
 
 
 
ee39a70
061aa4e
 
 
 
 
 
 
ee39a70
061aa4e
 
 
 
 
ee39a70
061aa4e
 
 
 
 
 
 
ee39a70
061aa4e
 
 
 
ee39a70
 
061aa4e
 
 
ee39a70
061aa4e
 
 
 
 
 
 
 
ee39a70
061aa4e
 
 
 
ee39a70
061aa4e
ee39a70
061aa4e
 
 
ee39a70
061aa4e
 
ee39a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de7c780
ee39a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4856f42
ee39a70
de7c780
4856f42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de7c780
6674a75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de7c780
6674a75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8337858
de7c780
8337858
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de7c780
 
4b9f80a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddcaad4
4b9f80a
 
 
 
 
 
 
 
 
 
 
de7c780
4b9f80a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de7c780
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
from api.settings import RetCode
from test_sdkbase import TestSdk
from ragflow import RAGFlow
import pytest
from common import API_KEY, HOST_ADDRESS


class TestFile(TestSdk):
    """
    This class contains a suite of tests for the content management functionality within the dataset.
    It ensures that the following functionalities as expected:
        1. upload local files
        2. upload remote files
        3. download a file
        4. delete a file
        5. enable rename
        6. list files
        7. start parsing
        8. end parsing
        9. check the status of the file
        10. list the chunks
        11. delete a chunk
        12. insert a new chunk
        13. edit the status of chunk
        14. get the specific chunk
        15. retrieval test
    """

# ----------------------------upload local files-----------------------------------------------------
    def test_upload_two_files(self):
        """
        Test uploading two files with success.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_two_files")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert res["code"] == RetCode.SUCCESS and res["message"] == "success"

    def test_upload_one_file(self):
        """
        Test uploading one file with success.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_one_file")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt"]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert res["code"] == RetCode.SUCCESS and res["message"] == "success"

    def test_upload_nonexistent_files(self):
        """
        Test uploading a file which does not exist.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_nonexistent_files")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/imagination.txt"]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert res["code"] == RetCode.DATA_ERROR and "does not exist" in res["message"]

    def test_upload_file_if_dataset_does_not_exist(self):
        """
        Test uploading files if the dataset id does not exist.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        file_paths = ["test_data/test.txt"]
        res = ragflow.upload_local_file("111", file_paths)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "Can't find this dataset"

    def test_upload_file_without_name(self):
        """
        Test uploading files that do not have name.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_file_without_name")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/.txt"]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert res["code"] == RetCode.SUCCESS

    def test_upload_file_without_name1(self):
        """
        Test uploading files that do not have name.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_file_without_name")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/.txt", "test_data/empty.txt"]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert res["code"] == RetCode.SUCCESS

    def test_upload_files_exceeding_the_number_limit(self):
        """
        Test uploading files whose number exceeds the limit.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_files_exceeding_the_number_limit")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt", "test_data/test1.txt"] * 256
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert (res["message"] ==
                "You try to upload 512 files, which exceeds the maximum number of uploading files: 256"
                and res["code"] == RetCode.DATA_ERROR)

    def test_upload_files_without_files(self):
        """
        Test uploading files without files.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_files_without_files")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = [None]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert (res["message"] == "None is not string." and res["code"] == RetCode.ARGUMENT_ERROR)

    def test_upload_files_with_two_files_with_same_name(self):
        """
        Test uploading files with the same name.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_files_with_two_files_with_same_name")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt"] * 2
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert (res["message"] == "success" and res["code"] == RetCode.SUCCESS)

    def test_upload_files_with_file_paths(self):
        """
        Test uploading files with only specifying the file path's repo.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_files_with_file_paths")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/"]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert (res["message"] == "The file test_data/ does not exist" and res["code"] == RetCode.DATA_ERROR)

    def test_upload_files_with_remote_file_path(self):
        """
        Test uploading files with remote files.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_upload_files_with_remote_file_path")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["https://github.com/genostack/ragflow"]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        assert res["code"] == RetCode.ARGUMENT_ERROR and res["message"] == "Remote files have not unsupported."

# ----------------------------delete a file-----------------------------------------------------
    def test_delete_one_file(self):
        """
        Test deleting one file with success.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_delete_one_file")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt"]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        # get the doc_id
        data = res["data"][0]
        doc_id = data["id"]
        # delete the files
        deleted_res = ragflow.delete_files(doc_id, dataset_id)
        # assert value
        assert deleted_res["code"] == RetCode.SUCCESS and deleted_res["data"] is True

    def test_delete_document_with_not_existing_document(self):
        """
        Test deleting a document that does not exist with failure.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_delete_document_with_not_existing_document")
        dataset_id = created_res["data"]["dataset_id"]
        res = ragflow.delete_files("111", dataset_id)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "Document 111 not found!"

    def test_delete_document_with_creating_100_documents_and_deleting_100_documents(self):
        """
        Test deleting documents when uploading 100 docs and deleting 100 docs.
        """
        # upload 100 docs
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_delete_one_file")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt"] * 100
        res = ragflow.upload_local_file(dataset_id, file_paths)

        # get the doc_id
        data = res["data"]
        for d in data:
            doc_id = d["id"]
            # delete the files
            deleted_res = ragflow.delete_files(doc_id, dataset_id)
            # assert value
            assert deleted_res["code"] == RetCode.SUCCESS and deleted_res["data"] is True

    def test_delete_document_from_nonexistent_dataset(self):
        """
        Test deleting documents from a non-existent dataset
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_delete_one_file")
        dataset_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt"]
        res = ragflow.upload_local_file(dataset_id, file_paths)
        # get the doc_id
        data = res["data"][0]
        doc_id = data["id"]
        # delete the files
        deleted_res = ragflow.delete_files(doc_id, "000")
        # assert value
        assert (deleted_res["code"] == RetCode.ARGUMENT_ERROR and deleted_res["message"] ==
                f"The document {doc_id} is not in the dataset: 000, but in the dataset: {dataset_id}.")

    def test_delete_document_which_is_located_in_other_dataset(self):
        """
        Test deleting a document which is located in other dataset.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        # upload a document
        created_res = ragflow.create_dataset("test_delete_document_which_is_located_in_other_dataset")
        created_res_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt"]
        res = ragflow.upload_local_file(created_res_id, file_paths)
        # other dataset
        other_res = ragflow.create_dataset("other_dataset")
        other_dataset_id = other_res["data"]["dataset_id"]
        # get the doc_id
        data = res["data"][0]
        doc_id = data["id"]
        # delete the files from the other dataset
        deleted_res = ragflow.delete_files(doc_id, other_dataset_id)
        # assert value
        assert (deleted_res["code"] == RetCode.ARGUMENT_ERROR and deleted_res["message"] ==
                f"The document {doc_id} is not in the dataset: {other_dataset_id}, but in the dataset: {created_res_id}.")

# ----------------------------list files-----------------------------------------------------
    def test_list_documents_with_success(self):
        """
        Test listing documents with a successful outcome.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        # upload a document
        created_res = ragflow.create_dataset("test_list_documents_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt"]
        ragflow.upload_local_file(created_res_id, file_paths)
        # Call the list_document method
        response = ragflow.list_files(created_res_id)
        assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 1

    def test_list_documents_with_checking_size(self):
        """
        Test listing documents and verify the size and names of the documents.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        # upload 10 documents
        created_res = ragflow.create_dataset("test_list_documents_with_checking_size")
        created_res_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt"] * 10
        ragflow.upload_local_file(created_res_id, file_paths)
        # Call the list_document method
        response = ragflow.list_files(created_res_id)
        assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 10

    def test_list_documents_with_getting_empty_result(self):
        """
        Test listing documents that should be empty.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        # upload 0 documents
        created_res = ragflow.create_dataset("test_list_documents_with_getting_empty_result")
        created_res_id = created_res["data"]["dataset_id"]
        # Call the list_document method
        response = ragflow.list_files(created_res_id)
        assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 0

    def test_list_documents_with_creating_100_documents(self):
        """
        Test listing 100 documents and verify the size of these documents.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        # upload 100 documents
        created_res = ragflow.create_dataset("test_list_documents_with_creating_100_documents")
        created_res_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt"] * 100
        ragflow.upload_local_file(created_res_id, file_paths)
        # Call the list_document method
        response = ragflow.list_files(created_res_id)
        assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 100

    def test_list_document_with_failure(self):
        """
        Test listing documents with IndexError.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_list_document_with_failure")
        created_res_id = created_res["data"]["dataset_id"]
        response = ragflow.list_files(created_res_id, offset=-1, count=-1)
        assert "IndexError" in response["message"] and response["code"] == RetCode.EXCEPTION_ERROR

    def test_list_document_with_verifying_offset_and_count(self):
        """
        Test listing documents with verifying the functionalities of offset and count.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_list_document_with_verifying_offset_and_count")
        created_res_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt", "test_data/empty.txt"] * 10
        ragflow.upload_local_file(created_res_id, file_paths)
        # Call the list_document method
        response = ragflow.list_files(created_res_id, offset=2, count=10)

        assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 10

    def test_list_document_with_verifying_keywords(self):
        """
        Test listing documents with verifying the functionality of searching keywords.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_list_document_with_verifying_keywords")
        created_res_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt", "test_data/empty.txt"]
        ragflow.upload_local_file(created_res_id, file_paths)
        # Call the list_document method
        response = ragflow.list_files(created_res_id, keywords="empty")

        assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 1

    def test_list_document_with_verifying_order_by_and_descend(self):
        """
        Test listing documents with verifying the functionality of order_by and descend.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_list_document_with_verifying_order_by_and_descend")
        created_res_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt", "test_data/empty.txt"]
        ragflow.upload_local_file(created_res_id, file_paths)
        # Call the list_document method
        response = ragflow.list_files(created_res_id)
        assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 2
        docs = response["data"]["docs"]
        # reverse
        i = 1
        for doc in docs:
            assert doc["name"] in file_paths[i]
            i -= 1

    def test_list_document_with_verifying_order_by_and_ascend(self):
        """
        Test listing documents with verifying the functionality of order_by and ascend.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_list_document_with_verifying_order_by_and_ascend")
        created_res_id = created_res["data"]["dataset_id"]
        file_paths = ["test_data/test.txt", "test_data/test1.txt", "test_data/empty.txt"]
        ragflow.upload_local_file(created_res_id, file_paths)
        # Call the list_document method
        response = ragflow.list_files(created_res_id, descend=False)
        assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 3

        docs = response["data"]["docs"]

        i = 0
        for doc in docs:
            assert doc["name"] in file_paths[i]
            i += 1

# ----------------------------update files: enable, rename, template_type-------------------------------------------

    def test_update_nonexistent_document(self):
        """
        Test updating a document which does not exist.
        """
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        params = {
            "name": "new_name"
        }
        res = ragflow.update_file(created_res_id, "weird_doc_id", **params)
        assert res["code"] == RetCode.ARGUMENT_ERROR and res["message"] == f"This document weird_doc_id cannot be found!"

    def test_update_document_without_parameters(self):
        """
        Test updating a document without giving parameters.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_without_parameters")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.DATA_ERROR and
                update_res["message"] == "Please input at least one parameter that you want to update!")

    def test_update_document_in_nonexistent_dataset(self):
        """
        Test updating a document in the nonexistent dataset.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_in_nonexistent_dataset")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "name": "new_name"
        }
        update_res = ragflow.update_file("fake_dataset_id", doc_id, **params)
        assert (update_res["code"] == RetCode.DATA_ERROR and
                update_res["message"] == f"This dataset fake_dataset_id cannot be found!")

    def test_update_document_with_different_extension_name(self):
        """
        Test the updating of a document with an extension name that differs from its original.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_with_different_extension_name")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "name": "new_name.doc"
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.ARGUMENT_ERROR and
                update_res["message"] == "The extension of file cannot be changed")

    def test_update_document_with_duplicate_name(self):
        """
        Test the updating of a document with a duplicate name.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_with_different_extension_name")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "name": "test.txt"
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.ARGUMENT_ERROR and
                update_res["message"] == "Duplicated document name in the same dataset.")

    def test_update_document_with_updating_its_name_with_success(self):
        """
        Test the updating of a document's name with success.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_with_updating_its_name_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "name": "new_name.txt"
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.SUCCESS and
                update_res["message"] == "Success" and update_res["data"]["name"] == "new_name.txt")

    def test_update_document_with_updating_its_template_type_with_success(self):
        """
        Test the updating of a document's template type with success.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_with_updating_its_template_type_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "template_type": "laws"
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.SUCCESS and
                update_res["message"] == "Success" and update_res["data"]["parser_id"] == "laws")

    def test_update_document_with_updating_its_enable_value_with_success(self):
        """
        Test the updating of a document's enable value with success.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_with_updating_its_enable_value_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "enable": "0"
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.SUCCESS and
                update_res["message"] == "Success" and update_res["data"]["status"] == "0")

    def test_update_document_with_updating_illegal_parameter(self):
        """
        Test the updating of a document's illegal parameter.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_with_updating_illegal_parameter")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "illegal_parameter": "0"
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.ARGUMENT_ERROR and
                update_res["message"] == "illegal_parameter is an illegal parameter.")

    def test_update_document_with_giving_its_name_value(self):
        """
        Test the updating of a document's name without its name value.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_with_updating_its_name_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "name": ""
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.DATA_ERROR and
                update_res["message"] == "There is no new name.")

    def test_update_document_with_giving_illegal_value_for_enable(self):
        """
        Test the updating of a document's with giving illegal enable's value.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_with_updating_its_name_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "enable": "?"
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.DATA_ERROR and
                update_res["message"] == "Illegal value ? for 'enable' field.")

    def test_update_document_with_giving_illegal_value_for_type(self):
        """
        Test the updating of a document's with giving illegal type's value.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_update_document_with_updating_its_name_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # update file
        params = {
            "template_type": "?"
        }
        update_res = ragflow.update_file(created_res_id, doc_id, **params)
        assert (update_res["code"] == RetCode.DATA_ERROR and
                update_res["message"] == "Illegal value ? for 'template_type' field.")

# ----------------------------download a file-----------------------------------------------------

    def test_download_nonexistent_document(self):
        """
        Test downloading a document which does not exist.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_download_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        res = ragflow.download_file(created_res_id, "imagination")
        assert res["code"] == RetCode.ARGUMENT_ERROR and res["message"] == f"This document 'imagination' cannot be found!"

    def test_download_document_in_nonexistent_dataset(self):
        """
        Test downloading a document whose dataset is nonexistent.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_download_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # download file
        res = ragflow.download_file("imagination", doc_id)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == f"This dataset 'imagination' cannot be found!"

    def test_download_document_with_success(self):
        """
        Test the downloading of a document with success.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_download_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # download file
        with open("test_data/test.txt", "rb") as file:
            binary_data = file.read()
        res = ragflow.download_file(created_res_id, doc_id)
        assert res["code"] == RetCode.SUCCESS and res["data"] == binary_data

    def test_download_an_empty_document(self):
        """
        Test the downloading of an empty document.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_download_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/empty.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # download file
        res = ragflow.download_file(created_res_id, doc_id)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "This file is empty."

# ----------------------------start parsing-----------------------------------------------------
    def test_start_parsing_document_with_success(self):
        """
        Test the parsing of a document with success.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_start_parsing_document_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/lol.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # parse file
        res = ragflow.start_parsing_document(created_res_id, doc_id)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""

    def test_start_parsing_nonexistent_document(self):
        """
        Test the parsing a document which does not exist.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_start_parsing_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        res = ragflow.start_parsing_document(created_res_id, "imagination")
        assert res["code"] == RetCode.ARGUMENT_ERROR and res["message"] == "This document 'imagination' cannot be found!"

    def test_start_parsing_document_in_nonexistent_dataset(self):
        """
        Test the parsing a document whose dataset is nonexistent.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_download_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # parse
        res = ragflow.start_parsing_document("imagination", doc_id)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "This dataset 'imagination' cannot be found!"

    def test_start_parsing_an_empty_document(self):
        """
        Test the parsing of an empty document.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_download_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/empty.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        res = ragflow.start_parsing_document(created_res_id, doc_id)
        assert res["code"] == RetCode.SUCCESS and res["message"] == "Empty data in the document: empty.txt; "

    # ------------------------parsing multiple documents----------------------------
    def test_start_parsing_documents_in_nonexistent_dataset(self):
        """
        Test the parsing documents whose dataset is nonexistent.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_download_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # parse
        res = ragflow.start_parsing_documents("imagination")
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "This dataset 'imagination' cannot be found!"

    def test_start_parsing_multiple_documents(self):
        """
        Test the parsing documents with a success.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset(" test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        ragflow.upload_local_file(created_res_id, file_paths)
        res = ragflow.start_parsing_documents(created_res_id)
        assert res["code"] == RetCode.SUCCESS and res["data"] is True and res["message"] == ""

    def test_start_parsing_multiple_documents_with_one_empty_file(self):
        """
        Test the parsing documents, one of which is empty.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset(" test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt", "test_data/empty.txt"]
        ragflow.upload_local_file(created_res_id, file_paths)
        res = ragflow.start_parsing_documents(created_res_id)
        assert res["code"] == RetCode.SUCCESS and res["message"] == "Empty data in the document: empty.txt; "

    def test_start_parsing_multiple_specific_documents(self):
        """
        Test the parsing documents whose document ids are specified.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset(" test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"]
        doc_ids = []
        for d in data:
            doc_ids.append(d["id"])
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""

    def test_start_re_parsing_multiple_specific_documents(self):
        """
        Test the re-parsing documents.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset(" test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"]
        doc_ids = []
        for d in data:
            doc_ids.append(d["id"])
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""
        # re-parse
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""

    def test_start_re_parsing_multiple_specific_documents_with_changing_parser_id(self):
        """
        Test the re-parsing documents after changing the parser id.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset(" test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"]
        doc_ids = []
        for d in data:
            doc_ids.append(d["id"])
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""
        # general -> laws
        params = {
            "template_type": "laws"
        }
        ragflow.update_file(created_res_id, doc_ids[0], **params)
        # re-parse
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""

    def test_start_re_parsing_multiple_specific_documents_with_changing_illegal_parser_id(self):
        """
        Test the re-parsing documents after changing an illegal parser id.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset(" test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"]
        doc_ids = []
        for d in data:
            doc_ids.append(d["id"])
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""
        # general -> illegal
        params = {
            "template_type": "illegal"
        }
        res = ragflow.update_file(created_res_id, doc_ids[0], **params)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "Illegal value illegal for 'template_type' field."
        # re-parse
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""

    def test_start_parsing_multiple_specific_documents_with_changing_illegal_parser_id(self):
        """
        Test the parsing documents after changing an illegal parser id.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset(" test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"]
        doc_ids = []
        for d in data:
            doc_ids.append(d["id"])
        # general -> illegal
        params = {
            "template_type": "illegal"
        }
        res = ragflow.update_file(created_res_id, doc_ids[0], **params)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "Illegal value illegal for 'template_type' field."
        # re-parse
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""

    def test_start_parsing_multiple_documents_in_the_dataset_whose_parser_id_is_illegal(self):
        """
        Test the parsing documents whose dataset's parser id is illegal.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_start_parsing_multiple_documents_in_the_dataset_whose_parser_id_is_illegal")
        created_res_id = created_res["data"]["dataset_id"]
        # update the parser id
        params = {
            "chunk_method": "illegal"
        }
        res = ragflow.update_dataset("test_start_parsing_multiple_documents_in_the_dataset_whose_parser_id_is_illegal", **params)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "Illegal value illegal for 'chunk_method' field."
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"]
        doc_ids = []
        for d in data:
            doc_ids.append(d["id"])
        # parse
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""

# ----------------------------stop parsing-----------------------------------------------------
    def test_stop_parsing_document_with_success(self):
        """
        Test the stopping parsing of a document with success.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_start_parsing_document_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/lol.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # parse file
        res = ragflow.start_parsing_document(created_res_id, doc_id)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""
        res = ragflow.stop_parsing_document(created_res_id, doc_id)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""

    def test_stop_parsing_nonexistent_document(self):
        """
        Test the stopping parsing a document which does not exist.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_start_parsing_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        res = ragflow.stop_parsing_document(created_res_id, "imagination.txt")
        assert res["code"] == RetCode.ARGUMENT_ERROR and res["message"] == "This document 'imagination.txt' cannot be found!"

    def test_stop_parsing_document_in_nonexistent_dataset(self):
        """
        Test the stopping parsing a document whose dataset is nonexistent.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_download_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # parse
        res = ragflow.stop_parsing_document("imagination", doc_id)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "This dataset 'imagination' cannot be found!"

    # ------------------------stop parsing multiple documents----------------------------
    def test_stop_parsing_documents_in_nonexistent_dataset(self):
        """
        Test the stopping parsing documents whose dataset is nonexistent.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_download_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # parse
        res = ragflow.stop_parsing_documents("imagination")
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "This dataset 'imagination' cannot be found!"

    def test_stop_parsing_multiple_documents(self):
        """
        Test the stopping parsing documents with a success.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        ragflow.upload_local_file(created_res_id, file_paths)
        res = ragflow.start_parsing_documents(created_res_id)
        assert res["code"] == RetCode.SUCCESS and res["data"] is True and res["message"] == ""

        res = ragflow.stop_parsing_documents(created_res_id)
        assert res["code"] == RetCode.SUCCESS and res["data"] is True and res["message"] == ""

    def test_stop_parsing_multiple_documents_with_one_empty_file(self):
        """
        Test the stopping parsing documents, one of which is empty.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset(" test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt", "test_data/empty.txt"]
        ragflow.upload_local_file(created_res_id, file_paths)
        res = ragflow.start_parsing_documents(created_res_id)
        assert res["code"] == RetCode.SUCCESS and res["message"] == "Empty data in the document: empty.txt; "
        res = ragflow.stop_parsing_documents(created_res_id)
        assert res["code"] == RetCode.SUCCESS and res["data"] is True and res["message"] == ""

    def test_stop_parsing_multiple_specific_documents(self):
        """
        Test the stopping parsing documents whose document ids are specified.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset(" test_start_parsing_multiple_documents")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt", "test_data/test1.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"]
        doc_ids = []
        for d in data:
            doc_ids.append(d["id"])
        res = ragflow.start_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""
        res = ragflow.stop_parsing_documents(created_res_id, doc_ids)
        assert res["code"] == RetCode.SUCCESS and res["data"] is True and res["message"] == ""

# ----------------------------show the status of the file-----------------------------------------------------
    def test_show_status_with_success(self):
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_show_status_with_success")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/lol.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # parse file
        res = ragflow.start_parsing_document(created_res_id, doc_id)
        assert res["code"] == RetCode.SUCCESS and res["message"] == ""
        # show status
        status_res = ragflow.show_parsing_status(created_res_id, doc_id)
        assert status_res["code"] == RetCode.SUCCESS and status_res["data"]["status"] == "RUNNING"

    def test_show_status_nonexistent_document(self):
        """
        Test showing the status of a document which does not exist.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_show_status_nonexistent_document")
        created_res_id = created_res["data"]["dataset_id"]
        res = ragflow.show_parsing_status(created_res_id, "imagination")
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "This document: 'imagination' is not a valid document."

    def test_show_status_document_in_nonexistent_dataset(self):
        """
        Test showing the status of a document whose dataset is nonexistent.
        """
        # create a dataset
        ragflow = RAGFlow(API_KEY, HOST_ADDRESS)
        created_res = ragflow.create_dataset("test_show_status_document_in_nonexistent_dataset")
        created_res_id = created_res["data"]["dataset_id"]
        # upload files
        file_paths = ["test_data/test.txt"]
        uploading_res = ragflow.upload_local_file(created_res_id, file_paths)
        # get the doc_id
        data = uploading_res["data"][0]
        doc_id = data["id"]
        # parse
        res = ragflow.show_parsing_status("imagination", doc_id)
        assert res["code"] == RetCode.DATA_ERROR and res["message"] == "This dataset: 'imagination' cannot be found!"
# ----------------------------list the chunks of the file-----------------------------------------------------

# ----------------------------delete the chunk-----------------------------------------------------

# ----------------------------edit the status of the chunk-----------------------------------------------------

# ----------------------------insert a new chunk-----------------------------------------------------

# ----------------------------get a specific chunk-----------------------------------------------------

# ----------------------------retrieval test-----------------------------------------------------