Add support for JPEG deck covers#49
Conversation
a54fdc2 to
aa643be
Compare
Pull Request Test Coverage Report for Build 255
💛 - Coveralls |
29a3d95 to
c224621
Compare
|
Hi @marccarre, thanks for the PR. Creating new decks with a cover image works like a charm for me. However, when trying to change the cover of an existing deck and calling |
|
Fair point, I'll update this PR accordingly. |
b3995ae to
f019f54
Compare
It previously was just ignored, and left unused.
It previously was ignored, but with a commented-out line which suggested this is where this should be added.
…e endings of the actual form
The current test really is just testing requests_toolbelt.multipart.encoder.MultipartEncoder, and has no real reason to remain as this MultipartEncoder is already heavily tested upstream. Note that prior to removal, tests were passing under some versions of Python, but not others, due to different orderings of the form values: - https://travis-ci.org/floscha/tinycards-python-api/jobs/506018179 - https://travis-ci.org/floscha/tinycards-python-api/builds/506018178 Besides, this logic is also covered by integration tests.
f019f54 to
7667128
Compare
|
FYI:
|
This is a more robust test, albeit a bit more expensive, as the default cover could also eventually be hosted by cloudfront.
Otherwise, the reason of the failure is masked, which hinders debugging.
Previously, the following would be added to the payload, resulting in errors server side, since invalid JSON:
```
Content-Disposition: form-data; name="cards"\r\n
\r\n
[{\'creationTimestamp\': 1552700740000, \'sides\': [{\'concepts\': [{\'fact\': {\'text\': \'front test 1\', \'type\': \'TEXT\'}}]}, {\'concepts\': [{\'fact\': {\'text\': \'back test 1\', \'type\': \'TEXT\'}}]}]}, {\'creationTimestamp\': 1552700740000, \'sides\': [{\'concepts\': [{\'fact\': {\'text\': \'front test 2\', \'type\': \'TEXT\'}}]}, {\'concepts\': [{\'fact\': {\'text\': \'back test 2\', \'type\': \'TEXT\'}}]}]}]\r\n
```
Indeed, when updating a deck's cover in the web UI, cards are encoded like this:
```
Content-Disposition: form-data; name="cards"\r\n
\r\n
[{"sides":[{"concepts":[{"fact":{"text":"Q1","type":"TEXT"}}]},{"concepts":[{"fact":{"text":"A1","type":"TEXT"}}]}]},{"sides":[{"concepts":[{"fact":{"type":"TEXT","text":"Q2"}}]},{"concepts":[{"fact":{"type":"TEXT","text":"A2"}}]}]}]\r\n
```
|
Done:
@floscha, PTAL 🙂 |
|
The code and tests look good so far. When toying around with the functionality a bit, I found that while adding cover images from local files works as expected, using a URL for images that have been uploaded to the internet already, is simply disregarded by Tinycards. When checking the requests used by the Tinycards web page, you see that it also sends the cover image in binary format, even when selecting an image from a URL. So I figured one possible solution to this could be trying to download the image from the specified URL and if successful (i.e. getting a 2** HTTP response), submitting the downloaded image as bytes just like when using a local file. One problem to keep in mind with this approach though is to make sure that the image is only downloaded and updated when it was actually changed and not with every update made to the deck. One solution to this could be using the coverImageUrl field (which unfortunately is not included in the Python Deck class yet). This field appears to be set by the Tinycards backend only after the image was updated (i.e. the local file path has been replaced with the URL to the uploaded version of the image on cloudfront.net). Therefore, it should be possible to simply check if imageUrl (i.e. the cover property of the Deck class) equals coverImageUrl. |
|
Issue created. I'll reply there to avoid mixing discussion threads. |
|
Thanks a lot! 🙂 Also, I'll bump the version of the library to 0.27 after merging so that your changes are also available when pip-installing the library. |
|
Thanks! 🙂 |
Fixes #47.
Screenshots: