Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ODL with multiple license blocks #39

Merged
merged 7 commits into from
Oct 15, 2021
Merged

Conversation

jonathangreen
Copy link
Member

Description

This PR is a work in progress. Its failing currently since its just tests to try to illustrate the problem.

@leonardr made a comment on #25 (#25 (comment)) that there may be some issue in recalculating when a licensepool has multiple licenses and a single one expires.

Motivation and Context

To try to understand the problem that @leonardr indicated, I added a set of tests for OPDS and OPDS2 + ODL that import a feed where a single publication has multiple licenses and where a single license block has more then one license available.

- Test a feed with multiple license blocks.
- Test a single license block with different numbers of
  licenses available.
@jonathangreen jonathangreen marked this pull request as draft September 9, 2021 19:28
@jonathangreen
Copy link
Member Author

@leonardr do these tests illustrate the situation that you were talking about in #25 (comment) ?

@jonathangreen
Copy link
Member Author

@ThePalaceProject/backend tagging you both to see if these tests make sense to you.

@jonathangreen jonathangreen force-pushed the bugfix/odl-multiple-licenses branch from f623e85 to 5ab1a6f Compare September 9, 2021 19:57
Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a quick look and the logic makes sense. A couple of the comments seem out of sync with the logic and could be confusing.

tests/test_odl.py Outdated Show resolved Hide resolved
tests/test_odl.py Outdated Show resolved Hide resolved
tests/test_odl.py Outdated Show resolved Hide resolved
@jonathangreen
Copy link
Member Author

Thanks @tdilauro I updated those comments to make them more clear.

@tdilauro tdilauro self-requested a review September 9, 2021 21:23
tests/test_odl.py Outdated Show resolved Hide resolved
@jonathangreen
Copy link
Member Author

Feel free to just push more commits to this branch if you want to @vbessonov

remaining_checkouts = checkouts.get("left")
available_concurrent_checkouts = checkouts.get("available")

if remaining_checkouts is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if left property is missing but total_checkouts is there it means that nobody used it so far.
But on the other hand it might mean that it actually expired and lack of left means that no checkouts left.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If left is missing, it is an error according to the ODL spec. Have we seen that case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdilauro, I even found the case in the DPLA Exchange Feed when left is missing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this question to De Marque. Hopefully will have a response soon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De Marque indicated that you should not expect to see left when there is an unlimited number of checkouts (which is not consistent with the spec). In that case, total_checkouts should be missing also, as it is in the example you gave above.

Have you seen any cases where left is missing, but total_checkouts is present?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdilauro, yes, there are cases like that in the DPLA Exchange feed. I added a new cell to the Jupyter notebook where all the licenses like that are shown.

@vbessonov
Copy link
Contributor

@jonathangreen, @tdilauro, the changes I made should cover most of the cases except the case of perpetual licenses, i.e. licenses without total_checkouts`left` properties.
There is a comment I left to bring your attention to the part I'm not sure about.

Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking very good. There are a couple of places where some additional documentation would be helpful, as noted.

Regarding the fetch of the license status document, it think it would be helpful to have some visibility into failures when we don't get one when we expect to.

api/odl.py Outdated Show resolved Hide resolved
api/odl.py Show resolved Hide resolved
api/odl.py Outdated Show resolved Hide resolved
tests/files/odl/feed_template.opds.jinja2 Outdated Show resolved Hide resolved
tests/test_odl.py Outdated Show resolved Hide resolved
tests/test_odl2.py Outdated Show resolved Hide resolved
tests/files/odl/feed_template.opds.jinja2 Outdated Show resolved Hide resolved
tests/files/odl2/feed_template.json.jinja2 Outdated Show resolved Hide resolved
tests/test_odl.py Outdated Show resolved Hide resolved
@jonathangreen jonathangreen marked this pull request as ready for review September 30, 2021 13:30
@jonathangreen
Copy link
Member Author

I think this is looking ready to merge other then the two unresolved comments left.

@leonardr if you have time to give this a review, any comments you have here would be appreciated as well, since you are likely going to pull this fix in upstream as well.

)


class TestLicense:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's mocking the License data model class, which isn't ODL-specific. So this could go into testing.py. But right now the only reason to do it would be if you also needed it in test_odl2.py.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not used in test_odl2.py explicitly but rather implicitly. Test classes in test_odl2.py inherit from base classes defined in test_odl.py.

@leonardr
Copy link
Contributor

Sorry for the delay. I'm going through this and I think it does a good job of addressing the cases I brought up, so I don't think I'll have any substantive comments. I'm not wild about the jinja2 dependency, but it looks like you introduced that earlier. As long as it's just a test dependency I can deal with it.

@leonardr
Copy link
Contributor

Yes, this looks good. It also appears that jinja2 is a dependency of one of our existing dependencies, so that's less of a problem than I thought.

leonardr added a commit to NYPL-Simplified/circulation that referenced this pull request Oct 15, 2021
@tdilauro tdilauro self-requested a review October 15, 2021 19:53
Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! 🚀

@jonathangreen jonathangreen merged commit 8ec48c7 into main Oct 15, 2021
@jonathangreen jonathangreen deleted the bugfix/odl-multiple-licenses branch October 15, 2021 19:58
jonathangreen referenced this pull request in jonathangreen/circulation Dec 21, 2021
* Show lcp:hashed_passphrase only for LCP DRM-protected items
* Refactor to align with tags on Adobe DRM.

Co-authored-by: Jonathan Green <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants