Ejemplo n.º 1
0
 def test09_google_get_data(self):
     with dummy_app.test_request_context('/a_request'):
         with mock.patch('urllib2.urlopen', return_value=Readable('{"c":"d"}')):
             auth = IIIFAuthGoogle(client_secret_file=csf)
             config = Struct(host='a_host',port=None)
             j = auth.google_get_data(config,{'access_token':'TOKEN'})
             self.assertEqual( j, {'c':'d'} )
Ejemplo n.º 2
0
 def test10_google_get_data(self):
     """Test google_get_data method."""
     with dummy_app.test_request_context('/a_request'):
         with mock.patch(self.urlopen_name(),
                         return_value=Readable(b'{"c":"d"}')):
             auth = IIIFAuthGoogle(client_secret_file=csf)
             config = Struct(host='a_host', port=None)
             j = auth.google_get_data(config, {'access_token': 'TOKEN'})
             self.assertEqual(j, {'c': 'd'})
Ejemplo n.º 3
0
 def test07_home_handler(self):
     with dummy_app.test_request_context('/a_request'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         # Avoid actual calls to Google by mocking methods used by home_handler()
         auth.google_get_token = mock.Mock(return_value='ignored')
         auth.google_get_data = mock.Mock(return_value={'email':'e@mail','name':'a name'})
         response = auth.home_handler()
         self.assertEqual( response.status_code, 200 )
         self.assertEqual( response.headers['Content-type'], 'text/html' )
         html = response.get_data()
         self.assertTrue( re.search(r'<script>window.close\(\);</script>',html) )
Ejemplo n.º 4
0
 def test08_home_handler(self):
     """Test home_handler method."""
     with dummy_app.test_request_context('/a_request'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         # Avoid actual calls to Google by mocking methods used by
         # home_handler()
         auth.google_get_token = mock.Mock(return_value='ignored')
         auth.google_get_data = mock.Mock(return_value={
             'email': 'e@mail',
             'name': 'a name'
         })
         response = auth.home_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.headers['Content-type'], 'text/html')
         html = response.get_data().decode('utf-8')
         self.assertTrue(
             re.search(r'<script>window.close\(\);</script>', html))