Skip to content

Conversation

sodre
Copy link
Contributor

@sodre sodre commented Jun 30, 2017

response = client.get('/persons/' + str(person.person_id) + '/relationships/computers?include=computers',
content_type='application/vnd.api+json')
assert response.status_code == 200
assert (json.loads(response.get_data()))['links']['related'] == '/persons/' + str(person.person_id) + '/computers'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not needed, and shall be removed.

from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy.ext.declarative import declarative_base
from flask import Blueprint, make_response
from flask import Blueprint, make_response, json
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use flask.json since it handles bytes and unicode correctly.

assert response.status_code == 200


def test_issue_49(session, client, register_routes, person, person_2):
Copy link
Contributor Author

@sodre sodre Jun 30, 2017

Choose a reason for hiding this comment

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

  • Feel free to propose a different test function name.

@sodre sodre force-pushed the i-49-related-link branch 2 times, most recently from 7b9c25d to 15b6e72 Compare July 1, 2017 03:19
sodre added 5 commits June 30, 2017 23:55
 - Set person missing and default to None in Computer Schema
 - Fix typo, the SQLAlchemy model uses .person not .owner
 - Assert data is empty

The related view is for person_detail page which does not
exist since the computer is not attached to a person yet during
this test.
 - The flask version handles unicode and bytestream by default
 - Add Person 1
 - Add Person 2
 - Access person/1/relationships/computers
 - Verify links.related is valid.
 - Access person/2/relationships/computers
 - Verify links.related is valid. (Fails)
  - Use marshmallow to render related_url
  - This depends on marshmallow-jsonapi being updated.

Closes miLibris#49
@sodre sodre force-pushed the i-49-related-link branch from 15b6e72 to 3ae4482 Compare July 1, 2017 04:13
@coveralls
Copy link

coveralls commented Jul 1, 2017

Coverage Status

Coverage decreased (-0.04%) to 95.0% when pulling 3ae4482 on sodre:i-49-related-link into 9566f6f on miLibris:master.

@sodre sodre changed the title [WIP] Fix issue #49 Fix issue #49 Jul 1, 2017
@sodre
Copy link
Contributor Author

sodre commented Jul 1, 2017

This PR is ready for review.

The coverage/coveralls fail should be ignored. It occurs because the proposed fix trades 10-covered-lines of resource.py in favor of one function call to marshmallow-jsonapi get_related_url.

When the prosed fix is applied, two other unit tests begin to fail unless they are corrected before-hand. I split those fixes in PRs #51, and #52, feel free to merge them first or change to order of the commits.

cc: @akira-dev, @jcampbell

tmp_obj = obj
for field in value[1:-1].split('.'):
tmp_obj = getattr(tmp_obj, field)
related_view_kwargs[key] = tmp_obj
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line is the original source of the bug.

It was rewriting the related_view_kwargs template with the value for the current page access. From this point on, related_view_kwargs will remain in a broken state until the application is restarted

@sodre
Copy link
Contributor Author

sodre commented Aug 1, 2017

@akira-dev

Any chance of taking a look at this PR? The coveralls failure is because the proposed solution reduces the number of lines of code in favor of calling an existing function in marshmallow-jsonapi.

@sodre
Copy link
Contributor Author

sodre commented Aug 16, 2017

pinging @akira-dev 🏓

@akira-dev akira-dev merged commit bbb0604 into miLibris:master Oct 11, 2017
@akira-dev
Copy link
Collaborator

Thx

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.

3 participants