Esempio n. 1
0
  def test_unsubscribing_when_explicitly_subscribed(self):
    """Test that users can unsubscribe themselves.

    NOTE: Explicitly subscribed means that there exists a relevant notification
    config entry in database.
    """
    person = all_models.Person.query.first()

    config = all_models.NotificationConfig(
        person_id=person.id,
        notif_type="Email_Digest",
        enable_flag=True
    )
    db.session.add(config)
    db.session.flush()

    url = unsubscribe_url(person.id)
    response = self.client.get(url)
    self.assert200(response)

    config = all_models.NotificationConfig.query.filter_by(
        person_id=person.id, notif_type="Email_Digest"
    ).first()
    self.assertIsNotNone(config)
    self.assertFalse(config.enable_flag)
Esempio n. 2
0
 def test_unsubscribing_not_publicly_allowed(self):
   """Anonymous users should not be allowed to unsubscribe anyone."""
   self.client.get("/logout")
   person = all_models.Person.query.first()
   url = unsubscribe_url(person.id)
   response = self.client.get(url)
   self.assertEqual(response.status_code, 302)
Esempio n. 3
0
def modify_data(data):
    """Modify notification data dictionary.

  For easier use in templates, it computes/aggregates some additional
  notification data.
  together.

  Args:
    data (dict): notification data.

  Returns:
    dict: the received dict with some additional fields for easier traversal
      in the notification template.
  """
    # combine "my_tasks" from multiple cycles
    data["cycle_started_tasks"] = {}
    if "cycle_data" in data:
        for cycle in data["cycle_data"].values():
            if "my_tasks" in cycle:
                data["cycle_started_tasks"].update(cycle["my_tasks"])

    data["unsubscribe_url"] = unsubscribe_url(data["user"]["id"])

    # Move comment notifications for same object into list and sort by
    # created_at field
    sort_comments(data)
    data["DATE_FORMAT"] = DATE_FORMAT_US

    return data
Esempio n. 4
0
def modify_data(data):
  """Modify notification data dictionary.

  For easier use in templates, it computes/aggregates some additional
  notification data.
  together.

  Args:
    data (dict): notification data.

  Returns:
    dict: the received dict with some additional fields for easier traversal
      in the notification template.
  """
  # combine "my_tasks" from multiple cycles
  data["cycle_started_tasks"] = {}
  if "cycle_data" in data:
    for cycle in data["cycle_data"].values():
      if "my_tasks" in cycle:
        data["cycle_started_tasks"].update(cycle["my_tasks"])

  data["unsubscribe_url"] = unsubscribe_url(data["user"]["id"])

  # Move comment notifications for same object into list and sort by
  # created_at field
  sort_comments(data)
  data["DATE_FORMAT"] = DATE_FORMAT_US

  return data
Esempio n. 5
0
  def test_does_not_allow_unsubscribing_other_users(self):
    """Unsubscribing users other than self should results in HTTP 403."""
    person = all_models.Person.query.first()

    url = unsubscribe_url(person.id + 123)
    response = self.client.get(url)

    self.assertEqual(response.status_code, 403)
Esempio n. 6
0
  def test_unsubscribing_when_subscribed_by_default(self):
    """Test that users can unsubscribe themselves when no DB entry.

    By default, users are subscribed to daily digest emails even if there is no
    notification config entry in database, but unsubscribing such users must
    work, too.
    """
    person = all_models.Person.query.first()
    url = unsubscribe_url(person.id)
    response = self.client.get(url)
    self.assert200(response)

    person = all_models.Person.query.first()
    config = all_models.NotificationConfig.query.filter_by(
        person_id=person.id, notif_type="Email_Digest"
    ).first()
    self.assertIsNotNone(config)
    self.assertFalse(config.enable_flag)
Esempio n. 7
0
  def test_unsubscribing_when_already_unsubscribed(self):
    """Test that unsubscribing oneself when unsubscribed yields no error."""
    person = all_models.Person.query.first()
    config = all_models.NotificationConfig(
        person_id=person.id,
        notif_type="Email_Digest",
        enable_flag=False
    )
    db.session.add(config)
    db.session.flush()
    url = unsubscribe_url(person.id)
    response = self.client.get(url)
    self.assert200(response)

    config = all_models.NotificationConfig.query.filter_by(
        person_id=person.id, notif_type="Email_Digest"
    ).first()
    self.assertIsNotNone(config)
    self.assertFalse(config.enable_flag)