Beispiel #1
0
 def test_feed_updated_date_format(self):
     """Tests XML feed <updated> field format."""
     feed = xml_etree.fromstring(utils.GenerateFeed())
     updated = feed.find(
         "{http://www.w3.org/2005/Atom}updated").text.strip()
     self.assertEqual(len(self.FEED_DATE_FORMAT_RE.findall(updated)), 1)
     self.assertEqual(self.FEED_DATE_FORMAT_RE.findall(updated)[0], updated)
Beispiel #2
0
    def get(self, request, *args, **kwargs):
        feed_type = kwargs["feed_type"]

        audience = request.GET.get('audience', '')
        # print(audience)

        if "alert_id" in kwargs:
            try:
                alert = models.Alert.objects.get(uuid=kwargs["alert_id"])
            except models.Alert.DoesNotExist:
                raise Http404

            if feed_type == "html":
                context = {
                    "alert": utils.ParseAlert(alert.content, feed_type,
                                              alert.uuid)
                }
                response = render_to_string("core/alert.html.tmpl", context)
                return HttpResponse(
                    BeautifulSoup(response, feed_type).prettify())

            return HttpResponse(alert.content, content_type="text/xml")

        feed_data = utils.GenerateFeed(feed_type)
        if feed_type == "json":
            if audience == "":
                return JsonResponse(feed_data, safe=False)
            new_feed = []
            for alert in feed_data:
                if alert["audience"] == audience:
                    new_feed.append(alert)
            return JsonResponse(new_feed, safe=False)

        return HttpResponse(feed_data, content_type="text/%s" % feed_type)
Beispiel #3
0
    def test_generate_feed_inactive_alert(self):
        """Tests XML feed with date after alert expiration date.

       Expiration date is 2014-08-10T23:55:12+00:00.
    """
        uuid, _, _ = utils.CreateAlert(self.draft_alert_content,
                                       self.TEST_USER_NAME)
        self.assertFalse(uuid in utils.GenerateFeed())
Beispiel #4
0
  def test_generate_feed_alerts_db_query(self):
    """Tests XML feed alerts order."""
    feed = xml_etree.fromstring(utils.GenerateFeed())  # Deals with Unicode.
    entries = []
    for entry in feed.findall(".//{http://www.w3.org/2005/Atom}entry"):
      entries.append(entry)

    self.assertEqual(len(entries), 2)  # Check the feed length.

    # Make sure alerts order is correct - most recent go first.
    last_alert = entries[0]
    previous_alert = entries[1]
    last_alert_created_at = last_alert.find(
        "{http://www.w3.org/2005/Atom}updated").text.strip()
    previous_alert_created_at = previous_alert.find(
        "{http://www.w3.org/2005/Atom}updated").text.strip()
    self.assertTrue(last_alert_created_at > previous_alert_created_at)
Beispiel #5
0
  def get(self, request, *args, **kwargs):
    feed_type = kwargs["feed_type"]

    if "alert_id" in kwargs:
      try:
        alert = models.Alert.objects.get(uuid=kwargs["alert_id"])
      except models.Alert.DoesNotExist:
        raise Http404

      if feed_type == "html":
        context = {
            "alert": utils.ParseAlert(alert.content, feed_type, alert.uuid)
        }
        response = render_to_string("core/alert.html.tmpl", context)
        return HttpResponse(BeautifulSoup(response, feed_type).prettify())

      return HttpResponse(alert.content, content_type="text/xml")

    return HttpResponse(utils.GenerateFeed(feed_type),
                        content_type="text/%s" % feed_type)