Exemple #1
0
 def test_new_github_profile_from_request(self):
     """ Test that a new profile is saved with info from a request. """
     request = Mock(POST={"name": "testing", "email": "*****@*****.**",
         "login": "******"})
     profile = GitHub.populate_from_request(request)
     self.assertEqual(profile.name, "testing")
     self.assertEqual(profile.username, "foobar")
Exemple #2
0
    def get_redirect_url(self, **kwargs):
        """ Generate the github profile and redirect to login """
        if "code" not in self.request.GET:
            raise Exception("Invalid GitHub callback: %s", self.request.GET)
        token = github.get_github_access_token(
            code=self.request.GET["code"])

        user_profile = github.get_github_user_profile(token=token)
        username = user_profile["user"]["login"]
        github_results = GitHub.objects.filter(username=username)
        if not github_results:
            # Assuming this is a new user
            profile = GitHub.populate_from_user_profile(user_profile)
            user = User.create_from_profile(profile)
            user.save()
            profile.user = user
            profile.save()
        else:
            profile = github_results[0]
            user = profile.user
        # MAN, this is a dirty, dirty hack. Seriously Django?
        user.backend = 'django.contrib.auth.backends.ModelBackend'
        user.save()
        login(self.request, user)
        return "/login"
Exemple #3
0
 def test_new_github_profile_from_api_request(self):
     """ Test that a new profile is saved with info from the API. """
     profile = GitHub.populate_from_user_profile({
         "user" : {
             "name": "testing",
             "email": "*****@*****.**",
             "login": "******"
         }
     })
     self.assertEqual(profile.name, "testing")
     self.assertEqual(profile.username, "foobar")