Пример #1
0
  def test_end2end_alert_cancel(self):
    """Emulates existing alert cancellation process using webdriver."""
    initial_dict = {
        "category": "Geo",
        "response_type": "Avoid",
        "urgency": "Expected",
        "severity": "Moderate",
        "certainty": "Likely",
        "title": "Alert that will be cancelled",
        "area_desc": "This and that area",
        "event": "Some event to be cancelled",
        "geocodes": [{
            "name": "geocode name",
            "value": "geocode value",
        }]
    }

    # Create initial alert.
    uuid = self.CreateAlert(initial_dict)
    initial_dict["alert_id"] = uuid
    self.assertTrue(models.Alert.objects.filter(uuid=uuid).exists())

    # Ensure that feed contains new alert.
    response = self.client.get("/feed.xml")
    self.assertContains(response, uuid)
    initial_alert_dict = self.CheckValues(uuid, initial_dict)
    sent_at = initial_alert_dict["sent"]
    initial_alert_reference = "%s@%s,%s,%s" % (self.TEST_USER_LOGIN,
                                               settings.SITE_DOMAIN,
                                               uuid, sent_at.isoformat())
    # Create alert update.
    self.GoToAlertsTab()
    self.OpenLatestAlert()
    self.ClickCancelAlertButton()
    self.GoToMessageTab()
    self.GoToAreaTab()
    self.GoToReleaseTab()
    self.SetUsername(self.TEST_USER_LOGIN)
    self.SetPassword(self.TEST_USER_PASSWORD)
    self.ReleaseAlert()
    uuid = UUID_RE.findall(self.GetUuid())[0]

    initial_dict["alert_id"] = uuid
    self.assertTrue(models.Alert.objects.filter(uuid=uuid).exists())

    canceled_alert_dict = self.CheckValues(uuid, initial_dict)
    self.assertEqual(canceled_alert_dict["msg_type"], "Cancel")
    sent_at = canceled_alert_dict["sent"]
    expires_at = canceled_alert_dict["expires"]
    self.assertEqual((expires_at - sent_at).seconds / 60, 60)
    canceled_alert_references = canceled_alert_dict["references"]
    self.assertEqual(initial_alert_reference, canceled_alert_references)
Пример #2
0
  def test_end2end_alert_cancel(self):
    """Emulates existing alert cancellation process using webdriver."""
    initial_dict = {
        "category": "Geo",
        "response_type": "Avoid",
        "urgency": "Expected",
        "severity": "Moderate",
        "certainty": "Likely",
        "title": "Alert that will be cancelled",
        "area_desc": "This and that area",
        "event": "Some event to be cancelled",
        "geocodes": [{
            "name": "geocode name",
            "value": "geocode value",
        }]
    }

    # Create initial alert.
    uuid = self.CreateAlert(initial_dict)
    initial_dict["alert_id"] = uuid
    self.assertTrue(models.Alert.objects.filter(uuid=uuid).exists())

    # Ensure that feed contains new alert.
    response = self.client.get("/feed.xml")
    self.assertContains(response, uuid)
    initial_alert_dict = self.CheckValues(uuid, initial_dict)
    sent_at = initial_alert_dict["sent"]
    initial_alert_reference = "%s@%s,%s,%s" % (self.TEST_USER_LOGIN,
                                               settings.SITE_DOMAIN,
                                               uuid, sent_at.isoformat())
    # Create alert update.
    self.GoToAlertsTab()
    self.OpenLatestAlert()
    self.ClickCancelAlertButton()
    self.GoToMessageTab()
    self.GoToAreaTab()
    self.GoToReleaseTab()
    self.SetUsername(self.TEST_USER_LOGIN)
    self.SetPassword(self.TEST_USER_PASSWORD)
    self.ReleaseAlert()
    uuid = UUID_RE.findall(self.GetUuid())[0]

    initial_dict["alert_id"] = uuid
    self.assertTrue(models.Alert.objects.filter(uuid=uuid).exists())

    canceled_alert_dict = self.CheckValues(uuid, initial_dict)
    self.assertEqual(canceled_alert_dict["msg_type"], "Cancel")
    sent_at = canceled_alert_dict["sent"]
    expires_at = canceled_alert_dict["expires"]
    self.assertEqual((expires_at - sent_at).seconds / 60, 60)
    canceled_alert_references = canceled_alert_dict["references"]
    self.assertEqual(initial_alert_reference, canceled_alert_references)
