Ejemplo n.º 1
0
 def setUp(self):
     self.client = TestClient(middleware)
     self.entrant = Entrant.create(email='*****@*****.**',
                                   name='Kyle',
                                   github_username='******')
     self.invitation = self.entrant.invite()
     self.path = '/invitation/{}'.format(self.invitation.code)
Ejemplo n.º 2
0
    def test_with_invitation(self):
        entrant = Entrant.create(email='*****@*****.**', name='Kyle', github_username='******')
        invitation = entrant.invite()
        invitation.save()

        response = self.client.get('/callback', {'code': 5})
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response.headers['Location'],
            'https://sotu.cocoapods.org/invitation/{}'.format(invitation.code)
        )

        entrant.delete_instance()
        invitation.delete_instance()
Ejemplo n.º 3
0
    def test_with_invitation(self):
        entrant = Entrant.create(email='*****@*****.**',
                                 name='Kyle',
                                 github_username='******')
        invitation = entrant.invite()
        invitation.save()

        response = self.client.get('/callback', {'code': 5})
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response.headers['Location'],
            'https://sotu.cocoapods.org/invitation/{}'.format(invitation.code))

        entrant.delete_instance()
        invitation.delete_instance()
Ejemplo n.º 4
0
def callback(request):
    code = request.GET.get('code')
    if not code:
        error = request.GET.get('error')
        error_description = request.GET.get('error_description',
                                            'Unknown Error, please try again')
        return JinjaResponse(
            request,
            template_names=['error.html'],
            context={'reason': '{} ({})'.format(error_description, error)})

    access_token = github.retrieve_access_token(code)
    if not access_token:
        return ResponseRedirect('https://sotu.cocoapods.org/')
    user = github.retrieve_account(access_token)
    email = github.retrieve_email(access_token)
    username = user['login']

    name = user.get('name', username)
    if name is None or len(name) == 0:
        name = username

    avatar = user.get('avatar_url', None)

    try:
        entrant = Entrant.select().where(
            Entrant.github_username == username).get()
    except Entrant.DoesNotExist:
        entrant = Entrant.create(github_username=username,
                                 name=name,
                                 email=email)

    try:
        invitation = entrant.invitation_set.get()
    except Invitation.DoesNotExist:
        invitation = None

    if invitation:
        if invitation.state == Invitation.ACCEPTED_STATE:
            return ResponseRedirect(invitation.accept_url)
        elif invitation.state == Invitation.REJECTED_STATE:
            return ResponseRedirect(invitation.reject_url)
        elif invitation.state == Invitation.INVITED_STATE:
            return ResponseRedirect(invitation.invited_url)

    return EntrantView.as_view(entrant=entrant, avatar=avatar)(request)
Ejemplo n.º 5
0
 def create_entrant(number):
     return Entrant.create(email='kyle_{}@cocoapods.org'.format(number),
                           name='Kyle',
                           github_username='******'.format(number))
Ejemplo n.º 6
0
 def setUp(self):
     self.client = TestClient(middleware)
     self.entrant = Entrant.create(email='*****@*****.**', name='Kyle', github_username='******')
     self.invitation = self.entrant.invite()
     self.path = '/invitation/{}'.format(self.invitation.code)
Ejemplo n.º 7
0
 def create_entrant(number):
     return Entrant.create(
         email='kyle_{}@cocoapods.org'.format(number),
         name='Kyle', github_username='******'.format(number)
     )