File size: 2,304 Bytes
0874636
7889c99
 
 
 
 
 
 
0874636
cf772f7
0874636
7889c99
 
0874636
 
 
 
7889c99
0874636
7889c99
cf772f7
7889c99
 
 
0874636
cf772f7
0874636
 
cf772f7
 
 
0874636
cf772f7
 
 
 
 
 
 
 
 
 
0874636
cf772f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from ragflow import RAGFlow, DataSet

from common import API_KEY, HOST_ADDRESS
from test_sdkbase import TestSdk


class TestDataset(TestSdk):
    def test_create_dataset_with_success(self):
        """

        Test creating a dataset with success

        """
        rag = RAGFlow(API_KEY, HOST_ADDRESS)
        ds = rag.create_dataset("God")
        if isinstance(ds, DataSet):
            assert ds.name == "God", "Name does not match."
        else:
            assert False, f"Failed to create dataset, error: {ds}"

    def test_update_dataset_with_success(self):
        """

        Test updating a dataset with success.

        """
        rag = RAGFlow(API_KEY, HOST_ADDRESS)
        ds = rag.create_dataset("ABC")
        if isinstance(ds, DataSet):
            assert ds.name == "ABC", "Name does not match."
            ds.name = 'DEF'
            res = ds.save()
            assert res is True, f"Failed to update dataset, error: {res}"
        else:
            assert False, f"Failed to create dataset, error: {ds}"

    def test_delete_dataset_with_success(self):
        """

        Test deleting a dataset with success

        """
        rag = RAGFlow(API_KEY, HOST_ADDRESS)
        ds = rag.create_dataset("MA")
        if isinstance(ds, DataSet):
            assert ds.name == "MA", "Name does not match."
            res = ds.delete()
            assert res is True, f"Failed to delete dataset, error: {res}"
        else:
            assert False, f"Failed to create dataset, error: {ds}"

    def test_list_datasets_with_success(self):
        """

        Test listing datasets with success

        """
        rag = RAGFlow(API_KEY, HOST_ADDRESS)
        list_datasets = rag.list_datasets()
        assert len(list_datasets) > 0, "Do not exist any dataset"
        for ds in list_datasets:
            assert isinstance(ds, DataSet), "Existence type is not dataset."

    def test_get_detail_dataset_with_success(self):
        """

        Test getting a dataset's detail with success

        """
        rag = RAGFlow(API_KEY, HOST_ADDRESS)
        ds = rag.get_dataset(name="God")
        assert isinstance(ds, DataSet), f"Failed to get dataset, error: {ds}."
        assert ds.name == "God", "Name does not match"