Пример #3
0
  def CreateAlert(self, golden_dict, expiration=None, skip_login=False,
                  update=False):
    """Creates alert based on passed dictionary. Supports log in when needed."""
    if not skip_login:
      self.webdriver.get(self.live_server_url)
      self.GoToAlertsTab()
      self.Login()

    if not update:
      # Alert tab.
      self.GoToAlertTab()

    self.SetCategory(golden_dict["category"])
    self.SetResponseType(golden_dict["response_type"])
    self.SetUrgency(golden_dict["urgency"])
    self.SetSeverity(golden_dict["severity"])
    self.SetCertainty(golden_dict["certainty"])
    if expiration:
      self.SetExpiration(expiration)
      if expiration == "Other":
        self.SetOtherTextExpireMinutes(45)

    # Message tab.
    self.GoToMessageTab()
    if "language" in golden_dict:
      self.SetLanguage(golden_dict["language"])
    self.SetHeadline(golden_dict["title"])
    if "event" in golden_dict:
      self.SetEvent(golden_dict["event"])
    self.SetAlertSenderName(self.sender_name)
    if golden_dict.get("description"):
      self.SetDescription(golden_dict["description"])
    self.SetInstruction(self.instruction)
    self.SetContact(self.contact)
    if "web" in golden_dict:
      self.SetWeb(golden_dict["web"])

    # Area tab.
    self.GoToAreaTab()
    self.SetArea(golden_dict["area_desc"])

    if "geocodes" in golden_dict:
      geocodes = golden_dict["geocodes"][0]
      self.SetGeocode(geocodes["name"], geocodes["value"])

    # Release tab.
    self.GoToReleaseTab()
    self.SetUsername(self.TEST_USER_LOGIN)
    self.SetPassword(self.TEST_USER_PASSWORD)
    self.ReleaseAlert()

    return UUID_RE.findall(self.GetUuid())[0]
Пример #4
0
  def test_create_alert_created(self):
    """Tests alert created successfully."""
    alert_uuid, is_valid, error = utils.CreateAlert(self.draft_alert_content,
                                                    self.TEST_USER_NAME)
    self.assertTrue(UUID_RE.match(alert_uuid))
    self.assertTrue(is_valid)
    self.assertEquals(error, None)

    alert = models.Alert.objects.get(uuid=alert_uuid)
    alert_dict = utils.ParseAlert(alert.content, "xml", alert.uuid)
    draft_dict = utils.ParseAlert(self.draft_alert_content, "xml", alert.uuid)
    # Remove alert IDs due to their random nature.
    del alert_dict["alert_id"]
    del draft_dict["alert_id"]
    self.assertDictEqual(alert_dict, draft_dict)
Пример #5
0
  def test_create_alert_created(self):
    """Tests alert created successfully."""
    alert_uuid, is_valid, error = utils.CreateAlert(self.draft_alert_content,
                                                    self.TEST_USER_NAME)
    self.assertTrue(UUID_RE.match(alert_uuid))
    self.assertTrue(is_valid)
    self.assertEqual(error, None)

    alert = models.Alert.objects.get(uuid=alert_uuid)
    alert_dict = utils.ParseAlert(alert.content, "xml", alert.uuid)
    draft_dict = utils.ParseAlert(self.draft_alert_content, "xml", alert.uuid)
    # Remove alert IDs due to their random nature.
    del alert_dict["alert_id"]
    del draft_dict["alert_id"]
    self.assertDictEqual(alert_dict, draft_dict)
