8000 Adjust JobStores for PTB v20.4 (#91) · python-telegram-bot/ptbcontrib@29189d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 29189d8

Browse files
authored
Adjust JobStores for PTB v20.4 (#91)
1 parent c111451 commit 29189d8

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,8 @@ jobs:
1313
runs-on: ${{matrix.os}}
1414
strategy:
1515
matrix:
16-
python-version: ["3.7", "3.8", "3.9", "3.10"]
16+
python-version: ["3.8", "3.9", "3.10"]
1717
os: [ubuntu-latest, windows-latest, macos-latest]
18-
include:
19-
- os: ubuntu-latest
20-
python-version: 3.7
21-
test-build: True
22-
- os: windows-latest
23-
python-version: 3.7
24-
test-build: True
2518
fail-fast: False
2619
steps:
2720
- uses: actions/checkout@v3

ptbcontrib/ptb_jobstores/ptb_adapter.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ def _prepare_job(job: APSJob) -> APSJob:
5454
prepped_job = APSJob.__new__(APSJob)
5555
prepped_job.__setstate__(job.__getstate__())
5656
# Get the tg_job instance in memory
57-
# or the one that we deserialized during _reconstitute (first arg in args)
58-
if len(job.args) == 1:
59-
tg_job = Job._from_aps_job(job) # pylint: disable=W0212
60-
else:
61-
tg_job = job.args[0]
57+
tg_job = Job.from_aps_job(job)
6258
# Extract relevant information from the job and
6359
# store it in the job's args.
6460
prepped_job.args = (
@@ -86,8 +82,8 @@ def _restore_job(self, job: APSJob) -> APSJob:
8682
)
8783
job._modify( # pylint: disable=W0212
8884
args=(
85+
self.application.job_queue,
8986
tg_job,
90-
self.application,
9187
)
9288
)
9389
return job
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
python-telegram-bot[job-queue]>=20.0,<=21.0
1+
python-telegram-bot[job-queue]~=20.4
22
pymongo>=4.1,<5
33
SQLAlchemy~=1.4.46

tests/test_ptb_jobstores.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import apscheduler.triggers.interval
2525
import pytest
26-
from telegram.ext import CallbackContext, JobQueue
26+
from telegram.ext import ApplicationBuilder, CallbackContext, JobQueue
2727

2828
from ptbcontrib.ptb_jobstores import PTBMongoDBJobStore, PTBSQLAlchemyJobStore # noqa: E402
2929

@@ -42,13 +42,15 @@
4242
params=job_queue_params,
4343
ids=job_queue_param_ids,
4444
)
45-
async def jq(app, request):
45+
async def jq(request, bot):
4646
jq = JobQueue()
47-
jq.set_application(app)
47+
app = ApplicationBuilder().bot(bot).job_queue(jq).build()
4848
job_store = request.param[0](application=app, **request.param[1])
4949
jq.scheduler.add_jobstore(job_store)
5050
await jq.start()
5151
yield jq
52+
if isinstance(job_store, PTBMongoDBJobStore):
53+
job_store.remove_all_jobs()
5254
await jq.stop()
5355

5456

@@ -80,10 +82,11 @@ def test_next_runtime(self, jq, jobstore):
8082

8183
def test_lookup_job(self, jq, jobstore):
8284
initial_job = jq.run_once(dummy_job, 1)
83-
job = jobstore.lookup_job(initial_job.id)
84-
assert job == initial_job.job
85-
assert job.name == initial_job.job.name
86-
assert job.args[0].callback is initial_job.callback is dummy_job
85+
aps_job = jobstore.lookup_job(initial_job.id)
86+
assert aps_job == initial_job.job
87+
assert aps_job.name == initial_job.job.name
88+
assert aps_job.args[0] is jq
89+
assert aps_job.args[1].callback is initial_job.callback is dummy_job
8790

8891
def test_non_existent_job(self, jobstore):
8992
assert jobstore.lookup_job("foo") is None

0 commit comments

Comments
 (0)
0