Commit Graph

523 Commits

Author SHA1 Message Date
Alexei Yatskov
113dc50e3a
Merge pull request #334 from oakkitten/fix-tox-tests
Fix tests by “pinning” Anki dependencies via a time machine
2022-06-11 20:56:04 -07:00
oakkitten
cfcb1616ce Tests: add environments for Anki 2.1.51 to 53 2022-06-08 19:29:45 +01:00
oakkitten
b01dd47dec Tests: Run CI tests in parallel 2022-06-08 19:29:45 +01:00
oakkitten
863cef5e64 Tests: use time machine to “pin” Anki dependencies
Packages anki and aqt do not pin their requirements,
which breaks anki <= 2.1.49 because of protobuf major version bump.

While it's possible to use requirements.txt as constraints,
it might not be the best idea:
  * requirements.txt can’t be used as constraints
    without some careful sed’ding to remove hashes and extras;
  * its location changes between versions;
  * you can’t get this file for a pre-release version of Anki
    since these don't get git tags;
  * it’s rarely updated anyway and hence won’t reliably
    produce the environment that actual Anki uses.

So use a pypi-timemachine, which prevents pip from using packages
that were uploaded after a specified date.
While the code is a tad complex, it feels slightly less hacky,
and is likely to be producing more accurate environments.
2022-06-08 19:29:45 +01:00
Alexei Yatskov
5774ef7346
Merge pull request #323 from oakkitten/edit-dialog-bring-to-foreground
Bring Edit dialog to foreground more reliably
2022-05-29 12:59:02 -07:00
Alexei Yatskov
99d6256ade
Merge pull request #324 from toasted-nutbread/api-reflect
apiReflect
2022-05-29 12:58:38 -07:00
Alexei Yatskov
1d5b87b3f4
Merge pull request #322 from ZhengPeiRu21/fixDeckStatsTest
Fix getDeckStats test
2022-05-29 12:57:18 -07:00
Alexei Yatskov
23c25dd7ae
Merge pull request #319 from oakkitten/fix-bad-json-error
Produce a better error in case of malformed JSON
2022-05-29 12:56:51 -07:00
郑佩茹
1d7bf6969a Correct line endings 2022-05-23 11:37:18 -06:00
郑佩茹
5e701e30aa Only add total_in_deck to deckStats in supported Anki versions 2022-05-23 11:27:40 -06:00
toasted-nutbread
e842dc78e0 Add test 2022-05-20 17:19:29 -04:00
toasted-nutbread
0d0962319a Add documentation 2022-05-20 17:08:35 -04:00
toasted-nutbread
8d9163048a Add apiReflect 2022-05-20 17:08:29 -04:00
oakkitten
3d7e00a86c Bring Edit dialog to foreground more reliably 2022-05-19 16:49:08 +01:00
郑佩茹
b55ac78f84 Fix getDeckStats test 2022-05-16 13:36:02 -06:00
Alexei Yatskov
1d8e41e317
Merge pull request #318 from ZhengPeiRu21/getDailyReviews
Add getDeckStats action
2022-05-14 21:32:03 -07:00
oakkitten
9c3310a8b6 Don't crash if JSON is valid but of wrong schema 2022-05-11 20:32:09 +01:00
oakkitten
bffbb051f2 Produce a better error in case of malformed JSON
$ curl localhost:8777 -X POST -i -d '{"action": "version", "version": 6},' && echo ␄
HTTP/1.1 200 OK
Content-Type: text/json
Access-Control-Allow-Origin: http://localhost
Access-Control-Allow-Headers: *
Content-Length: 67

{"result": null, "error": "Extra data: line 1 column 36 (char 35)"}␄

$ curl localhost:8777 -X POST -i -d '{"action": "version", "version": 6},' -H "Origin: foo" && echo ␄
HTTP/1.1 403 Forbidden
Access-Control-Allow-Origin: http://localhost
Access-Control-Allow-Headers: *