Пример #6
0
  def test_end2end_alert_create_from_template(self):
    """Emulates alert from template creation process using webdriver.

       Afrer webdriver part is done it checks whether alert file has created
       in active alerts directory and deletes alert file after that.
    """

    self.GoToAlertsTab()
    self.Login()

    # Alert tab.
    self.GoToAlertTab()
    self.SetMessageTemplate(1)

    # Message tab.
    self.GoToMessageTab()
    self.SetAlertSenderName(self.sender_name)
    self.SetContact(self.contact)

    # Area tab.
    self.GoToAreaTab()
    self.SetAreaTemplate(4)

    # Release tab.
    self.GoToReleaseTab()
    self.SetUsername(self.TEST_USER_LOGIN)
    self.SetPassword(self.TEST_USER_PASSWORD)
    self.ReleaseAlert()

    alert_uuid = UUID_RE.findall(self.GetUuid())[0]
    self.assertTrue(models.Alert.objects.filter(uuid=alert_uuid).exists())

    # Ensure that feed contains new alert.
    response = self.client.get("/feed.xml")
    self.assertContains(response, alert_uuid)

    # Check alert XML against initial values.
    alert = models.Alert.objects.get(uuid=alert_uuid)
    message_template_xml = models.MessageTemplate.objects.get(id=1).content
    area_template_xml = models.AreaTemplate.objects.get(id=4).content
    alert_dict = utils.ParseAlert(alert.content, "xml", alert_uuid)
    message_dict = utils.ParseAlert(message_template_xml, "xml", alert_uuid)
    area_dict = utils.ParseAlert(area_template_xml, "xml", alert_uuid)
    alert_expires_at = alert_dict["expires"]
    alert_sent_at = alert_dict["sent"]
    self.assertEqual((alert_expires_at - alert_sent_at).seconds / 60,
                     int(message_dict["expiresDurationMinutes"]))
    del message_dict["expiresDurationMinutes"]

    # Message template assertions.
    for key in message_dict:
      if message_dict.get(key):
        self.assertEqual(alert_dict[key], message_dict[key])

    # Area template assertions.
    for key in area_dict:
      if area_dict[key]:
        self.assertEqual(alert_dict[key], area_dict[key])

    # Check web field is set to default.
    alert_default_web = "%s%s" % (settings.SITE_URL,
                                  reverse("alert", args=[alert_uuid, "html"]))
    self.assertEqual(alert_dict["web"], alert_default_web)
Пример #7
0
  def test_end2end_alert_create_from_template(self):
    """Emulates alert from template creation process using webdriver.

       Afrer webdriver part is done it checks whether alert file has created
       in active alerts directory and deletes alert file after that.
    """

    self.GoToAlertsTab()
    self.Login()

    # Alert tab.
    self.GoToAlertTab()
    self.SetMessageTemplate(1)

    # Message tab.
    self.GoToMessageTab()
    self.SetAlertSenderName(self.sender_name)
    self.SetContact(self.contact)

    # Area tab.
    self.GoToAreaTab()
    self.SetAreaTemplate(4)

    # Release tab.
    self.GoToReleaseTab()
    self.SetUsername(self.TEST_USER_LOGIN)
    self.SetPassword(self.TEST_USER_PASSWORD)
    self.ReleaseAlert()

    alert_uuid = UUID_RE.findall(self.GetUuid())[0]
    self.assertTrue(models.Alert.objects.filter(uuid=alert_uuid).exists())

    # Ensure that feed contains new alert.
    response = self.client.get("/feed.xml")
    self.assertContains(response, alert_uuid)

    # Check alert XML against initial values.
    alert = models.Alert.objects.get(uuid=alert_uuid)
    message_template_xml = models.MessageTemplate.objects.get(id=1).content
    area_template_xml = models.AreaTemplate.objects.get(id=1).content
    alert_dict = utils.ParseAlert(alert.content, "xml", alert_uuid)
    message_dict = utils.ParseAlert(message_template_xml, "xml", alert_uuid)
    area_dict = utils.ParseAlert(area_template_xml, "xml", alert_uuid)
    alert_expires_at = alert_dict["expires"]
    alert_sent_at = alert_dict["sent"]
    self.assertEqual((alert_expires_at - alert_sent_at).seconds / 60,
                     int(message_dict["expiresDurationMinutes"]))

    # Message template assertions.
    for key in message_dict:
      if not message_dict.get(key) or not alert_dict.get(key):
        continue  # We need values present in both template and alert files.
      self.assertEqual(alert_dict[key], message_dict[key])

    # Area template assertions.
    for key in area_dict:
      if not area_dict[key]:
        continue  # We need values present in both template and alert files.
      self.assertEqual(alert_dict[key], area_dict[key])

    # Check web field is set to default.
    alert_default_web = "%s%s" % (settings.SITE_URL,
                                  reverse("alert", args=[alert_uuid, "html"]))
    self.assertEqual(alert_dict["web"], alert_default_web)