From 4f33ad20c3c0d948f4b47dff5eca6d43f3014b1e Mon Sep 17 00:00:00 2001 From: jyong <718720800@qq.com> Date: Fri, 14 Jun 2024 23:56:53 +0800 Subject: [PATCH] lint --- api/libs/bearer_data_source.py | 7 ++---- api/services/auth/api_key_auth_base.py | 1 + .../rag/extractor/firecrawl/test_firecrawl.py | 25 ++++++------------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/api/libs/bearer_data_source.py b/api/libs/bearer_data_source.py index 61d37b23a2ced4..04de1fb6daefbd 100644 --- a/api/libs/bearer_data_source.py +++ b/api/libs/bearer_data_source.py @@ -1,4 +1,3 @@ - # [REVIEW] Implement if Needed? Do we need a new type of data source from abc import abstractmethod @@ -19,14 +18,13 @@ def validate_bearer_data_source(self): """ Validate the data source """ - class FireCrawlDataSource(BearerDataSource): def validate_bearer_data_source(self): TEST_CRAWL_SITE_URL = "https://www.google.com" FIRECRAWL_API_VERSION = "v0" - + test_api_endpoint = self.api_base_url.rstrip('/') + f"/{FIRECRAWL_API_VERSION}/scrape" headers = { @@ -42,9 +40,8 @@ def validate_bearer_data_source(self): return response.json().get("status") == "success" - def save_credentials(self): - # save data source binding + # save data source binding data_source_binding = DataSourceBearerBinding.query.filter( db.and_( DataSourceBearerBinding.tenant_id == current_user.current_tenant_id, diff --git a/api/services/auth/api_key_auth_base.py b/api/services/auth/api_key_auth_base.py index 8484e9c410e2a6..75f4e2c020b36f 100644 --- a/api/services/auth/api_key_auth_base.py +++ b/api/services/auth/api_key_auth_base.py @@ -5,5 +5,6 @@ class ApiKeyAuthBase(ABC): def __init__(self, credentials: dict): self.credentials = credentials + @staticmethod def validate_credentials(self): raise NotImplementedError diff --git a/api/tests/unit_tests/core/rag/extractor/firecrawl/test_firecrawl.py b/api/tests/unit_tests/core/rag/extractor/firecrawl/test_firecrawl.py index 7463ee38bf218d..a8bba11e16db1f 100644 --- a/api/tests/unit_tests/core/rag/extractor/firecrawl/test_firecrawl.py +++ b/api/tests/unit_tests/core/rag/extractor/firecrawl/test_firecrawl.py @@ -1,28 +1,13 @@ import os +from unittest import mock from core.rag.extractor.firecrawl.firecrawl_app import FirecrawlApp from core.rag.extractor.firecrawl.firecrawl_web_extractor import FirecrawlWebExtractor from core.rag.models.document import Document +from tests.unit_tests.core.rag.extractor.test_notion_extractor import _mock_response -def test_firecrawl_web_extractor_scrape_mode(): - url = "https://dify.ai" - api_key = os.getenv('FIRECRAWL_API_KEY') or 'fc-' - base_url = 'https://api.firecrawl.dev' - firecrawl_app = FirecrawlApp(api_key=api_key, - base_url=base_url) - params = { - 'pageOptions': { - 'onlyMainContent': True, - "includeHtml": False - } - } - data = firecrawl_app.scrape_url(url, params) - print(data) - assert isinstance(data, dict) - - -def test_firecrawl_web_extractor_crawl_mode(): +def test_firecrawl_web_extractor_crawl_mode(mocker): url = "https://firecrawl.dev" api_key = os.getenv('FIRECRAWL_API_KEY') or 'fc-' base_url = 'https://api.firecrawl.dev' @@ -39,6 +24,10 @@ def test_firecrawl_web_extractor_crawl_mode(): } } + mocked_firecrawl = { + "jobId": "test", + } + mocker.patch("requests.post", return_value=_mock_response(mocked_firecrawl)) job_id = firecrawl_app.crawl_url(url, params) print(job_id) assert isinstance(job_id, str)