コード例 #1
0
 def setUp(self):
     User.objects.create_superuser(
         username='******', password='******', email='*****@*****.**')
     item = Hiren()
     item.access_token = "bla bla"
     item.authorized = True
     item.save()
     self.HIREN_ID = item.id
コード例 #2
0
    def test_saving_and_retrieving_item(self):
        item = Hiren()
        item.access_token = "bla bla"
        item.authorized = True
        item.save()

        saved_item = Hiren.objects.all()
        self.assertEqual(saved_item.count(), 1)

        saved_item_content = saved_item[0]
        self.assertEqual(saved_item_content.access_token, "bla bla")
        self.assertEqual(saved_item_content.authorized, True)
コード例 #3
0
def callback(request):
    """
    Handle github call back and then save the access token
    """
    if request.GET.get('code'):
        headers = {'Accept': 'application/json'}
        response = requests.post('https://github.com/login/oauth/access_token',
                                 {'client_id': settings.JSON_DATA['client_id'],
                                  'client_secret': settings.JSON_DATA['client_secret'],
                                  'code': request.GET.get('code'),
                                  'redirect_uri': settings.JSON_DATA['redirect_uri']}, headers=headers)
        api_res = response.json()
        obj = Hiren(access_token=api_res['access_token'], authorized=True)
        obj.save()
        return render(request, 'hiren.html', {'auth_button': True, 'id': obj.id})
    else:
        messages.error(request, "Ops ! Maybe a kitten died ! ")
        return render(request, 'hiren.html')
コード例 #4
0
 def setUp(self):
     User.objects.create_superuser(username='******',
                                   password='******',
                                   email='*****@*****.**')
     item = Hiren()
     item.access_token = "bla bla"
     item.authorized = True
     item.save()
     self.HIREN_ID = item.id
コード例 #5
0
    def test_saving_and_retrieving_item(self):
        item = Hiren()
        item.access_token = "bla bla"
        item.authorized = True
        item.save()

        saved_item = Hiren.objects.all()
        self.assertEqual(saved_item.count(), 1)

        saved_item_content = saved_item[0]
        self.assertEqual(saved_item_content.access_token, "bla bla")
        self.assertEqual(saved_item_content.authorized, True)