␄
2022-05-11 20:32:08 +01:00
郑佩茹
137554f522 Add getDeckStats action 2022-05-03 15:59:33 -06:00
Alex Yatskov
fe8b221a93
Merge pull request #313 from oakkitten/anki50
Fix tests and some of the code to work with Anki 2.1.50
2022-04-26 20:57:20 -07:00
oakkitten
8a84db971a Patch Anki 2.1.50 on Windows to have valid stdout
Something in Anki is setting stdout to Null.
This is a problem because Anki itself is writing to it,
particularly when printing warnings about
the deprecated methods that we are using.

This patches Anki using the same method that
the upcoming Anki 2.1.51 is using.
2022-04-26 15:22:07 +01:00
oakkitten
ca90ef95fc Tests: set HOME via the command env
Environmental variables set in `setenv` also affect pip invocations.
`HOME` determines where pip is placing its cache.
Setting HOME to anything virtual env-specific means that
every virtual environment is created with its own cache.
This wastes time, data and disk space.
2022-04-26 15:22:07 +01:00
oakkitten
700c6ae218 Explicitly require Anki >= 2.1.45
Consolidate Anki version checks across files
2022-04-26 15:22:06 +01:00
oakkitten
056e722187 Edit dialog: fix editor buttons on Anki 2.1.50
Also add a few tests for the buttons to make sure
that they get actually added and enabled/disabled.
2022-04-26 15:22:06 +01:00
oakkitten
901d92b067 Tests: make tests pass for Anki 2.1.50 (Qt6)
* Import things from `aqt.qt` not `PyQt5`/`PyQt6`
* When testing with Qt6, disable Anki's Qt5 compatibility mode
* Depend on `pytest-anki` that is also Qt version agnostic
2022-04-26 15:22:06 +01:00
oakkitten
e025a44ea3 Tests: make tests pass for Anki 2.1.50 (Qt5)
* require Python 3.10
* prevent Anki from doing backups, again
* restore cwd that deck exporter changes for some wild reason
2022-04-26 15:22:06 +01:00
Abdo
a433f600a4 Allow passing deleteExisting in addNote (#309) 2022-04-25 20:13:06 -07:00
introt
81fccbfac6 requestPermission: improve UX & docs (#312)
* requestPermission: change Ignore button to checkbox

* Update requestPermission documentation

- describe the possible results
- document ignoreOriginList
2022-04-25 20:10:36 -07:00
8e9879f80f Merge remote-tracking branch 'oakkitten/edit-dialog' 2022-04-25 19:48:26 -07:00
oakkitten
6643dca83e Tests: patch waitress to reduce test flakiness
Waitress is a WSGI server that Anki starts to serve css etc to
its web views. It seems to have a race condition issue;
the main loop thread is trying to `select.select` the sockets
which a worker thread is closing because of a dead connection.

This makes waitress skip actually closing the sockets.
2022-04-14 01:55:41 +01:00
oakkitten
c688895c0e Edit dialog: make browser button show all history
Before, pressing the Browse button would only show browser
with the cards or notes corresponding to the currently edited note.

Now, it shows all cards or notes from the dialog history,
in reverse order (last seen on top),
with the currently edited note or its cards selected.
2022-04-14 01:55:41 +01:00
oakkitten
849ab43be7 Tests: simplify profile removal
It turns out that `pytest-anki` does what we are trying to do already.

Note that `empty_anki_session_started` creates a temporary user too.
We are “overwriting“ it in `profile_created_and_loaded`
by calling `temporary_user`. It seems that doing this is safe.
2022-04-11 02:28:25 +01:00
oakkitten
c53aa86a0d Ignore option closeAfterAdding of guiAddCards
The functionality was broken, creating a dialog that was not,
in fact, closing after adding a card.

See the deleted comment in `test_graphical.py`
2022-04-11 02:28:25 +01:00
oakkitten
8d507908c7 Add GitHub workflows tests 2022-04-11 02:28:25 +01:00
oakkitten
8aa5fdd1de Add api method guiEditNote 2022-04-11 02:28:25 +01:00
oakkitten
2313b8ba65 Add tox.ini, remove test.sh
The tests can be run now using `tox` against multiple Anki versions;
see instructions in `tox.ini`.

The tests depend on `pytest-anki` that had to be slightly modified
to remove the upper constraint on Anki version, as well as
to remove a few dependencies that are not essential to using it.
2022-04-11 02:28:25 +01:00
oakkitten
fb892d330a Add tests for the Edit dialog 2022-04-11 02:28:03 +01:00
oakkitten
8f1a2cc5fd Convert all tests to pytest
Previously, tests were run against Anki launched by user.

Now,
 * most tests run against isolated Anki in current process;
 * tests in `test_server.py` launch another Anki in a separate process
   and run a few commands to test the server;
 * nearly all tests were preserved in the sense that
   what was being tested is tested still.
   A few tests in `test_graphical.py` are skipped due to
   a problem with the method tests, see the comments;
 * tests can be run:
   * In a single profile, using --no-tear-down-profile-after-each-test;
   * In a single app instance, but with the profile being torn down
     after each test--default;
   * In separate processes, using --forked.
2022-04-11 02:26:44 +01:00
oakkitten
ddad426563 Do not wrap api methods with a lambda
Makes Pycharm happy
2022-04-11 02:26:44 +01:00
oakkitten
cfc6b0d012 Move configuration defaults dict to module level
So that it is importable by tests
2022-04-11 02:26:44 +01:00
oakkitten
f7d5cbbd04 Edit dialog: refactor
* make previewer use a more generic Adapter to flip through cards;
* return Previewer from `show_preview()` for testing,
* as well as Edit dialog from `open_dialog_and_show_note_with_id`;
* disable/enable `Edit` editor buttons more reliably;
* a few minor changes
2022-04-11 02:26:35 +01:00
oakkitten
748310def4 Make plugin importable
Don't start the web server if imported not from inside Anki

Make sure Anki Connect instance is not garbage collected.
This kills the timer that's responsible for the web server.
2022-04-07 09:48:37 +01:00
oakkitten
d6061affad Remove api method updateCompleteDeck
This method was broken and there are no issues regarding it on GitHub.
2022-04-07 09:48:37 +01:00
oakkitten
eac658716a Fix api method findAndReplaceInModels
I think this was a typo?
2022-04-07 09:48:37 +01:00
oakkitten
baed642489 Fix api method deleteDecks
The method was failing due to Anki API changes.

Also, make it mandatory to call the method with `cardsToo=True`,
since deleting decks on Anki >= 2.1.28 without cards is
no longer supported, and the deprecated `decks.rem()` method
on Anki >= 2.1.45 ignores keyword arguments.
2022-04-07 09:48:37 +01:00
oakkitten
0fdc93abc6 Add Edit dialog
Like Edit Current, but:
  * has a Preview button to preview all cards for this note
  * has a Browse button to open the browser with these
  * has Previous/Back buttons to navigate the history of the dialog
  * has no Close button bar
2022-04-07 09:48:37 +01:00
thiswillbeyourgithub
54a7105bf9
implement setSpecificValueOfCard for user @TobiasWehrum (#303)
Co-authored-by: thiswillbeyourgithub <github@32mail.33mail.comm>
2022-02-22 18:31:43 -08:00
Raphael-Joel Lim
a5aecfceee
Explicitly allow requests from public websites via new header (#302)
- Chrome now enforces that servers on private networks explicitly
  grant access to public websites using a new header
  "Access-Control-Allow-Private-Network" that should be sent in
  responses to preflight OPTIONS requests.
- This change implements special handling for OPTIONS requests by
  sending all the existing CORS headers along with the new
  Access-Control-Allow-Private-Network header if private network
  access is being requested.
- See https://developer.chrome.com/blog/private-network-access-preflight/
  for more info.
2022-02-18 23:08:44 -08:00
Jone Wang
7136a15ade
Allow safari-web-extension to access Aniki Connect. (#297)
* Allow safari-web-extension to access Aniki Connect.

* Fix typo.
2022-01-08 20:01:00 -08:00
Ren Tatsumoto
418ebcb0de
Fix updateModelTemplates and updateModelStyling functionality on Anki 2.1.45 and later (#296)
* fix update functionality on anki 2.1.45+

* delete trailing semicolon in the statement
2021-12-26 22:21:21 -08:00