repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import pytest |
| #2 | import requests |
| #3 | |
| #4 | from embedchain.loaders.discourse import DiscourseLoader |
| #5 | |
| #6 | |
| #7 | @pytest.fixture |
| #8 | def discourse_loader_config(): |
| #9 | return { |
| #10 | "domain": "https://example.com/", |
| #11 | } |
| #12 | |
| #13 | |
| #14 | @pytest.fixture |
| #15 | def discourse_loader(discourse_loader_config): |
| #16 | return DiscourseLoader(config=discourse_loader_config) |
| #17 | |
| #18 | |
| #19 | def test_discourse_loader_init_with_valid_config(): |
| #20 | config = {"domain": "https://example.com/"} |
| #21 | loader = DiscourseLoader(config=config) |
| #22 | assert loader.domain == "https://example.com/" |
| #23 | |
| #24 | |
| #25 | def test_discourse_loader_init_with_missing_config(): |
| #26 | with pytest.raises(ValueError, match="DiscourseLoader requires a config"): |
| #27 | DiscourseLoader() |
| #28 | |
| #29 | |
| #30 | def test_discourse_loader_init_with_missing_domain(): |
| #31 | config = {"another_key": "value"} |
| #32 | with pytest.raises(ValueError, match="DiscourseLoader requires a domain"): |
| #33 | DiscourseLoader(config=config) |
| #34 | |
| #35 | |
| #36 | def test_discourse_loader_check_query_with_valid_query(discourse_loader): |
| #37 | discourse_loader._check_query("sample query") |
| #38 | |
| #39 | |
| #40 | def test_discourse_loader_check_query_with_empty_query(discourse_loader): |
| #41 | with pytest.raises(ValueError, match="DiscourseLoader requires a query"): |
| #42 | discourse_loader._check_query("") |
| #43 | |
| #44 | |
| #45 | def test_discourse_loader_check_query_with_invalid_query_type(discourse_loader): |
| #46 | with pytest.raises(ValueError, match="DiscourseLoader requires a query"): |
| #47 | discourse_loader._check_query(123) |
| #48 | |
| #49 | |
| #50 | def test_discourse_loader_load_post_with_valid_post_id(discourse_loader, monkeypatch): |
| #51 | def mock_get(*args, **kwargs): |
| #52 | class MockResponse: |
| #53 | def json(self): |
| #54 | return {"raw": "Sample post content"} |
| #55 | |
| #56 | def raise_for_status(self): |
| #57 | pass |
| #58 | |
| #59 | return MockResponse() |
| #60 | |
| #61 | monkeypatch.setattr(requests, "get", mock_get) |
| #62 | |
| #63 | post_data = discourse_loader._load_post(123) |
| #64 | |
| #65 | assert post_data["content"] == "Sample post content" |
| #66 | assert "meta_data" in post_data |
| #67 | |
| #68 | |
| #69 | def test_discourse_loader_load_data_with_valid_query(discourse_loader, monkeypatch): |
| #70 | def mock_get(*args, **kwargs): |
| #71 | class MockResponse: |
| #72 | def json(self): |
| #73 | return {"grouped_search_result": {"post_ids": [123, 456, 789]}} |
| #74 | |
| #75 | def raise_for_status(self): |
| #76 | pass |
| #77 | |
| #78 | return MockResponse() |
| #79 | |
| #80 | monkeypatch.setattr(requests, "get", mock_get) |
| #81 | |
| #82 | def mock_load_post(*args, **kwargs): |
| #83 | return { |
| #84 | "content": "Sample post content", |
| #85 | "meta_data": { |
| #86 | "url": "https://example.com/posts/123.json", |
| #87 | "created_at": "2021-01-01", |
| #88 | "username": "test_user", |
| #89 | "topic_slug": "test_topic", |
| #90 | "score": 10, |
| #91 | }, |
| #92 | } |
| #93 | |
| #94 | monkeypatch.setattr(discourse_loader, "_load_post", mock_load_post) |
| #95 | |
| #96 | data = discourse_loader.load_data("sample query") |
| #97 | |
| #98 | assert len(data["data"]) == 3 |
| #99 | assert data["data"][0]["content"] == "Sample post content" |
| #100 | assert data["data"][0]["meta_data"]["url"] == "https://example.com/posts/123.json" |
| #101 | assert data["data"][0]["meta_data"]["created_at"] == "2021-01-01" |
| #102 | assert data["data"][0]["meta_data"]["username"] == "test_user" |
| #103 | assert data["data"][0]["meta_data"]["topic_slug"] == "test_topic" |
| #104 | assert data["data"][0]["meta_data"]["score"] == 10 |
| #105 |