-
Notifications
You must be signed in to change notification settings - Fork 274
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
Add rest-auth helpers #125
Conversation
Due to the high usage of rest-auth, it is likely others will benefit from this.
|
|
||
|
||
class DRFDefaultDetailSerializer(serializers.Serializer): | ||
detail = serializers.CharField(read_only=True, required=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of the responses for #101
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that is would be highly desirable to fix #101 first! This is a major bug in the current schemas emitted by drf-spectacular.
Doing that first will cement in the serializer name, and thus the component name, which will be in the schema, and then it can be used there and elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm currently trying out some ideas for #101 but it is a bit tricker that one would expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tfranzel , please comment here. This is the most important part, and you ignored it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have not ignored it. my time is also limited and i wanted to give a well thought out review. will comment on it very soon.
Also worth noting, this doesnt include the social auth views provided by rest-auth. |
138e24e
to
d1c6141
Compare
4138555
to
b8c425b
Compare
Codecov Report
@@ Coverage Diff @@
## master #125 +/- ##
==========================================
- Coverage 96.82% 96.44% -0.38%
==========================================
Files 45 47 +2
Lines 3087 3210 +123
==========================================
+ Hits 2989 3096 +107
- Misses 98 114 +16
Continue to review full report at Codecov.
|
Hmm. Forgot to add tests. Will amend tonight. |
b8c425b
to
ec4c94c
Compare
Use diff-match-patch to show differences only. Create baseline yml if it does not exist.
163288f
to
f948baa
Compare
Output can vary between different versions of dependencies, and those differences may be of no consequence to the correctness of the test.
f948baa
to
5970984
Compare
@tfranzel please reviewing the code contribution here in the PR, rather than your constant rewriting of other peoples code after merging. If there are stylistic issues, I am happy to adjust if that is communicated. Designs are better when people work together, rather than having ones persons design immediately 'cancelled' by someone else. |
dmp = diff_match_patch() | ||
diff = dmp.diff_main(expected, generated) | ||
dmp.diff_cleanupSemantic(diff) | ||
patch = dmp.patch_toText(dmp.patch_make(diff)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This library is better than nothing, and quite good for short textual differences, especially within a single line, but the current results are far from perfect for large chunks of multiline differences.
The outstanding rest-polymorphic difference here is not exactly easy to grok.
Maybe the invocation can be improved by tweaking some of its options.
Doing a plain unified diff is also an option; that at least leverages existing brain circuitry for people familiar with diffs of YAML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just had a quick look if python's included batteries are good enough. looks good to me. i think we can refrain from adding a new dependency here.
diff = difflib.unified_diff(
schema_ref.splitlines(True),
schema_yml.decode().splitlines(True),
)
diff = ''.join(diff)
assert not diff, diff
sure thing. already working on the review. on your last PR i just changed a variable name and a style thing. i thought that it would be faster and that i wouldn't waste your time on a trivial second review round. sure i can include those OCD minors in the review process. whatever you prefer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as requested quite a few comments/questions. good stuff though!
dmp = diff_match_patch() | ||
diff = dmp.diff_main(expected, generated) | ||
dmp.diff_cleanupSemantic(diff) | ||
patch = dmp.patch_toText(dmp.patch_make(diff)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just had a quick look if python's included batteries are good enough. looks good to me. i think we can refrain from adding a new dependency here.
diff = difflib.unified_diff(
schema_ref.splitlines(True),
schema_yml.decode().splitlines(True),
)
diff = ''.join(diff)
assert not diff, diff
raise RuntimeError( | ||
f'{reference_filename} was not found. ' | ||
f'It has been created with the generated schema. ' | ||
f'Review carefully, as it is the baseline for subsequent checks.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closing parenthesis on a new line please
|
||
|
||
@pytest.mark.contrib('rest_auth') | ||
def test_rest_auth_registration(no_warnings): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho you can merge those two tests together with one yaml.
@@ -1,7 +1,8 @@ | |||
diff-match-patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove it (see other comment)
@@ -1,4 +1,6 @@ | |||
django-allauth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add working min versions
from rest_framework import serializers | ||
|
||
try: | ||
from allauth.account.app_settings import EMAIL_VERIFICATION, EmailVerificationMethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do local import and setup in the extensions instead (for contrib stuff). duplication seem minimal from a quick glance. python, basic django&drf and spectaculuar imports can stay of course.
i only did those fallbacks out of necessity in the tests when running with the packaging (missing-contrib) option. not really necessary here.
yield capsys | ||
|
||
if request.node.rep_call.failed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the rational behind this? why is it needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See commit messages please.
|
||
transforms = [ | ||
# User model first_name differences | ||
lambda x: re.sub(r'(first_name:\n *type: string\n *maxLength:) 150', r'\g<1> 30', x, re.M), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afais those transforms do nothing. test pass without them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are required on different versions of django and drf. This is explained in the commit messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah that makes sense. now i see. can you extend the comment with something like (changed in Django 3.1)
to make it more obvious.
generator = SchemaGenerator(patterns=urlpatterns) | ||
schema = generator.get_schema(request=None, public=True) | ||
|
||
assert_schema(schema, 'tests/contrib/test_rest_auth.yml', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i prefer
assert_schema(
schema, 'tests/contrib/test_rest_auth.yml', transforms=transforms
)
or
assert_schema(
schema,
'tests/contrib/test_rest_auth.yml',
transforms=transforms
)
depending on line length. i try not going over ~95 in general
Closes #113