def _add_short_links_chunked(data): """Create short_url's for a chunked list of docs.""" base_url = 'https://{0}%s'.format(Site.objects.get_current().domain) for doc in data: endpoint = reverse('wiki.document', locale=doc.locale, args=[doc.slug]) doc.share_link = generate_short_url(base_url % endpoint) doc.save()
def test_generate_short_url_200(self, mock_requests): """Tests a valid 200 response for generate_short_url method.""" mock_json = mock.Mock() mock_json.json.return_value = { 'status_code': 200, 'data': { 'url': 'http://mzl.la/LFolSf' } } mock_requests.post.return_value = mock_json eq_('http://mzl.la/LFolSf', generate_short_url(self.test_url))
def add_short_links(doc_ids): """Create short_url's for a list of docs.""" base_url = "https://{0}%s".format(Site.objects.get_current().domain) docs = Document.objects.filter(id__in=doc_ids) try: for doc in docs: # Use django's reverse so the locale isn't included. endpoint = django_reverse("wiki.document", args=[doc.slug]) doc.update(share_link=generate_short_url(base_url % endpoint)) except BitlyRateLimitException: # The next run of the `generate_missing_share_links` cron job will # catch all documents that were unable to be processed. pass
def add_short_links(doc_ids): """Create short_url's for a list of docs.""" base_url = 'https://{0}%s'.format(Site.objects.get_current().domain) docs = Document.objects.filter(id__in=doc_ids) try: for doc in docs: endpoint = reverse('wiki.document', locale=doc.locale, args=[doc.slug]) doc.share_link = generate_short_url(base_url % endpoint) doc.save() except BitlyRateLimitException: # The next run of the `generate_missing_share_links` cron job will # catch all documents that were unable to be processed. pass
def add_short_links(doc_ids): """Create short_url's for a list of docs.""" base_url = 'https://{0}%s'.format(Site.objects.get_current().domain) docs = Document.objects.filter(id__in=doc_ids) try: pin_this_thread() # Stick to master. for doc in docs: # Use django's reverse so the locale isn't included. endpoint = django_reverse('wiki.document', args=[doc.slug]) doc.update(share_link=generate_short_url(base_url % endpoint)) statsd.incr('wiki.add_short_links.success') except BitlyRateLimitException: # The next run of the `generate_missing_share_links` cron job will # catch all documents that were unable to be processed. statsd.incr('wiki.add_short_links.rate_limited') pass finally: unpin_this_thread()
def add_short_links(doc_ids): """Create short_url's for a list of docs.""" base_url = 'https://{0}%s'.format(Site.objects.get_current().domain) docs = Document.objects.filter(id__in=doc_ids) try: pin_this_thread() # Stick to master. for doc in docs: endpoint = reverse('wiki.document', locale=doc.locale, args=[doc.slug]) doc.share_link = generate_short_url(base_url % endpoint) doc.save() except BitlyRateLimitException: # The next run of the `generate_missing_share_links` cron job will # catch all documents that were unable to be processed. pass finally: unpin_this_thread()
def test_generate_short_url_200(self, mock_requests): """Tests a valid 200 response for generate_short_url method.""" mock_json = mock.Mock() mock_json.json.return_value = {"status_code": 200, "data": {"url": "http://mzl.la/LFolSf"}} mock_requests.post.return_value = mock_json eq_("http://mzl.la/LFolSf", generate_short_url(self.test_url))