def test_get_url_content_download_error_handling(self, _, authed_fetch): authed_fetch.side_effect = urlfetch.DownloadError import dtmm_utils mock_handler = Mock() dtmm_utils.get_url_content(mock_handler, 'http://mock.com') mock_handler.error.assert_called_with(408)
def test_get_url_content_retrieve_from_memcache(self): import dtmm_utils url_digest = dtmm_utils.md5_hash('http://mock.com') memcache.set(url_digest, {'content': 'word'}) end_data = dtmm_utils.get_url_content(None, 'http://mock.com') self.assertEqual(end_data, {'content': 'word'})
def get(self): "Handlers get requests" data = dtmm_utils.get_modules(self) module_name = self.request.get('name') if module_name not in map(itemgetter('path'), data): self.error(404) return data_dict = { rpart(fragment['path']): fragment['url'] for fragment in data } encoded_content = dtmm_utils.get_url_content(self, data_dict[module_name]) content = base64.b64decode(encoded_content['content']) self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Cache-Control'] = 'no-Cache' self.response.write(content)
def get(self, platform): platform = platform.lower() key = 'build_status_{}'.format(platform) # import pudb # pu.db # ensure the platform is valid if platform not in ['mac', 'linux', 'windows']: self.notify_status('unknown') return status = memcache.get(key) if not status: # create the build status url url = STATUS_URL.format(platform) raw_data = dtmm_utils.get_url_content(self, url) # if no exceptions occured if '-1' in raw_data and 'text' in raw_data['-1']: status_text = raw_data['-1']['text'] if 'successful' in status_text: logging.info('Builds are passing') status = 'passing' elif ('failed' in status_text or 'exception' in status_text): logging.info('Builds are failing') status = 'failing' else: status = 'unknown' else: logging.info('Build status is unknown') status = 'unknown' memcache.set(key, status) self.notify_status(status)
def test_get_url_content_fetch_from_remote(self, mock_authed_fetch): url = 'http://mock.com' content = { u'tree': [{ u'sha': u'ac178f6489f2d3f601df6a9a5e641b62a0388eae', u'mode': u'100644', u'path': u'README.md', u'type': u'blob', u'size': 314 }] } mock_authed_fetch.return_value.content = json.dumps(content) import dtmm_utils end_data = dtmm_utils.get_url_content(None, url) self.assertEqual(end_data, content) mock_authed_fetch.assert_called_with(url) self.assertEqual( memcache.get(dtmm_utils.md5_hash(url)), content )