Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
push:
branches: ["main"]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install ruff
- name: Run linters
run: ruff check .
- name: Run tests
run: pytest -vv
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from tools.wordpress_poster_tool import WordPressPosterTool
from logger import setup_logger
from check_ollama import check_ollama
from custom_ollama import CustomOllamaLLM
import os
import sys
import time
Expand Down
4 changes: 2 additions & 2 deletions tests/test_news_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def is_recent_date(date_str):
parsed_date = datetime.strptime(date_str, "%a, %d %b %Y %H:%M:%S %z")
cutoff_date = datetime.now(timezone.utc) - timedelta(hours=24)
return parsed_date >= cutoff_date
except:
except Exception:
return False

def test_news_fetcher():
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_news_fetcher():

return True

except Exception as e:
except Exception:
logger.exception("Test failed with exception")
return False

Expand Down
4 changes: 2 additions & 2 deletions tests/test_wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_wordpress_post():
logger.info(f"Raw response:\n{json.dumps(result, indent=2)}")

if isinstance(result, dict) and 'id' in result:
logger.info(f"Post created successfully!")
logger.info("Post created successfully!")
logger.info(f"Post ID: {result['id']}")
logger.info(f"Post URL: {result.get('link', 'No link available')}")
logger.info(f"Post Status: {result.get('status', 'unknown')}")
Expand All @@ -48,6 +48,6 @@ def test_wordpress_post():
if __name__ == "__main__":
try:
test_wordpress_post()
except Exception as e:
except Exception:
logger.error("Test failed", exc_info=True)
sys.exit(1)
1 change: 0 additions & 1 deletion tests/test_wordpress_mock.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest
from unittest.mock import patch, MagicMock
from tools.wordpress_poster_tool import WordPressPosterTool
import requests

class TestWordPressPosterTool(unittest.TestCase):
def setUp(self):
Expand Down
18 changes: 12 additions & 6 deletions tests/test_wordpress_poster.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ def test_missing_env_vars():
original_pass = os.environ.get('WORDPRESS_PASS')

# Temporarily remove environment variables
if 'WORDPRESS_URL' in os.environ: del os.environ['WORDPRESS_URL']
if 'WORDPRESS_USER' in os.environ: del os.environ['WORDPRESS_USER']
if 'WORDPRESS_PASS' in os.environ: del os.environ['WORDPRESS_PASS']
if 'WORDPRESS_URL' in os.environ:
del os.environ['WORDPRESS_URL']
if 'WORDPRESS_USER' in os.environ:
del os.environ['WORDPRESS_USER']
if 'WORDPRESS_PASS' in os.environ:
del os.environ['WORDPRESS_PASS']

try:
tool = WordPressPosterTool(
Expand All @@ -124,6 +127,9 @@ def test_missing_env_vars():
assert 'WORDPRESS_URL not set' in str(exc_info.value)
finally:
# Restore environment variables
if original_url: os.environ['WORDPRESS_URL'] = original_url
if original_user: os.environ['WORDPRESS_USER'] = original_user
if original_pass: os.environ['WORDPRESS_PASS'] = original_pass
if original_url:
os.environ['WORDPRESS_URL'] = original_url
if original_user:
os.environ['WORDPRESS_USER'] = original_user
if original_pass:
os.environ['WORDPRESS_PASS'] = original_pass
2 changes: 0 additions & 2 deletions tests/test_wordpress_tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import pytest
import responses
import requests
from requests.auth import HTTPBasicAuth
from dotenv import load_dotenv
from tools.wordpress_poster_tool import WordPressPosterTool
Expand Down
2 changes: 1 addition & 1 deletion tools/news_fetcher_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from logger import setup_logger
import time
from datetime import datetime, timezone, timedelta
from typing import List, Dict, Any
from typing import Dict, Any

logger = setup_logger()

Expand Down
6 changes: 2 additions & 4 deletions tools/wordpress_poster_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from dotenv import load_dotenv
from requests.auth import HTTPBasicAuth
from logger import setup_logger
from typing import Dict, Any, List, Tuple, Optional, Union
from urllib.parse import urljoin, urlparse
import re
from typing import Dict, Any, List, Tuple, Optional
import time

logger = setup_logger()
Expand Down Expand Up @@ -127,7 +125,7 @@ def _validate_response(self, response: requests.Response) -> Dict[str, Any]:

except requests.exceptions.JSONDecodeError:
raise ValueError(f"Invalid JSON response: {response.text}")
except requests.exceptions.HTTPError as e:
except requests.exceptions.HTTPError:
if response.status_code == 401:
raise ValueError("Authentication failed. Check your WordPress credentials.")
elif response.status_code == 404:
Expand Down
Loading