mirror of
https://github.com/aserper/masto-rss.git
synced 2025-12-17 13:25:25 +00:00
Compare commits
35 Commits
main
...
0719b713e4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0719b713e4 | ||
|
|
082a0ac35c | ||
|
|
a5d5ac6b7d | ||
|
|
230f28d54e | ||
|
|
a46b54a06e | ||
|
|
7bcc0a8a16 | ||
|
|
11b17373e0 | ||
|
|
3f40b64fb6 | ||
|
|
14da5f6123 | ||
|
|
0512aaf9b3 | ||
|
|
c8618ec3b7 | ||
|
|
70a23fdb75 | ||
|
|
89b298253a | ||
|
|
cff2a721af | ||
|
|
40ede411a5 | ||
|
|
4d2dea7ab2 | ||
|
|
02b289f5d1 | ||
|
|
37ed31782f | ||
|
|
d7c710b51c | ||
|
|
78469217b3 | ||
|
|
cb534d87b2 | ||
|
|
fc1f70c845 | ||
|
|
f51c6ffa46 | ||
|
|
e3b7bc4431 | ||
|
|
263a6a90b5 | ||
|
|
b392c53129 | ||
|
|
c3a2ab9329 | ||
|
|
e2a170c10e | ||
|
|
4172460e9e | ||
|
|
94aee5e001 | ||
|
|
9e1487b6ba | ||
|
|
7e86e9ad97 | ||
|
|
21a0768c8a | ||
|
|
46f96aeecd | ||
|
|
9ec0fb08f6 |
53
.github/workflows/masto-rss.yml
vendored
53
.github/workflows/masto-rss.yml
vendored
@@ -8,13 +8,52 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v4
|
||||||
- name: Build & Push Image
|
|
||||||
run: |
|
- name: Set up QEMU
|
||||||
echo "${{ secrets.DH_PASSWORD }}" | docker login -u "amitserper" --password-stdin
|
uses: docker/setup-qemu-action@v3
|
||||||
docker build -t amitserper/masto-rss .
|
|
||||||
docker push amitserper/masto-rss
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: amitserper
|
||||||
|
password: ${{ secrets.DH_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
amitserper/masto-rss
|
||||||
|
ghcr.io/aserper/masto-rss
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=sha,prefix={{branch}}-
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
|
- name: Build and push multiarch image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|||||||
162
.github/workflows/test.yml
vendored
Normal file
162
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit-tests:
|
||||||
|
name: Unit Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: ['3.10', '3.11', '3.12']
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
cache: 'pip'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install -r requirements-test.txt
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: |
|
||||||
|
pytest test_bot.py -m "not integration" --cov=bot --cov=main --cov-report=xml --cov-report=term
|
||||||
|
|
||||||
|
- name: Upload coverage to Codecov
|
||||||
|
uses: codecov/codecov-action@v4
|
||||||
|
with:
|
||||||
|
file: ./coverage.xml
|
||||||
|
flags: unittests
|
||||||
|
name: codecov-${{ matrix.python-version }}
|
||||||
|
fail_ci_if_error: false
|
||||||
|
|
||||||
|
integration-tests:
|
||||||
|
name: Integration Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: ['3.10', '3.11', '3.12']
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
cache: 'pip'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install -r requirements-test.txt
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
run: |
|
||||||
|
pytest test_integration.py --cov=bot --cov-report=xml --cov-report=term --cov-fail-under=70
|
||||||
|
|
||||||
|
- name: Upload coverage to Codecov
|
||||||
|
uses: codecov/codecov-action@v4
|
||||||
|
with:
|
||||||
|
file: ./coverage.xml
|
||||||
|
flags: integration
|
||||||
|
name: codecov-integration-${{ matrix.python-version }}
|
||||||
|
fail_ci_if_error: false
|
||||||
|
|
||||||
|
code-quality:
|
||||||
|
name: Code Quality
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.11'
|
||||||
|
cache: 'pip'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install -r requirements-test.txt
|
||||||
|
|
||||||
|
- name: Run flake8
|
||||||
|
run: |
|
||||||
|
flake8 bot.py main.py --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||||
|
flake8 bot.py main.py --count --max-complexity=10 --max-line-length=127 --statistics
|
||||||
|
|
||||||
|
- name: Run black check
|
||||||
|
run: |
|
||||||
|
black --check bot.py main.py test_bot.py test_integration.py
|
||||||
|
|
||||||
|
- name: Run mypy
|
||||||
|
run: |
|
||||||
|
mypy bot.py main.py --ignore-missing-imports
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
docker-build-test:
|
||||||
|
name: Docker Build Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Build Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
load: true
|
||||||
|
tags: masto-rss:test
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Test Docker image structure
|
||||||
|
run: |
|
||||||
|
docker run --rm masto-rss:test python --version
|
||||||
|
docker run --rm masto-rss:test pip list | grep feedparser
|
||||||
|
docker run --rm masto-rss:test pip list | grep Mastodon
|
||||||
|
|
||||||
|
all-tests-pass:
|
||||||
|
name: All Tests Passed
|
||||||
|
needs: [unit-tests, integration-tests, code-quality, docker-build-test]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: always()
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check test results
|
||||||
|
run: |
|
||||||
|
if [ "${{ needs.unit-tests.result }}" != "success" ]; then
|
||||||
|
echo "Unit tests failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ "${{ needs.integration-tests.result }}" != "success" ]; then
|
||||||
|
echo "Integration tests failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ "${{ needs.code-quality.result }}" != "success" ]; then
|
||||||
|
echo "Code quality checks failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ "${{ needs.docker-build-test.result }}" != "success" ]; then
|
||||||
|
echo "Docker build test failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "All tests passed successfully!"
|
||||||
47
.gitignore
vendored
47
.gitignore
vendored
@@ -1,3 +1,50 @@
|
|||||||
|
# State files
|
||||||
processed_entries.txt
|
processed_entries.txt
|
||||||
|
/state/
|
||||||
|
|
||||||
|
# IDEs
|
||||||
.idea/
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# Python
|
||||||
venv/
|
venv/
|
||||||
|
.venv/
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
*.so
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
coverage.xml
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.hypothesis/
|
||||||
|
|
||||||
|
# Type checking
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Environment
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
|||||||
18
Dockerfile
18
Dockerfile
@@ -1,14 +1,18 @@
|
|||||||
# Use an appropriate base image with Python pre-installed
|
# Use an appropriate base image with Python pre-installed
|
||||||
FROM python:3.8-slim
|
FROM alpine:3.18
|
||||||
|
|
||||||
# Set the working directory inside the container
|
# Set the working directory inside the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy the entire current directory into the container at /app
|
# Install Python dependencies in a single layer
|
||||||
|
RUN apk add --no-cache python3 py3-pip
|
||||||
|
|
||||||
|
# Copy requirements first for better layer caching
|
||||||
|
COPY requirements.txt /app/
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Copy the application code
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
|
||||||
# Install any Python dependencies
|
# Run Python script with unbuffered output for container logs
|
||||||
RUN pip install -r requirements.txt
|
CMD ["python", "-u", "main.py"]
|
||||||
|
|
||||||
# Run your Python script
|
|
||||||
CMD ["python", "main.py"]
|
|
||||||
|
|||||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
237
README.md
237
README.md
@@ -1,16 +1,233 @@
|
|||||||
|

|
||||||
|
|
||||||
|
# Masto-RSS
|
||||||
|
|
||||||
|
[](https://github.com/aserper/masto-rss/actions/workflows/masto-rss.yml)
|
||||||
|
[](https://github.com/aserper/masto-rss/actions/workflows/test.yml)
|
||||||
|
[](https://hub.docker.com/r/amitserper/masto-rss)
|
||||||
|
[](https://github.com/aserper/masto-rss/pkgs/container/masto-rss)
|
||||||
|
[](LICENSE)
|
||||||
|
[](https://www.python.org/downloads/)
|
||||||
|
[](https://github.com/aserper/masto-rss)
|
||||||
|
|
||||||
|
A simple, lightweight Mastodon bot that automatically posts updates from RSS feeds to the Fediverse. Built with Python and designed to run seamlessly in Docker with multiarch support (amd64 & arm64).
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Automatically monitors RSS/Atom feeds and posts new items to Mastodon
|
||||||
|
- Persistent state tracking to avoid duplicate posts
|
||||||
|
- Configurable post visibility (public, unlisted, private, direct)
|
||||||
|
- Lightweight Alpine-based Docker image
|
||||||
|
- Multiarch support (amd64 & arm64) for broad compatibility
|
||||||
|
- Continuous monitoring with configurable check intervals
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### Using Docker (Recommended)
|
||||||
|
|
||||||
|
The easiest way to run Masto-RSS is using the pre-built multiarch Docker images available on both Docker Hub and GitHub Container Registry.
|
||||||
|
|
||||||
|
#### Pull from Docker Hub
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker pull amitserper/masto-rss:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Pull from GitHub Container Registry
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker pull ghcr.io/aserper/masto-rss:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Run the Bot
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
--name masto-rss-bot \
|
||||||
|
-e MASTODON_CLIENT_ID="your_client_id" \
|
||||||
|
-e MASTODON_CLIENT_SECRET="your_client_secret" \
|
||||||
|
-e MASTODON_ACCESS_TOKEN="your_access_token" \
|
||||||
|
-e MASTODON_INSTANCE_URL="https://mastodon.social" \
|
||||||
|
-e RSS_FEED_URL="https://example.com/feed.xml" \
|
||||||
|
-e TOOT_VISIBILITY="public" \
|
||||||
|
-e CHECK_INTERVAL="300" \
|
||||||
|
-v /path/to/state:/state \
|
||||||
|
amitserper/masto-rss:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Important:** Use a bind mount for `/state` to persist the list of processed feed items across container restarts.
|
||||||
|
|
||||||
|
### Using Docker Compose
|
||||||
|
|
||||||
|
Create a `docker-compose.yml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
masto-rss:
|
||||||
|
image: amitserper/masto-rss:latest
|
||||||
|
# Or use GHCR: ghcr.io/aserper/masto-rss:latest
|
||||||
|
container_name: masto-rss-bot
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
MASTODON_CLIENT_ID: "your_client_id"
|
||||||
|
MASTODON_CLIENT_SECRET: "your_client_secret"
|
||||||
|
MASTODON_ACCESS_TOKEN: "your_access_token"
|
||||||
|
MASTODON_INSTANCE_URL: "https://mastodon.social"
|
||||||
|
RSS_FEED_URL: "https://example.com/feed.xml"
|
||||||
|
TOOT_VISIBILITY: "public"
|
||||||
|
CHECK_INTERVAL: "300"
|
||||||
|
volumes:
|
||||||
|
- ./state:/state
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Multiple Feeds
|
||||||
|
To monitor multiple feeds, you can either:
|
||||||
|
- Use the `RSS_FEEDS` environment variable (comma-separated list)
|
||||||
|
- Use the `FEEDS_FILE` environment variable (path to file with one URL per line)
|
||||||
|
|
||||||
# Masto-rss
|
#### Run with Multiple Feeds (Docker)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
--name masto-rss-bot \
|
||||||
|
-e MASTODON_CLIENT_ID="your_client_id" \
|
||||||
|
-e MASTODON_CLIENT_SECRET="your_client_secret" \
|
||||||
|
-e MASTODON_ACCESS_TOKEN="your_access_token" \
|
||||||
|
-e MASTODON_INSTANCE_URL="https://mastodon.social" \
|
||||||
|
-e RSS_FEEDS="https://feed1.com/rss,https://feed2.com/rss" \
|
||||||
|
-e TOOT_VISIBILITY="public" \
|
||||||
|
-e CHECK_INTERVAL="300" \
|
||||||
|
-v /path/to/state:/state \
|
||||||
|
amitserper/masto-rss:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
A simple Mastodon bot written in python that posts updates from an RSS feed to a Mastodon account.
|
All configuration is done via environment variables:
|
||||||
This project is meant to be built to a docker container, so all of the options need to be set as environment variables:
|
|
||||||
MASTODON_CLIENT_ID = <Mastodon client ID
|
| Variable | Description | Required | Example |
|
||||||
MASTODON_CLIENT_SECRET = <Mastodon client secret>
|
|----------|-------------|----------|---------|
|
||||||
MASTODON_ACCESS_TOKEN = <Mastodon access token>
|
| `MASTODON_CLIENT_ID` | Mastodon application client ID | Yes | `abc123...` |
|
||||||
MASTODON_INSTANCE_URL = <Mastodon instance URL>
|
| `MASTODON_CLIENT_SECRET` | Mastodon application client secret | Yes | `xyz789...` |
|
||||||
RSS_FEED_URL = <URL of RSS/xml feed>
|
| `MASTODON_ACCESS_TOKEN` | Mastodon access token | Yes | `token123...` |
|
||||||
The best way to use this project is by using [its docker container](https://hub.docker.com/r/amitserper/masto-rss)
|
| `MASTODON_INSTANCE_URL` | URL of your Mastodon instance | Yes | `https://mastodon.social` |
|
||||||

|
| `RSS_FEED_URL` | Single RSS/Atom feed URL (Legacy) | No* | `https://example.com/feed.xml` |
|
||||||
|
| `RSS_FEEDS` | Comma-separated list of feed URLs | No* | `https://site1.com,https://site2.com` |
|
||||||
|
| `FEEDS_FILE` | Path to file containing list of feed URLs | No* | `/config/feeds.txt` |
|
||||||
|
| `TOOT_VISIBILITY` | Post visibility level | Yes | `public`, `unlisted`, `private`, or `direct` |
|
||||||
|
| `CHECK_INTERVAL` | Seconds between feed checks | Yes | `300` (5 minutes) |
|
||||||
|
| `PROCESSED_ENTRIES_FILE`| Custom path for state file | No | `/state/processed.txt` |
|
||||||
|
|
||||||
|
\* At least one of `RSS_FEED_URL`, `RSS_FEEDS`, or `FEEDS_FILE` must be provided.
|
||||||
|
|
||||||
|
### Getting Mastodon API Credentials
|
||||||
|
|
||||||
|
1. Log into your Mastodon instance
|
||||||
|
2. Go to **Settings** → **Development** → **New Application**
|
||||||
|
3. Give it a name (e.g., "RSS Bot")
|
||||||
|
4. Set scopes to `write:statuses`
|
||||||
|
5. Save and copy the client ID, client secret, and access token
|
||||||
|
|
||||||
|
## Building from Source
|
||||||
|
|
||||||
|
### Build Locally
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/aserper/masto-rss.git
|
||||||
|
cd masto-rss
|
||||||
|
docker build -t masto-rss .
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build Multiarch Images
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Set up buildx
|
||||||
|
docker buildx create --use
|
||||||
|
|
||||||
|
# Build for both architectures
|
||||||
|
docker buildx build \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
-t yourusername/masto-rss:latest \
|
||||||
|
--push \
|
||||||
|
.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running Without Docker
|
||||||
|
|
||||||
|
If you prefer to run the bot directly with Python:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clone the repository
|
||||||
|
git clone https://github.com/aserper/masto-rss.git
|
||||||
|
cd masto-rss
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
|
export MASTODON_CLIENT_ID="your_client_id"
|
||||||
|
export MASTODON_CLIENT_SECRET="your_client_secret"
|
||||||
|
export MASTODON_ACCESS_TOKEN="your_access_token"
|
||||||
|
export MASTODON_INSTANCE_URL="https://mastodon.social"
|
||||||
|
export RSS_FEED_URL="https://example.com/feed.xml"
|
||||||
|
export TOOT_VISIBILITY="public"
|
||||||
|
export CHECK_INTERVAL="300"
|
||||||
|
|
||||||
|
# Run the bot
|
||||||
|
python main.py
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note:** When running without Docker, the bot stores its state in `/state/processed_entries.txt`. Make sure this directory exists or modify [main.py](main.py#L15) to use a different path.
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. The bot fetches the RSS feed at regular intervals (defined by `CHECK_INTERVAL`)
|
||||||
|
2. For each feed item, it checks if the item's URL has been processed before
|
||||||
|
3. If the item is new, it posts to Mastodon with the format: `{title}\n\n{link}`
|
||||||
|
4. The item URL is saved to prevent duplicate posts
|
||||||
|
5. The process repeats indefinitely
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
- **Base Image:** Alpine Linux 3.18 (minimal footprint)
|
||||||
|
- **Python Version:** 3.10+
|
||||||
|
- **Platforms:** linux/amd64, linux/arm64
|
||||||
|
- **Dependencies:** feedparser, mastodon.py (see [requirements.txt](requirements.txt))
|
||||||
|
|
||||||
|
## State Persistence
|
||||||
|
|
||||||
|
The bot maintains state in `/state/processed_entries.txt` to track which feed items have already been posted. This prevents duplicate posts across restarts.
|
||||||
|
|
||||||
|
**Important:** Always mount `/state` as a volume to preserve this state file.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Contributions are welcome! Feel free to:
|
||||||
|
|
||||||
|
- Report bugs by opening an issue
|
||||||
|
- Submit pull requests for improvements
|
||||||
|
- Suggest new features or enhancements
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you find this project useful, please consider giving it a star on GitHub!
|
||||||
|
|
||||||
|
## Links
|
||||||
|
|
||||||
|
- [Docker Hub Repository](https://hub.docker.com/r/amitserper/masto-rss)
|
||||||
|
- [GitHub Container Registry](https://github.com/aserper/masto-rss/pkgs/container/masto-rss)
|
||||||
|
- [Source Code](https://github.com/aserper/masto-rss)
|
||||||
|
- [Issues](https://github.com/aserper/masto-rss/issues)
|
||||||
|
|||||||
235
TESTING.md
Normal file
235
TESTING.md
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
# Testing Guide for Masto-RSS
|
||||||
|
|
||||||
|
This document describes the testing strategy and how to run tests for the Masto-RSS bot.
|
||||||
|
|
||||||
|
## Test Architecture
|
||||||
|
|
||||||
|
The test suite is organized into two main categories:
|
||||||
|
|
||||||
|
### Unit Tests ([test_bot.py](test_bot.py))
|
||||||
|
- Test individual functions and methods in isolation
|
||||||
|
- Use mocks and stubs for external dependencies
|
||||||
|
- Fast execution time
|
||||||
|
- High code coverage
|
||||||
|
- Test edge cases and error handling
|
||||||
|
|
||||||
|
### Integration Tests ([test_integration.py](test_integration.py))
|
||||||
|
- Test interactions between components
|
||||||
|
- Mock external services (RSS feeds, Mastodon API)
|
||||||
|
- Test end-to-end workflows
|
||||||
|
- Verify data persistence
|
||||||
|
- Test error recovery
|
||||||
|
|
||||||
|
## Running Tests Locally
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install test dependencies
|
||||||
|
pip install -r requirements-test.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run All Tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run all tests with coverage
|
||||||
|
pytest
|
||||||
|
|
||||||
|
# Run with verbose output
|
||||||
|
pytest -v
|
||||||
|
|
||||||
|
# Run with coverage report
|
||||||
|
pytest --cov=bot --cov=main --cov-report=html
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run Specific Test Categories
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run only unit tests
|
||||||
|
pytest test_bot.py
|
||||||
|
|
||||||
|
# Run only integration tests
|
||||||
|
pytest test_integration.py
|
||||||
|
|
||||||
|
# Run tests matching a pattern
|
||||||
|
pytest -k "test_parse_feed"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run with Markers
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run only unit tests (using markers)
|
||||||
|
pytest -m unit
|
||||||
|
|
||||||
|
# Run only integration tests
|
||||||
|
pytest -m integration
|
||||||
|
|
||||||
|
# Skip slow tests
|
||||||
|
pytest -m "not slow"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Coverage Reports
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Generate HTML coverage report
|
||||||
|
pytest --cov=bot --cov=main --cov-report=html
|
||||||
|
|
||||||
|
# View report
|
||||||
|
open htmlcov/index.html # macOS
|
||||||
|
xdg-open htmlcov/index.html # Linux
|
||||||
|
```
|
||||||
|
|
||||||
|
## GitHub Actions CI/CD
|
||||||
|
|
||||||
|
Tests run automatically on every push to `main` and on all pull requests via [.github/workflows/test.yml](.github/workflows/test.yml).
|
||||||
|
|
||||||
|
### Test Jobs
|
||||||
|
|
||||||
|
1. **Unit Tests**
|
||||||
|
- Runs on Python 3.10, 3.11, 3.12
|
||||||
|
- Executes all unit tests
|
||||||
|
- Uploads coverage to Codecov
|
||||||
|
|
||||||
|
2. **Integration Tests**
|
||||||
|
- Runs on Python 3.10, 3.11, 3.12
|
||||||
|
- Executes all integration tests with mocked external services
|
||||||
|
- Uploads coverage to Codecov
|
||||||
|
|
||||||
|
3. **Code Quality**
|
||||||
|
- Runs flake8 for linting
|
||||||
|
- Runs black for code formatting checks
|
||||||
|
- Runs mypy for type checking
|
||||||
|
|
||||||
|
4. **Docker Build Test**
|
||||||
|
- Builds the Docker image
|
||||||
|
- Verifies Python and dependencies are installed
|
||||||
|
- Ensures the image can run
|
||||||
|
|
||||||
|
5. **All Tests Pass**
|
||||||
|
- Final job that requires all previous jobs to succeed
|
||||||
|
- Provides a single status check for PR requirements
|
||||||
|
|
||||||
|
## Test Coverage Requirements
|
||||||
|
|
||||||
|
- **Minimum coverage**: 80%
|
||||||
|
- Coverage is measured for `bot.py` and `main.py`
|
||||||
|
- Test files are excluded from coverage metrics
|
||||||
|
|
||||||
|
## Code Quality Standards
|
||||||
|
|
||||||
|
### Flake8
|
||||||
|
- Maximum line length: 127 characters
|
||||||
|
- Maximum cyclomatic complexity: 10
|
||||||
|
- Critical error codes checked: E9, F63, F7, F82
|
||||||
|
|
||||||
|
### Black
|
||||||
|
- Line length: 88 characters (default)
|
||||||
|
- All Python files must pass black formatting
|
||||||
|
|
||||||
|
### Mypy
|
||||||
|
- Type hints encouraged but not required
|
||||||
|
- Runs in non-strict mode with missing imports ignored
|
||||||
|
|
||||||
|
## Test Data and Fixtures
|
||||||
|
|
||||||
|
### Mock RSS Feeds
|
||||||
|
Integration tests use realistic RSS 2.0 and Atom feed XML for testing feed parsing.
|
||||||
|
|
||||||
|
### Mock Mastodon API
|
||||||
|
The Mastodon API is mocked using `unittest.mock` to avoid making real API calls.
|
||||||
|
|
||||||
|
### Temporary State Files
|
||||||
|
Tests use `tempfile.mktemp()` to create temporary state files that are cleaned up after each test.
|
||||||
|
|
||||||
|
## Writing New Tests
|
||||||
|
|
||||||
|
### Unit Test Template
|
||||||
|
|
||||||
|
```python
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import Mock, patch
|
||||||
|
from bot import MastodonRSSBot
|
||||||
|
|
||||||
|
class TestNewFeature(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
"""Set up test fixtures"""
|
||||||
|
self.bot = MastodonRSSBot(
|
||||||
|
client_id='test',
|
||||||
|
client_secret='test',
|
||||||
|
access_token='test',
|
||||||
|
instance_url='https://test.com',
|
||||||
|
feed_url='https://feed.test/rss.xml',
|
||||||
|
state_file='/tmp/test_state.txt'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_feature(self):
|
||||||
|
"""Test description"""
|
||||||
|
result = self.bot.some_method()
|
||||||
|
self.assertEqual(result, expected_value)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Integration Test Template
|
||||||
|
|
||||||
|
```python
|
||||||
|
import unittest
|
||||||
|
import responses
|
||||||
|
from bot import MastodonRSSBot
|
||||||
|
|
||||||
|
class TestNewIntegration(unittest.TestCase):
|
||||||
|
@responses.activate
|
||||||
|
@patch('bot.Mastodon')
|
||||||
|
def test_integration(self, mock_mastodon):
|
||||||
|
"""Test description"""
|
||||||
|
# Mock HTTP responses
|
||||||
|
responses.add(
|
||||||
|
responses.GET,
|
||||||
|
'https://example.com/feed.xml',
|
||||||
|
body=rss_xml,
|
||||||
|
status=200
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run test
|
||||||
|
bot = MastodonRSSBot(...)
|
||||||
|
result = bot.process_new_entries()
|
||||||
|
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Continuous Integration Status
|
||||||
|
|
||||||
|
[](https://github.com/aserper/masto-rss/actions/workflows/test.yml)
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Tests Fail Locally But Pass in CI
|
||||||
|
- Ensure you're using the same Python version
|
||||||
|
- Check that all dependencies are installed: `pip install -r requirements-test.txt`
|
||||||
|
- Clear pytest cache: `pytest --cache-clear`
|
||||||
|
|
||||||
|
### Coverage Below 80%
|
||||||
|
- Identify untested code: `pytest --cov=bot --cov-report=term-missing`
|
||||||
|
- Add tests for the missing lines
|
||||||
|
- Some error handling paths may be acceptable to skip
|
||||||
|
|
||||||
|
### Import Errors
|
||||||
|
- Ensure the project root is in PYTHONPATH
|
||||||
|
- Run tests from the project root directory
|
||||||
|
- Check virtual environment is activated
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
1. **Test One Thing**: Each test should verify one specific behavior
|
||||||
|
2. **Clear Names**: Test names should describe what they're testing
|
||||||
|
3. **Arrange-Act-Assert**: Structure tests with setup, execution, and verification
|
||||||
|
4. **Mock External Services**: Never make real HTTP requests or API calls
|
||||||
|
5. **Clean Up**: Always clean up temporary files and state
|
||||||
|
6. **Test Edge Cases**: Test both happy paths and error conditions
|
||||||
|
7. **Keep Tests Fast**: Unit tests should run in milliseconds
|
||||||
|
8. **Document Complex Tests**: Add comments explaining non-obvious test logic
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
- [pytest documentation](https://docs.pytest.org/)
|
||||||
|
- [unittest.mock documentation](https://docs.python.org/3/library/unittest.mock.html)
|
||||||
|
- [responses library](https://github.com/getsentry/responses)
|
||||||
|
- [Coverage.py documentation](https://coverage.readthedocs.io/)
|
||||||
214
TEST_SUMMARY.md
Normal file
214
TEST_SUMMARY.md
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
# Test Implementation Summary
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Comprehensive test suite designed for the Masto-RSS bot with unit tests, integration tests, and automated CI/CD testing via GitHub Actions.
|
||||||
|
|
||||||
|
## Files Created
|
||||||
|
|
||||||
|
### 1. Core Refactoring
|
||||||
|
- **[bot.py](bot.py)** - Refactored core functionality into testable `MastodonRSSBot` class
|
||||||
|
- Separated concerns (parsing, posting, state management)
|
||||||
|
- Dependency injection for easier testing
|
||||||
|
- Error handling and logging
|
||||||
|
- Type hints for better code clarity
|
||||||
|
|
||||||
|
- **[main.py](main.py)** - Simplified entry point
|
||||||
|
- Loads configuration from environment
|
||||||
|
- Instantiates and runs the bot
|
||||||
|
- Clean separation from core logic
|
||||||
|
|
||||||
|
### 2. Test Files
|
||||||
|
|
||||||
|
#### [test_bot.py](test_bot.py) - Unit Tests
|
||||||
|
Contains **20+ unit tests** covering:
|
||||||
|
- Bot initialization with configuration
|
||||||
|
- Loading/saving processed entries (with and without existing files)
|
||||||
|
- Directory creation for state files
|
||||||
|
- Status formatting from feed entries
|
||||||
|
- Mastodon posting (success and failure cases)
|
||||||
|
- Feed parsing (success, errors, malformed data)
|
||||||
|
- Processing new entries (all new, partially processed, no entries)
|
||||||
|
- Handling entries without URLs
|
||||||
|
- Failed posts don't get marked as processed
|
||||||
|
- Main entry point configuration loading
|
||||||
|
|
||||||
|
**Coverage:** Core business logic, edge cases, error handling
|
||||||
|
|
||||||
|
#### [test_integration.py](test_integration.py) - Integration Tests
|
||||||
|
Contains **10+ integration tests** covering:
|
||||||
|
- End-to-end RSS to Mastodon flow
|
||||||
|
- Real RSS 2.0 feed parsing
|
||||||
|
- Real Atom feed parsing
|
||||||
|
- State persistence across bot runs
|
||||||
|
- Incremental feed updates (new entries added over time)
|
||||||
|
- Network error handling (500 errors, timeouts)
|
||||||
|
- Malformed XML handling
|
||||||
|
- Different visibility levels (public, unlisted, private, direct)
|
||||||
|
- Rate limiting error handling
|
||||||
|
- Retry mechanisms
|
||||||
|
|
||||||
|
**Coverage:** Component integration, external service mocking, data flow
|
||||||
|
|
||||||
|
### 3. Configuration Files
|
||||||
|
|
||||||
|
#### [pytest.ini](pytest.ini)
|
||||||
|
- Test discovery patterns
|
||||||
|
- Coverage settings (80% minimum)
|
||||||
|
- Output formatting
|
||||||
|
- Test markers (unit, integration, slow)
|
||||||
|
- Coverage exclusions
|
||||||
|
|
||||||
|
#### [requirements-test.txt](requirements-test.txt)
|
||||||
|
Test dependencies:
|
||||||
|
- `pytest` - Testing framework
|
||||||
|
- `pytest-cov` - Coverage plugin
|
||||||
|
- `pytest-mock` - Mocking utilities
|
||||||
|
- `responses` - HTTP mocking for integration tests
|
||||||
|
- `flake8` - Linting
|
||||||
|
- `black` - Code formatting
|
||||||
|
- `mypy` - Type checking
|
||||||
|
- `coverage` - Coverage reporting
|
||||||
|
|
||||||
|
#### [.gitignore](.gitignore)
|
||||||
|
Updated to exclude:
|
||||||
|
- Test artifacts (`.pytest_cache/`, `htmlcov/`, `coverage.xml`)
|
||||||
|
- Python cache files
|
||||||
|
- Virtual environments
|
||||||
|
- IDE configurations
|
||||||
|
|
||||||
|
### 4. CI/CD Pipeline
|
||||||
|
|
||||||
|
#### [.github/workflows/test.yml](.github/workflows/test.yml)
|
||||||
|
Comprehensive GitHub Actions workflow with **5 jobs**:
|
||||||
|
|
||||||
|
1. **Unit Tests**
|
||||||
|
- Runs on Python 3.10, 3.11, 3.12 (matrix)
|
||||||
|
- Executes unit tests with coverage
|
||||||
|
- Uploads coverage to Codecov
|
||||||
|
|
||||||
|
2. **Integration Tests**
|
||||||
|
- Runs on Python 3.10, 3.11, 3.12 (matrix)
|
||||||
|
- Executes integration tests
|
||||||
|
- Uploads coverage to Codecov
|
||||||
|
|
||||||
|
3. **Code Quality**
|
||||||
|
- Flake8 linting (error detection + complexity)
|
||||||
|
- Black formatting verification
|
||||||
|
- Mypy type checking
|
||||||
|
|
||||||
|
4. **Docker Build Test**
|
||||||
|
- Builds Docker image
|
||||||
|
- Verifies Python installation
|
||||||
|
- Checks dependencies are installed
|
||||||
|
|
||||||
|
5. **All Tests Pass**
|
||||||
|
- Requires all previous jobs to succeed
|
||||||
|
- Provides single status check for PRs
|
||||||
|
|
||||||
|
### 5. Documentation
|
||||||
|
|
||||||
|
#### [TESTING.md](TESTING.md)
|
||||||
|
Comprehensive testing guide covering:
|
||||||
|
- Test architecture explanation
|
||||||
|
- Running tests locally (all, specific, by marker)
|
||||||
|
- Coverage report generation
|
||||||
|
- GitHub Actions CI/CD workflow details
|
||||||
|
- Test coverage requirements (80% minimum)
|
||||||
|
- Code quality standards
|
||||||
|
- Writing new tests (templates provided)
|
||||||
|
- Troubleshooting common issues
|
||||||
|
- Best practices
|
||||||
|
|
||||||
|
#### [README.md](README.md)
|
||||||
|
Updated with:
|
||||||
|
- Test status badge
|
||||||
|
- Link to testing documentation
|
||||||
|
|
||||||
|
## Test Statistics
|
||||||
|
|
||||||
|
### Coverage Targets
|
||||||
|
- **Minimum:** 80% code coverage
|
||||||
|
- **Measured:** `bot.py` and `main.py`
|
||||||
|
- **Excluded:** Test files, virtual environments
|
||||||
|
|
||||||
|
### Test Count
|
||||||
|
- **Unit Tests:** 20+ tests
|
||||||
|
- **Integration Tests:** 10+ tests
|
||||||
|
- **Total:** 30+ tests
|
||||||
|
|
||||||
|
### Python Versions Tested
|
||||||
|
- Python 3.10
|
||||||
|
- Python 3.11
|
||||||
|
- Python 3.12
|
||||||
|
|
||||||
|
## Key Testing Features
|
||||||
|
|
||||||
|
### Mocking Strategy
|
||||||
|
- **Mastodon API:** Mocked using `unittest.mock` to avoid real API calls
|
||||||
|
- **RSS Feeds:** Mocked using `responses` library with realistic XML
|
||||||
|
- **File System:** Uses temporary files that are cleaned up automatically
|
||||||
|
|
||||||
|
### Test Data
|
||||||
|
- Realistic RSS 2.0 and Atom feed examples
|
||||||
|
- Multiple entry scenarios (new, processed, malformed)
|
||||||
|
- Error conditions (network failures, API errors, rate limits)
|
||||||
|
|
||||||
|
### Continuous Integration
|
||||||
|
- Runs on every push to `main`
|
||||||
|
- Runs on all pull requests
|
||||||
|
- Parallel test execution across Python versions
|
||||||
|
- Automatic coverage reporting
|
||||||
|
- Docker image validation
|
||||||
|
|
||||||
|
## Running Tests
|
||||||
|
|
||||||
|
### Locally
|
||||||
|
```bash
|
||||||
|
# Install dependencies
|
||||||
|
pip install -r requirements-test.txt
|
||||||
|
|
||||||
|
# Run all tests
|
||||||
|
pytest
|
||||||
|
|
||||||
|
# Run with coverage
|
||||||
|
pytest --cov=bot --cov=main --cov-report=html
|
||||||
|
|
||||||
|
# Run specific tests
|
||||||
|
pytest test_bot.py # Unit tests only
|
||||||
|
pytest test_integration.py # Integration tests only
|
||||||
|
```
|
||||||
|
|
||||||
|
### In CI/CD
|
||||||
|
Tests run automatically via GitHub Actions:
|
||||||
|
- **Trigger:** Push to main or pull request
|
||||||
|
- **Duration:** ~5-10 minutes
|
||||||
|
- **Matrix:** 3 Python versions × 2 test types = 6 parallel jobs
|
||||||
|
- **Plus:** Code quality and Docker build validation
|
||||||
|
|
||||||
|
## Benefits
|
||||||
|
|
||||||
|
1. **Code Quality:** Ensures all changes are tested before merging
|
||||||
|
2. **Regression Prevention:** Catches bugs before they reach production
|
||||||
|
3. **Documentation:** Tests serve as executable documentation
|
||||||
|
4. **Confidence:** Safe to refactor with comprehensive test coverage
|
||||||
|
5. **Type Safety:** Mypy catches type-related bugs early
|
||||||
|
6. **Code Style:** Black and flake8 enforce consistency
|
||||||
|
|
||||||
|
## Future Enhancements
|
||||||
|
|
||||||
|
Potential additions:
|
||||||
|
- Performance/load testing
|
||||||
|
- End-to-end tests with real Mastodon test instance
|
||||||
|
- Security scanning (Bandit, Safety)
|
||||||
|
- Mutation testing (mutmut)
|
||||||
|
- Property-based testing (Hypothesis)
|
||||||
|
- Contract testing for API interactions
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
|
||||||
|
- **Add tests** for all new features
|
||||||
|
- **Update tests** when changing behavior
|
||||||
|
- **Keep coverage above 80%**
|
||||||
|
- **Run tests before committing**
|
||||||
|
- **Review test failures** in CI before merging
|
||||||
212
bot.py
Normal file
212
bot.py
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
"""Mastodon RSS Bot - Core functionality"""
|
||||||
|
|
||||||
|
import feedparser
|
||||||
|
from mastodon import Mastodon
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
from typing import Set, Optional
|
||||||
|
|
||||||
|
|
||||||
|
class MastodonRSSBot:
|
||||||
|
"""Bot that monitors RSS feeds and posts updates to Mastodon"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
client_id: str,
|
||||||
|
client_secret: str,
|
||||||
|
access_token: str,
|
||||||
|
instance_url: str,
|
||||||
|
feed_urls: list[str],
|
||||||
|
toot_visibility: str = "public",
|
||||||
|
check_interval: int = 300,
|
||||||
|
state_file: str = "/state/processed_entries.txt",
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Initialize the Mastodon RSS bot.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
client_id: Mastodon application client ID
|
||||||
|
client_secret: Mastodon application client secret
|
||||||
|
access_token: Mastodon access token
|
||||||
|
instance_url: URL of the Mastodon instance
|
||||||
|
feed_urls: List of URLs of the RSS/Atom feeds to monitor
|
||||||
|
toot_visibility: Visibility level for posts ('public', 'unlisted', 'private', 'direct')
|
||||||
|
check_interval: Seconds between feed checks
|
||||||
|
state_file: Path to file storing processed entry URLs
|
||||||
|
"""
|
||||||
|
self.feed_urls = feed_urls
|
||||||
|
self.toot_visibility = toot_visibility
|
||||||
|
self.check_interval = check_interval
|
||||||
|
self.state_file = state_file
|
||||||
|
|
||||||
|
# Initialize Mastodon client
|
||||||
|
self.mastodon = Mastodon(
|
||||||
|
client_id=client_id,
|
||||||
|
client_secret=client_secret,
|
||||||
|
access_token=access_token,
|
||||||
|
api_base_url=instance_url,
|
||||||
|
)
|
||||||
|
|
||||||
|
def load_processed_entries(self) -> Set[str]:
|
||||||
|
"""
|
||||||
|
Load the set of processed entry URLs from the state file.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Set of URLs that have been processed
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
with open(self.state_file, "r") as file:
|
||||||
|
return set(file.read().splitlines())
|
||||||
|
except FileNotFoundError:
|
||||||
|
return set()
|
||||||
|
|
||||||
|
def save_processed_entries(self, processed_entries: Set[str]) -> None:
|
||||||
|
"""
|
||||||
|
Save the set of processed entry URLs to the state file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
processed_entries: Set of processed entry URLs
|
||||||
|
"""
|
||||||
|
# Ensure directory exists
|
||||||
|
os.makedirs(os.path.dirname(self.state_file), exist_ok=True)
|
||||||
|
|
||||||
|
with open(self.state_file, "w") as file:
|
||||||
|
file.write("\n".join(sorted(processed_entries)))
|
||||||
|
|
||||||
|
def parse_feed(self, feed_url: str) -> Optional[feedparser.FeedParserDict]:
|
||||||
|
"""
|
||||||
|
Parse the RSS feed.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
feed_url: URL of the feed to parse
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Parsed feed object or None if parsing fails
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
feed = feedparser.parse(feed_url)
|
||||||
|
if hasattr(feed, "bozo_exception"):
|
||||||
|
print(
|
||||||
|
f"Warning: Feed parsing issue for {feed_url}: {feed.bozo_exception}"
|
||||||
|
)
|
||||||
|
return feed
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error parsing feed {feed_url}: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def format_status(self, entry: feedparser.FeedParserDict) -> str:
|
||||||
|
"""
|
||||||
|
Format a feed entry as a Mastodon status.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
entry: Feed entry from feedparser
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Formatted status text
|
||||||
|
"""
|
||||||
|
title = entry.get("title", "Untitled")
|
||||||
|
link = entry.get("link", "")
|
||||||
|
return f"\n{title}\n\n{link}"
|
||||||
|
|
||||||
|
def post_to_mastodon(self, status: str) -> bool:
|
||||||
|
"""
|
||||||
|
Post a status to Mastodon.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
status: Status text to post
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if successful, False otherwise
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.mastodon.status_post(status, visibility=self.toot_visibility)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error posting to Mastodon: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def process_feed(self, feed_url: str, processed_entries: Set[str]) -> int:
|
||||||
|
"""
|
||||||
|
Process a single feed for new entries.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
feed_url: URL of the feed to process
|
||||||
|
processed_entries: Set of already processed entry URLs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Number of new entries posted
|
||||||
|
"""
|
||||||
|
print(f"Checking feed: {feed_url}")
|
||||||
|
feed = self.parse_feed(feed_url)
|
||||||
|
if not feed or not hasattr(feed, "entries"):
|
||||||
|
print(f"No entries found in feed: {feed_url}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
new_entries_count = 0
|
||||||
|
|
||||||
|
# Process each entry
|
||||||
|
for entry in feed.entries:
|
||||||
|
entry_url = entry.get("link", "")
|
||||||
|
|
||||||
|
if not entry_url:
|
||||||
|
print("Skipping entry without URL")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Check if entry is new
|
||||||
|
if entry_url not in processed_entries:
|
||||||
|
title = entry.get("title", "Untitled")
|
||||||
|
print(f"Found a new RSS item: {title}")
|
||||||
|
|
||||||
|
# Format and post status
|
||||||
|
status = self.format_status(entry)
|
||||||
|
if self.post_to_mastodon(status):
|
||||||
|
processed_entries.add(entry_url)
|
||||||
|
new_entries_count += 1
|
||||||
|
else:
|
||||||
|
print(f"Failed to post entry: {title}")
|
||||||
|
|
||||||
|
return new_entries_count
|
||||||
|
|
||||||
|
def process_new_entries(self) -> int:
|
||||||
|
"""
|
||||||
|
Check for new feed entries in all feeds and post them to Mastodon.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Total number of new entries posted across all feeds
|
||||||
|
"""
|
||||||
|
print("Checking for new RSS items...")
|
||||||
|
|
||||||
|
# Load processed entries
|
||||||
|
processed_entries = self.load_processed_entries()
|
||||||
|
|
||||||
|
total_new_entries = 0
|
||||||
|
|
||||||
|
for feed_url in self.feed_urls:
|
||||||
|
total_new_entries += self.process_feed(feed_url, processed_entries)
|
||||||
|
|
||||||
|
# Save updated state
|
||||||
|
if total_new_entries > 0:
|
||||||
|
self.save_processed_entries(processed_entries)
|
||||||
|
|
||||||
|
return total_new_entries
|
||||||
|
|
||||||
|
def run(self) -> None:
|
||||||
|
"""
|
||||||
|
Main loop: continuously monitor the feed and post new entries.
|
||||||
|
"""
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
count = self.process_new_entries()
|
||||||
|
if count > 0:
|
||||||
|
print(f"Posted {count} new entries")
|
||||||
|
|
||||||
|
print(f"Sleeping for {self.check_interval} seconds...")
|
||||||
|
time.sleep(self.check_interval)
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\nBot stopped by user")
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in main loop: {e}")
|
||||||
|
print(f"Retrying in {self.check_interval} seconds...")
|
||||||
|
time.sleep(self.check_interval)
|
||||||
BIN
header.jpg
Normal file
BIN
header.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 178 KiB |
127
main.py
127
main.py
@@ -1,74 +1,83 @@
|
|||||||
import feedparser
|
"""Mastodon RSS Bot - Entry point"""
|
||||||
from mastodon import Mastodon
|
|
||||||
import os
|
import os
|
||||||
import time
|
from bot import MastodonRSSBot
|
||||||
# Replace these with your Mastodon application details and access token
|
|
||||||
MASTODON_CLIENT_ID = os.environ['MASTODON_CLIENT_ID']
|
|
||||||
MASTODON_CLIENT_SECRET = os.environ['MASTODON_CLIENT_SECRET']
|
|
||||||
MASTODON_ACCESS_TOKEN = os.environ['MASTODON_ACCESS_TOKEN']
|
|
||||||
MASTODON_INSTANCE_URL = os.environ['MASTODON_INSTANCE_URL']
|
|
||||||
|
|
||||||
# RSS feed URL
|
|
||||||
RSS_FEED_URL = os.environ['RSS_FEED_URL']
|
|
||||||
|
|
||||||
# File to store the processed entry URLs
|
def main():
|
||||||
PROCESSED_ENTRIES_FILE = 'processed_entries.txt'
|
"""Initialize and run the bot with environment configuration"""
|
||||||
|
print("Starting Mastodon RSS Bot...")
|
||||||
|
|
||||||
# Time delay between RSS checks (in seconds)
|
# Load configuration from environment variables
|
||||||
CHECK_INTERVAL = os.environ['CHECK_INTERVAL'] # Check interval in seconds
|
feed_urls = []
|
||||||
|
|
||||||
# Initialize Mastodon client
|
# 1. Legacy single feed URL
|
||||||
mastodon = Mastodon(
|
if os.environ.get("RSS_FEED_URL"):
|
||||||
client_id=MASTODON_CLIENT_ID,
|
feed_urls.append(os.environ["RSS_FEED_URL"])
|
||||||
client_secret=MASTODON_CLIENT_SECRET,
|
|
||||||
access_token=MASTODON_ACCESS_TOKEN,
|
|
||||||
api_base_url=MASTODON_INSTANCE_URL
|
|
||||||
)
|
|
||||||
|
|
||||||
# Function to load processed entry URLs from a file
|
# 2. Comma-separated list of feeds
|
||||||
def load_processed_entries():
|
if os.environ.get("RSS_FEEDS"):
|
||||||
try:
|
feeds = [
|
||||||
with open(PROCESSED_ENTRIES_FILE, 'r') as file:
|
url.strip() for url in os.environ["RSS_FEEDS"].split(",") if url.strip()
|
||||||
return set(file.read().splitlines())
|
]
|
||||||
except FileNotFoundError:
|
feed_urls.extend(feeds)
|
||||||
return set()
|
|
||||||
|
|
||||||
# Function to save processed entry URLs to a file
|
# 3. File containing list of feeds
|
||||||
def save_processed_entries(processed_entries):
|
feeds_file = os.environ.get("FEEDS_FILE")
|
||||||
with open(PROCESSED_ENTRIES_FILE, 'w') as file:
|
if feeds_file and os.path.exists(feeds_file):
|
||||||
file.write('\n'.join(processed_entries))
|
try:
|
||||||
|
with open(feeds_file, "r") as f:
|
||||||
|
file_feeds = [
|
||||||
|
line.strip()
|
||||||
|
for line in f
|
||||||
|
if line.strip() and not line.startswith("#")
|
||||||
|
]
|
||||||
|
feed_urls.extend(file_feeds)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error reading feeds file {feeds_file}: {e}")
|
||||||
|
|
||||||
# Function to check and post new RSS items
|
# Deduplicate while preserving order
|
||||||
def check_and_post_new_items():
|
unique_feed_urls = []
|
||||||
while True:
|
seen = set()
|
||||||
print("Checking for new RSS items...")
|
for url in feed_urls:
|
||||||
# Load processed entry URLs from the file
|
if url not in seen:
|
||||||
processed_entries = load_processed_entries()
|
unique_feed_urls.append(url)
|
||||||
|
seen.add(url)
|
||||||
|
|
||||||
# Parse the RSS feed
|
if not unique_feed_urls:
|
||||||
feed = feedparser.parse(RSS_FEED_URL)
|
print(
|
||||||
|
"Error: No RSS feeds configured. Please set RSS_FEED_URL, RSS_FEEDS, or FEEDS_FILE."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
for entry in feed.entries:
|
bot = MastodonRSSBot(
|
||||||
entry_url = entry.link
|
client_id=os.environ["MASTODON_CLIENT_ID"],
|
||||||
|
client_secret=os.environ["MASTODON_CLIENT_SECRET"],
|
||||||
|
access_token=os.environ["MASTODON_ACCESS_TOKEN"],
|
||||||
|
instance_url=os.environ["MASTODON_INSTANCE_URL"],
|
||||||
|
feed_urls=unique_feed_urls,
|
||||||
|
toot_visibility=os.environ.get("TOOT_VISIBILITY", "public"),
|
||||||
|
check_interval=int(os.environ.get("CHECK_INTERVAL", "300")),
|
||||||
|
state_file=os.environ.get(
|
||||||
|
"PROCESSED_ENTRIES_FILE", "/state/processed_entries.txt"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
# Check if the entry is new (not in the processed_entries set)
|
print("Bot configured successfully:")
|
||||||
if entry_url not in processed_entries:
|
print(f" Instance: {os.environ['MASTODON_INSTANCE_URL']}")
|
||||||
print(f"Found a new RSS item: {entry.title}")
|
print(f" Monitoring {len(unique_feed_urls)} feed(s):")
|
||||||
# Create a Mastodon status
|
for url in unique_feed_urls:
|
||||||
status = f"\n{entry.title}\n\n{entry.link}"
|
print(f" - {url}")
|
||||||
|
print(f" Visibility: {os.environ.get('TOOT_VISIBILITY', 'public')}")
|
||||||
|
print(f" Check interval: {os.environ.get('CHECK_INTERVAL', '300')} seconds")
|
||||||
|
print(
|
||||||
|
f" State file: {os.environ.get('PROCESSED_ENTRIES_FILE', '/state/processed_entries.txt')}"
|
||||||
|
)
|
||||||
|
print()
|
||||||
|
|
||||||
# Post the status to Mastodon
|
# Start the bot
|
||||||
mastodon.status_post(status)
|
bot.run()
|
||||||
|
|
||||||
# Add the entry URL to the processed_entries set
|
|
||||||
processed_entries.add(entry_url)
|
|
||||||
|
|
||||||
# Save the updated processed_entries set to the file
|
|
||||||
save_processed_entries(processed_entries)
|
|
||||||
|
|
||||||
print("Sleeping for", CHECK_INTERVAL, "seconds...")
|
|
||||||
# Wait for the specified interval before checking again
|
|
||||||
time.sleep(int(CHECK_INTERVAL))
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
check_and_post_new_items()
|
main()
|
||||||
|
|||||||
46
pytest.ini
Normal file
46
pytest.ini
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
[pytest]
|
||||||
|
# Pytest configuration for Masto-RSS
|
||||||
|
|
||||||
|
# Test discovery patterns
|
||||||
|
python_files = test_*.py
|
||||||
|
python_classes = Test*
|
||||||
|
python_functions = test_*
|
||||||
|
|
||||||
|
# Output options
|
||||||
|
addopts =
|
||||||
|
-v
|
||||||
|
--strict-markers
|
||||||
|
--tb=short
|
||||||
|
--cov=bot
|
||||||
|
--cov=main
|
||||||
|
--cov-report=term-missing
|
||||||
|
--cov-report=html
|
||||||
|
--cov-report=xml
|
||||||
|
--cov-fail-under=80
|
||||||
|
|
||||||
|
# Test paths
|
||||||
|
testpaths = .
|
||||||
|
|
||||||
|
# Markers
|
||||||
|
markers =
|
||||||
|
unit: Unit tests that don't require external services
|
||||||
|
integration: Integration tests that may use mocked external services
|
||||||
|
slow: Tests that take a long time to run
|
||||||
|
|
||||||
|
# Coverage options
|
||||||
|
[coverage:run]
|
||||||
|
source = .
|
||||||
|
omit =
|
||||||
|
test_*.py
|
||||||
|
.venv/*
|
||||||
|
*/__pycache__/*
|
||||||
|
*/site-packages/*
|
||||||
|
|
||||||
|
[coverage:report]
|
||||||
|
exclude_lines =
|
||||||
|
pragma: no cover
|
||||||
|
def __repr__
|
||||||
|
raise AssertionError
|
||||||
|
raise NotImplementedError
|
||||||
|
if __name__ == .__main__.:
|
||||||
|
if TYPE_CHECKING:
|
||||||
19
requirements-test.txt
Normal file
19
requirements-test.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Test dependencies for Masto-RSS bot
|
||||||
|
# Updated to latest versions (2025-12-12)
|
||||||
|
# Install with: pip install -r requirements-test.txt
|
||||||
|
|
||||||
|
# Base requirements
|
||||||
|
-r requirements.txt
|
||||||
|
|
||||||
|
# Testing framework
|
||||||
|
pytest==9.0.2
|
||||||
|
pytest-cov==6.0.0
|
||||||
|
pytest-mock==3.14.0
|
||||||
|
|
||||||
|
# Code quality
|
||||||
|
flake8==7.1.1
|
||||||
|
black==25.12.0
|
||||||
|
mypy==1.19.0
|
||||||
|
|
||||||
|
# Coverage reporting
|
||||||
|
coverage==7.6.12
|
||||||
2
requirements.in
Normal file
2
requirements.in
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
feedparser==6.0.11
|
||||||
|
Mastodon.py==1.8.1
|
||||||
@@ -1,2 +1,32 @@
|
|||||||
mastodon.py
|
#
|
||||||
feedparser
|
# Updated dependencies to latest versions (2025-12-12)
|
||||||
|
# Major updates: Mastodon.py 1.8.1 -> 2.1.4, requests 2.32.2 -> 2.32.5
|
||||||
|
#
|
||||||
|
blurhash==1.1.4
|
||||||
|
# via mastodon-py
|
||||||
|
certifi==2025.11.12
|
||||||
|
# via requests
|
||||||
|
charset-normalizer==3.3.2
|
||||||
|
# via requests
|
||||||
|
decorator==5.1.1
|
||||||
|
# via mastodon-py
|
||||||
|
feedparser==6.0.12
|
||||||
|
# via -r requirements.in
|
||||||
|
idna==3.11
|
||||||
|
# via requests
|
||||||
|
mastodon-py==2.1.4
|
||||||
|
# via -r requirements.in
|
||||||
|
python-dateutil==2.9.0.post0
|
||||||
|
# via mastodon-py
|
||||||
|
python-magic==0.4.27
|
||||||
|
# via mastodon-py
|
||||||
|
requests==2.32.5
|
||||||
|
# via mastodon-py
|
||||||
|
sgmllib3k==1.0.0
|
||||||
|
# via feedparser
|
||||||
|
six==1.16.0
|
||||||
|
# via
|
||||||
|
# mastodon-py
|
||||||
|
# python-dateutil
|
||||||
|
urllib3==2.6.2
|
||||||
|
# via requests
|
||||||
|
|||||||
418
test_bot.py
Normal file
418
test_bot.py
Normal file
@@ -0,0 +1,418 @@
|
|||||||
|
"""Unit tests for Mastodon RSS Bot"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import Mock, patch, mock_open, MagicMock
|
||||||
|
import tempfile
|
||||||
|
import os
|
||||||
|
from bot import MastodonRSSBot
|
||||||
|
import feedparser
|
||||||
|
|
||||||
|
|
||||||
|
class TestMastodonRSSBot(unittest.TestCase):
|
||||||
|
"""Test cases for MastodonRSSBot class"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
"""Set up test fixtures"""
|
||||||
|
self.test_config = {
|
||||||
|
"client_id": "test_client_id",
|
||||||
|
"client_secret": "test_client_secret",
|
||||||
|
"access_token": "test_access_token",
|
||||||
|
"instance_url": "https://mastodon.test",
|
||||||
|
"feed_urls": ["https://example.com/feed.xml"],
|
||||||
|
"toot_visibility": "public",
|
||||||
|
"check_interval": 60,
|
||||||
|
"state_file": tempfile.mktemp(),
|
||||||
|
}
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
"""Clean up test files"""
|
||||||
|
if os.path.exists(self.test_config["state_file"]):
|
||||||
|
os.remove(self.test_config["state_file"])
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_bot_initialization(self, mock_mastodon):
|
||||||
|
"""Test bot initializes with correct configuration"""
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
|
||||||
|
self.assertEqual(bot.feed_urls, self.test_config["feed_urls"])
|
||||||
|
self.assertEqual(bot.toot_visibility, self.test_config["toot_visibility"])
|
||||||
|
self.assertEqual(bot.check_interval, self.test_config["check_interval"])
|
||||||
|
self.assertEqual(bot.state_file, self.test_config["state_file"])
|
||||||
|
|
||||||
|
# Verify Mastodon client was initialized correctly
|
||||||
|
mock_mastodon.assert_called_once_with(
|
||||||
|
client_id=self.test_config["client_id"],
|
||||||
|
client_secret=self.test_config["client_secret"],
|
||||||
|
access_token=self.test_config["access_token"],
|
||||||
|
api_base_url=self.test_config["instance_url"],
|
||||||
|
)
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_load_processed_entries_empty(self, mock_mastodon):
|
||||||
|
"""Test loading processed entries from non-existent file returns empty set"""
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
entries = bot.load_processed_entries()
|
||||||
|
|
||||||
|
self.assertEqual(entries, set())
|
||||||
|
self.assertIsInstance(entries, set)
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_load_processed_entries_existing(self, mock_mastodon):
|
||||||
|
"""Test loading processed entries from existing file"""
|
||||||
|
# Create a temporary file with test data
|
||||||
|
test_urls = [
|
||||||
|
"https://example.com/1",
|
||||||
|
"https://example.com/2",
|
||||||
|
"https://example.com/3",
|
||||||
|
]
|
||||||
|
with open(self.test_config["state_file"], "w") as f:
|
||||||
|
f.write("\n".join(test_urls))
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
entries = bot.load_processed_entries()
|
||||||
|
|
||||||
|
self.assertEqual(entries, set(test_urls))
|
||||||
|
self.assertEqual(len(entries), 3)
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_save_processed_entries(self, mock_mastodon):
|
||||||
|
"""Test saving processed entries to file"""
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
test_entries = {
|
||||||
|
"https://example.com/1",
|
||||||
|
"https://example.com/2",
|
||||||
|
"https://example.com/3",
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.save_processed_entries(test_entries)
|
||||||
|
|
||||||
|
# Verify file was created and contains correct data
|
||||||
|
self.assertTrue(os.path.exists(self.test_config["state_file"]))
|
||||||
|
|
||||||
|
with open(self.test_config["state_file"], "r") as f:
|
||||||
|
saved_entries = set(f.read().splitlines())
|
||||||
|
|
||||||
|
self.assertEqual(saved_entries, test_entries)
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_save_processed_entries_creates_directory(self, mock_mastodon):
|
||||||
|
"""Test that saving entries creates directory if it doesn't exist"""
|
||||||
|
# Use a path with a non-existent directory
|
||||||
|
test_dir = tempfile.mkdtemp()
|
||||||
|
nested_path = os.path.join(test_dir, "subdir", "state.txt")
|
||||||
|
self.test_config["state_file"] = nested_path
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
bot.save_processed_entries({"https://example.com/1"})
|
||||||
|
|
||||||
|
self.assertTrue(os.path.exists(nested_path))
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
shutil.rmtree(test_dir)
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_format_status(self, mock_mastodon):
|
||||||
|
"""Test status formatting from feed entry"""
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
|
||||||
|
entry = {"title": "Test Article", "link": "https://example.com/article"}
|
||||||
|
|
||||||
|
status = bot.format_status(entry)
|
||||||
|
expected = "\nTest Article\n\nhttps://example.com/article"
|
||||||
|
|
||||||
|
self.assertEqual(status, expected)
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_format_status_missing_title(self, mock_mastodon):
|
||||||
|
"""Test status formatting with missing title"""
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
|
||||||
|
entry = {"link": "https://example.com/article"}
|
||||||
|
status = bot.format_status(entry)
|
||||||
|
|
||||||
|
self.assertIn("Untitled", status)
|
||||||
|
self.assertIn("https://example.com/article", status)
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_post_to_mastodon_success(self, mock_mastodon):
|
||||||
|
"""Test successful posting to Mastodon"""
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
result = bot.post_to_mastodon("Test status")
|
||||||
|
|
||||||
|
self.assertTrue(result)
|
||||||
|
mock_instance.status_post.assert_called_once_with(
|
||||||
|
"Test status", visibility=self.test_config["toot_visibility"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_post_to_mastodon_failure(self, mock_mastodon):
|
||||||
|
"""Test handling of Mastodon posting failure"""
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_instance.status_post.side_effect = Exception("API Error")
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
result = bot.post_to_mastodon("Test status")
|
||||||
|
|
||||||
|
self.assertFalse(result)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_parse_feed_success(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test successful feed parsing"""
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = [{"title": "Test", "link": "https://example.com"}]
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
feed = bot.parse_feed("https://example.com/feed.xml")
|
||||||
|
|
||||||
|
self.assertIsNotNone(feed)
|
||||||
|
mock_parse.assert_called_once_with("https://example.com/feed.xml")
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_parse_feed_with_exception(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test feed parsing with exception"""
|
||||||
|
mock_parse.side_effect = Exception("Network error")
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
feed = bot.parse_feed("https://example.com/feed.xml")
|
||||||
|
|
||||||
|
self.assertIsNone(feed)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_process_new_entries_no_entries(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test processing when feed has no entries"""
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = []
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
self.assertEqual(count, 0)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_process_new_entries_all_new(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test processing with all new entries"""
|
||||||
|
# Mock feed with 3 entries
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = [
|
||||||
|
{"title": "Article 1", "link": "https://example.com/1"},
|
||||||
|
{"title": "Article 2", "link": "https://example.com/2"},
|
||||||
|
{"title": "Article 3", "link": "https://example.com/3"},
|
||||||
|
]
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
# Mock Mastodon instance
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
self.assertEqual(count, 3)
|
||||||
|
self.assertEqual(mock_instance.status_post.call_count, 3)
|
||||||
|
|
||||||
|
# Verify entries were saved
|
||||||
|
saved_entries = bot.load_processed_entries()
|
||||||
|
self.assertEqual(len(saved_entries), 3)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_process_new_entries_multiple_feeds(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test processing with multiple feeds"""
|
||||||
|
self.test_config["feed_urls"] = ["http://feed1.com", "http://feed2.com"]
|
||||||
|
|
||||||
|
def side_effect(url):
|
||||||
|
mock = Mock()
|
||||||
|
if url == "http://feed1.com":
|
||||||
|
mock.entries = [{"title": "1", "link": "http://link1.com"}]
|
||||||
|
else:
|
||||||
|
mock.entries = [{"title": "2", "link": "http://link2.com"}]
|
||||||
|
return mock
|
||||||
|
|
||||||
|
mock_parse.side_effect = side_effect
|
||||||
|
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
self.assertEqual(count, 2)
|
||||||
|
self.assertEqual(mock_parse.call_count, 2)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_process_new_entries_some_processed(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test processing with some entries already processed"""
|
||||||
|
# Pre-populate processed entries
|
||||||
|
processed = {"https://example.com/1", "https://example.com/2"}
|
||||||
|
with open(self.test_config["state_file"], "w") as f:
|
||||||
|
f.write("\n".join(processed))
|
||||||
|
|
||||||
|
# Mock feed with 4 entries (2 old, 2 new)
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = [
|
||||||
|
{
|
||||||
|
"title": "Article 1",
|
||||||
|
"link": "https://example.com/1",
|
||||||
|
}, # Already processed
|
||||||
|
{
|
||||||
|
"title": "Article 2",
|
||||||
|
"link": "https://example.com/2",
|
||||||
|
}, # Already processed
|
||||||
|
{"title": "Article 3", "link": "https://example.com/3"}, # New
|
||||||
|
{"title": "Article 4", "link": "https://example.com/4"}, # New
|
||||||
|
]
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
# Mock Mastodon instance
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
# Should only post 2 new entries
|
||||||
|
self.assertEqual(count, 2)
|
||||||
|
self.assertEqual(mock_instance.status_post.call_count, 2)
|
||||||
|
|
||||||
|
# Verify all 4 entries are now in processed list
|
||||||
|
saved_entries = bot.load_processed_entries()
|
||||||
|
self.assertEqual(len(saved_entries), 4)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_process_new_entries_skip_no_url(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test that entries without URLs are skipped"""
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = [
|
||||||
|
{"title": "Article without URL"}, # No link field
|
||||||
|
{"title": "Article with URL", "link": "https://example.com/1"},
|
||||||
|
]
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
# Should only process 1 entry (the one with URL)
|
||||||
|
self.assertEqual(count, 1)
|
||||||
|
self.assertEqual(mock_instance.status_post.call_count, 1)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_process_new_entries_posting_failure(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test that failed posts don't get marked as processed"""
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = [
|
||||||
|
{"title": "Article 1", "link": "https://example.com/1"},
|
||||||
|
]
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
# Mock Mastodon to fail
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_instance.status_post.side_effect = Exception("API Error")
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
# No entries should be counted as posted
|
||||||
|
self.assertEqual(count, 0)
|
||||||
|
|
||||||
|
# Entry should not be marked as processed
|
||||||
|
saved_entries = bot.load_processed_entries()
|
||||||
|
self.assertEqual(len(saved_entries), 0)
|
||||||
|
|
||||||
|
|
||||||
|
class TestMainEntry(unittest.TestCase):
|
||||||
|
"""Test cases for main.py entry point"""
|
||||||
|
|
||||||
|
@patch.dict(
|
||||||
|
os.environ,
|
||||||
|
{
|
||||||
|
"MASTODON_CLIENT_ID": "test_id",
|
||||||
|
"MASTODON_CLIENT_SECRET": "test_secret",
|
||||||
|
"MASTODON_ACCESS_TOKEN": "test_token",
|
||||||
|
"MASTODON_INSTANCE_URL": "https://mastodon.test",
|
||||||
|
"RSS_FEED_URL": "https://example.com/feed.xml",
|
||||||
|
"TOOT_VISIBILITY": "unlisted",
|
||||||
|
"CHECK_INTERVAL": "120",
|
||||||
|
"PROCESSED_ENTRIES_FILE": "/tmp/test_state.txt",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
@patch("main.MastodonRSSBot")
|
||||||
|
def test_main_loads_legacy_environment_config(self, mock_bot_class):
|
||||||
|
"""Test that main() loads configuration from legacy environment variable"""
|
||||||
|
from main import main
|
||||||
|
|
||||||
|
mock_bot_instance = Mock()
|
||||||
|
mock_bot_class.return_value = mock_bot_instance
|
||||||
|
|
||||||
|
# Call main (but it will try to run, so we need to handle that)
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except Exception:
|
||||||
|
pass # Expected since we're mocking
|
||||||
|
|
||||||
|
# Verify bot was created with correct config
|
||||||
|
mock_bot_class.assert_called_once_with(
|
||||||
|
client_id="test_id",
|
||||||
|
client_secret="test_secret",
|
||||||
|
access_token="test_token",
|
||||||
|
instance_url="https://mastodon.test",
|
||||||
|
feed_urls=["https://example.com/feed.xml"],
|
||||||
|
toot_visibility="unlisted",
|
||||||
|
check_interval=120,
|
||||||
|
state_file="/tmp/test_state.txt",
|
||||||
|
)
|
||||||
|
|
||||||
|
@patch.dict(
|
||||||
|
os.environ,
|
||||||
|
{
|
||||||
|
"MASTODON_CLIENT_ID": "test_id",
|
||||||
|
"MASTODON_CLIENT_SECRET": "test_secret",
|
||||||
|
"MASTODON_ACCESS_TOKEN": "test_token",
|
||||||
|
"MASTODON_INSTANCE_URL": "https://mastodon.test",
|
||||||
|
"RSS_FEEDS": "http://feed1.com, http://feed2.com",
|
||||||
|
# No RSS_FEED_URL
|
||||||
|
"TOOT_VISIBILITY": "public",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
@patch("main.MastodonRSSBot")
|
||||||
|
def test_main_loads_multiple_feeds_env(self, mock_bot_class):
|
||||||
|
"""Test that main() loads multiple feeds from environment variable"""
|
||||||
|
# Ensure RSS_FEED_URL is not set from previous tests or env
|
||||||
|
if "RSS_FEED_URL" in os.environ:
|
||||||
|
del os.environ["RSS_FEED_URL"]
|
||||||
|
|
||||||
|
from main import main
|
||||||
|
|
||||||
|
mock_bot_instance = Mock()
|
||||||
|
mock_bot_class.return_value = mock_bot_instance
|
||||||
|
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
mock_bot_class.assert_called_once()
|
||||||
|
_, kwargs = mock_bot_class.call_args
|
||||||
|
self.assertEqual(kwargs["feed_urls"], ["http://feed1.com", "http://feed2.com"])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
244
test_integration.py
Normal file
244
test_integration.py
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
"""Integration tests for Mastodon RSS Bot"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import Mock, patch
|
||||||
|
import tempfile
|
||||||
|
import os
|
||||||
|
from bot import MastodonRSSBot
|
||||||
|
|
||||||
|
|
||||||
|
class TestRSSFeedIntegration(unittest.TestCase):
|
||||||
|
"""Integration tests for RSS feed parsing"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
"""Set up test fixtures"""
|
||||||
|
self.test_config = {
|
||||||
|
"client_id": "test_client_id",
|
||||||
|
"client_secret": "test_client_secret",
|
||||||
|
"access_token": "test_access_token",
|
||||||
|
"instance_url": "https://mastodon.test",
|
||||||
|
"feed_urls": ["https://example.com/feed.xml"],
|
||||||
|
"toot_visibility": "public",
|
||||||
|
"check_interval": 1,
|
||||||
|
"state_file": tempfile.mktemp(),
|
||||||
|
}
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
"""Clean up test files"""
|
||||||
|
if os.path.exists(self.test_config["state_file"]):
|
||||||
|
os.remove(self.test_config["state_file"])
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_end_to_end_rss_to_mastodon(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test complete flow from RSS feed to Mastodon post"""
|
||||||
|
# Create mock feed object
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = [
|
||||||
|
{"title": "First Article", "link": "https://example.com/article1"},
|
||||||
|
{"title": "Second Article", "link": "https://example.com/article2"},
|
||||||
|
]
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
# Mock Mastodon instance
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
# Create bot and process entries
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
# Verify results
|
||||||
|
self.assertEqual(count, 2)
|
||||||
|
self.assertEqual(mock_instance.status_post.call_count, 2)
|
||||||
|
|
||||||
|
# Verify the content of posts
|
||||||
|
calls = mock_instance.status_post.call_args_list
|
||||||
|
self.assertIn("First Article", calls[0][0][0])
|
||||||
|
self.assertIn("https://example.com/article1", calls[0][0][0])
|
||||||
|
self.assertIn("Second Article", calls[1][0][0])
|
||||||
|
self.assertIn("https://example.com/article2", calls[1][0][0])
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_atom_feed_parsing(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test parsing Atom feeds"""
|
||||||
|
# Create mock Atom feed object
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = [
|
||||||
|
{"title": "Atom Article", "link": "https://example.com/atom1"}
|
||||||
|
]
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
self.assertEqual(count, 1)
|
||||||
|
calls = mock_instance.status_post.call_args_list
|
||||||
|
self.assertIn("Atom Article", calls[0][0][0])
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_persistence_across_runs(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test that processed entries persist across multiple bot runs"""
|
||||||
|
# Create mock feed object
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = [{"title": "Article 1", "link": "https://example.com/1"}]
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
# First run - should post the article
|
||||||
|
bot1 = MastodonRSSBot(**self.test_config)
|
||||||
|
count1 = bot1.process_new_entries()
|
||||||
|
self.assertEqual(count1, 1)
|
||||||
|
|
||||||
|
# Second run - should NOT post again (already processed)
|
||||||
|
bot2 = MastodonRSSBot(**self.test_config)
|
||||||
|
count2 = bot2.process_new_entries()
|
||||||
|
self.assertEqual(count2, 0)
|
||||||
|
|
||||||
|
# Total posts should be 1
|
||||||
|
self.assertEqual(mock_instance.status_post.call_count, 1)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_incremental_feed_updates(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test handling of new entries added to feed over time"""
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
# First run - initial feed with 2 articles
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = [
|
||||||
|
{"title": "Article 1", "link": "https://example.com/1"},
|
||||||
|
{"title": "Article 2", "link": "https://example.com/2"},
|
||||||
|
]
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count1 = bot.process_new_entries()
|
||||||
|
self.assertEqual(count1, 2)
|
||||||
|
|
||||||
|
# Second run - updated feed with 1 new article
|
||||||
|
mock_feed.entries = [
|
||||||
|
{"title": "Article 3", "link": "https://example.com/3"},
|
||||||
|
{"title": "Article 2", "link": "https://example.com/2"},
|
||||||
|
{"title": "Article 1", "link": "https://example.com/1"},
|
||||||
|
]
|
||||||
|
|
||||||
|
# Second run - should only post the new article
|
||||||
|
count2 = bot.process_new_entries()
|
||||||
|
self.assertEqual(count2, 1)
|
||||||
|
|
||||||
|
# Verify only 3 total posts
|
||||||
|
self.assertEqual(mock_instance.status_post.call_count, 3)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_network_error_handling(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test handling of network errors when fetching feed"""
|
||||||
|
# Simulate network error by returning None
|
||||||
|
mock_parse.return_value = None
|
||||||
|
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
# Should handle error gracefully
|
||||||
|
self.assertEqual(count, 0)
|
||||||
|
self.assertEqual(mock_instance.status_post.call_count, 0)
|
||||||
|
|
||||||
|
@patch("bot.feedparser.parse")
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_malformed_xml_handling(self, mock_mastodon, mock_parse):
|
||||||
|
"""Test handling of malformed XML feeds"""
|
||||||
|
# Create mock feed with bozo_exception (feedparser's error indicator)
|
||||||
|
mock_feed = Mock()
|
||||||
|
mock_feed.entries = []
|
||||||
|
mock_feed.bozo_exception = Exception("XML parsing error")
|
||||||
|
mock_parse.return_value = mock_feed
|
||||||
|
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
# Should handle malformed feed gracefully
|
||||||
|
count = bot.process_new_entries()
|
||||||
|
|
||||||
|
# feedparser is lenient and may parse some entries
|
||||||
|
# The important thing is it doesn't crash
|
||||||
|
self.assertIsInstance(count, int)
|
||||||
|
|
||||||
|
|
||||||
|
class TestMastodonAPIIntegration(unittest.TestCase):
|
||||||
|
"""Integration tests for Mastodon API interaction"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
"""Set up test fixtures"""
|
||||||
|
self.test_config = {
|
||||||
|
"client_id": "test_client_id",
|
||||||
|
"client_secret": "test_client_secret",
|
||||||
|
"access_token": "test_access_token",
|
||||||
|
"instance_url": "https://mastodon.test",
|
||||||
|
"feed_urls": ["https://example.com/feed.xml"],
|
||||||
|
"toot_visibility": "public",
|
||||||
|
"check_interval": 1,
|
||||||
|
"state_file": tempfile.mktemp(),
|
||||||
|
}
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
"""Clean up test files"""
|
||||||
|
if os.path.exists(self.test_config["state_file"]):
|
||||||
|
os.remove(self.test_config["state_file"])
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_different_visibility_levels(self, mock_mastodon):
|
||||||
|
"""Test posting with different visibility levels"""
|
||||||
|
mock_instance = Mock()
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
visibility_levels = ["public", "unlisted", "private", "direct"]
|
||||||
|
|
||||||
|
for visibility in visibility_levels:
|
||||||
|
self.test_config["toot_visibility"] = visibility
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
bot.post_to_mastodon("Test status")
|
||||||
|
|
||||||
|
# Verify all visibility levels were used
|
||||||
|
calls = mock_instance.status_post.call_args_list
|
||||||
|
for idx, visibility in enumerate(visibility_levels):
|
||||||
|
self.assertEqual(calls[idx][1]["visibility"], visibility)
|
||||||
|
|
||||||
|
@patch("bot.Mastodon")
|
||||||
|
def test_retry_on_rate_limit(self, mock_mastodon):
|
||||||
|
"""Test that rate limit errors are handled appropriately"""
|
||||||
|
from mastodon import MastodonRatelimitError
|
||||||
|
|
||||||
|
mock_instance = Mock()
|
||||||
|
# First call raises rate limit error, second succeeds
|
||||||
|
mock_instance.status_post.side_effect = [
|
||||||
|
MastodonRatelimitError("Rate limited"),
|
||||||
|
None,
|
||||||
|
]
|
||||||
|
mock_mastodon.return_value = mock_instance
|
||||||
|
|
||||||
|
bot = MastodonRSSBot(**self.test_config)
|
||||||
|
|
||||||
|
# First attempt should fail
|
||||||
|
result1 = bot.post_to_mastodon("Test status")
|
||||||
|
self.assertFalse(result1)
|
||||||
|
|
||||||
|
# Second attempt should succeed
|
||||||
|
result2 = bot.post_to_mastodon("Test status")
|
||||||
|
self.assertTrue(result2)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user