-
Notifications
You must be signed in to change notification settings - Fork 8
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
Adding a fast sign-in with google #66
base: main
Are you sure you want to change the base?
Conversation
2258bc5
to
6c9f143
Compare
6c9f143
to
1f63131
Compare
1f63131
to
3a39399
Compare
307f4dd
to
c156572
Compare
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 got the same error as Leead.
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.
@Leeadar and @nadavspinco It might have something to do with the registration of the sites and social app in the admin for configuration (linked to the way it configured through the settings file) I thought It will work without configuring it on every VM, if that is the case it might be better to give up on this PR, I will attach demonstration but it seems too much work for such a simple feature and because of google limitations it's not really practical at this point. @Yarboa @guy9050 @EdDev , right? I will demonstrate what is needed in my opinion to fix it, and maybe if there's a way to automate it will be smoother.
@@ -23,11 +24,20 @@ def __init__(self, general_model, admin_site): | |||
super(ListAdminMixin, self).__init__(general_model, admin_site) | |||
|
|||
|
|||
def is_related_to_social_signing(suspected_model): |
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 a bad solution but I couldn't find any other solution to exclude these models relates to the 'sites' and 'all-auth' models of Django (since there is an auto-registration of those models and then I kept getting the Already registered exception)- please give me your input here - @EdDev @guy9050 @Yarboa
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.
can you please elaborate more what the problem is and how does this function solve 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.
The automation of the model registration suppose to register to admin only models that haven't been registered already, regarding the 4, 5 models provided by Django that are allowing social account logins (like google sign in) are already registered by Django and then the code tries to register it although it already has been registered, and this causes an exception. I couldn't find a solution so I enforced the automation part to avoid registering the 4, 5 problematic models that have been registered by Django to avoid the problem using an ugly if statement that assuring the model that is registered is not one of these problematic ones (it might have something to do with the fact the social account models are registered differently because it happened automatically after adding the new settings to support social login)
admin.site.register(model, admin_class) | ||
except admin.sites.AlreadyRegistered: | ||
pass | ||
if not is_related_to_social_signing(model): |
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 not clear to me, Does the app could run both?
with the social auth and without?
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.
no, It's somehow registered automatically, so In order to avoid conflicts of registering twice I used this bad solution, but If it makes too much trouble we can give up on this PR, the other mentors have told me it's not a great idea
(not in these words).
And I followed a tutorial so I can't assume it would work without 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.
Sorry, i was asking misleading question,
In case no social media is set in admin, will it work the same w/o this PR?
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.
@Yarboa sorry I'm still not entirely understand your question, what do you mean by 'social media is set in admin'? I wasn't setting anything since Django is registering the social media models related to OAuth2 of google, and these specific models are making trouble with the auto-model registration code since it's trying to register the models again. I don't think I can give up on those settings (and this is what generates these social media models of Django), I followed a tutorial so I believe every setting is crucial, and Django is having a very specific way to do so, as I read from several sources.
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.
There is pip install of django-allauth
And in App/url.py
This is default user, no option to work with non allauth.urls?
path('accounts/', include('allauth.urls'))
Ok looking here https://django-
allauth.readthedocs.io/en/latest/overview.html
Signup of both local and social accounts, did you check that you can login local?
How do you plan to test this feature?
NOTE: I suggest to describe better in the comment what are the capabilities,
bb5ccd6
to
c636702
Compare
@nadavspinco |
Did you try pressing homepage, about? while server is up? |
picATrip/urls.py
Outdated
'about/', | ||
TemplateView.as_view(template_name="pickATrip_django_apps/about.html"), | ||
name='about', | ||
), |
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.
Those changes fail on tests. if we use Template.as_view I need to change the test because Template.as_view returns a different function on memory and python refers to this as different functions.
@maayanhd There is a reason you changed that?
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.
Actually, I did this at first because I thought it would be a better way, but I couldn't find if this is the case and haven't think of the fact it might fail future tests, thanks for clarifying.
9aca1f8
to
ddb8057
Compare
ddb8057
to
42f9e5e
Compare
users/tests/test_allauth.py
Outdated
first_name = "明" | ||
last_name = "小" |
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 would advise using english here
and auto generate name last name
users/tests/test_allauth.py
Outdated
ACCOUNT_SIGNUP_FORM_CLASS=None, | ||
ACCOUNT_EMAIL_VERIFICATION=account_settings.EmailVerificationMethod.MANDATORY, | ||
) | ||
class GoogleTests(OAuth2TestsMixin, TestCase): |
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 are using django-pytest we are not using TestCases
My intention was to receive ideas and work in django-pytest not to copy
sorry mate
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.
To be honest I don't find much purpose in not reusing parts of complex code for testing integration of Django with Google API without needing to write from a scratch method by method, this test uses preprepared objects to ease the test of the sign in with google and it has been written for the purpose of testing this feature, I do see value in making modifications from using test case to PyTest but further than that not sure why is it bad reusing code if it feets my purposes, If something I thought not doing everything is part of a developer's job, to save valuable developing time, so there's time for the more important stuff. That's my opinion but that's only one opinion after all.
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.
To be honest I don't find much purpose in not reusing parts of complex code for testing integration of Django with Google API without needing to write from a scratch method by method, this test uses preprepared objects to ease the test of the sign in with google and it has been written for the purpose of testing this feature, I do see value in making modifications from using test case to PyTest but further than that not sure why is it bad reusing code if it feets my purposes, If something I thought not doing everything is part of a developer's job, to save valuable developing time,
I am not sure it is not helping your knowledge and skills as SW dev.
so there's time for the more important stuff. That's my opinion but that's only one opinion after all.
You are correct, but i would advise to maintain testing standards.
Please rethink even in cost of less test coverage, to work with django-pytest standards
93ff587
to
2ce1212
Compare
users/tests/test_allauth.py
Outdated
<<<<<<< HEAD | ||
class GoogleTests(OAuth2TestsMixin): |
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.
You did not rebase correctly
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.
Yes not sure how this file got uploaded I erased it some kind of mistake of course..
users/tests/test_allauth.py
Outdated
|
||
@pytest.fixture | ||
def unverified_mail_mocked_response( | ||
<<<<<<< HEAD |
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.
same as above
users/tests/test_allauth.py
Outdated
======= | ||
<<<<<<< HEAD |
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.
same as above
users/tests/test_allauth.py
Outdated
name, | ||
email, | ||
unverified_email_val, | ||
>>>>>>> d3ee076 (fix) |
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.
same as above
users/tests/test_allauth.py
Outdated
name="Raymond Penners", | ||
email="[email protected]", | ||
verified_email=True, | ||
>>>>>>> 42f9e5e (Fixtures and tests for sign in with google feature) |
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.
same as above
users/tests/test_allauth.py
Outdated
name, | ||
email, | ||
given_name, | ||
<<<<<<< HEAD |
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 review the file
You can not force push without complete rebase
Please review all <<< ====
And do manual merge and then run tests, and commit push
53d4e73
to
a87ee9d
Compare
- Adding routing [urls.py][1] and auth-all of django in the [settings.py][2] file - Made some minor changes in the [base.html][3] Fast sign in with google for test users (in production adding gmail email for testing the feature) closes # 64
- Adding [allauth_fixtures][0] file for automating the site registation and social account in order to avoid doing so locally on each VM - Adding [test_allauth][1] file for testing the sign in eith google feature based on the tests file appeared in google provider tests in the allauth django project
- Added DB annottion of pytest due to a conflit occurs after adding the sign in with google feature
a87ee9d
to
ccdf698
Compare
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.
@nadavspinco Because you didn't follow the instructions of adding a social app, anyway, it looks like this PR won't be merged as it is, unfortunately. |
closes #64
Make sure that these settings are defined in the admin:
client id: 209174926940-maavnu1qvcrcil3la6a5h96b593d0p84.apps.googleusercontent.com
secret key: ch-VdNjqiqtUT1zzrDlwHV6p
sites admin:
social application model:- make sure the site is found on the chosen sites