def test_is_active(self):
        # Test the rules about when an Announcement is 'active'
        assert True == Announcement(**self.active).is_active
        assert False == Announcement(**self.expired).is_active
        assert False == Announcement(**self.forthcoming).is_active

        # An announcement that ends today is still active.
        expires_today = dict(self.active)
        expires_today["finish"] = self.today
        assert True == Announcement(**self.active).is_active
Пример #2
0
    def test_is_active(self):
        # Test the rules about when an Announcement is 'active'
        eq_(True, Announcement(**self.active).is_active)
        eq_(False, Announcement(**self.expired).is_active)
        eq_(False, Announcement(**self.forthcoming).is_active)

        # An announcement that ends today is still active.
        expires_today = dict(self.active)
        expires_today['finish'] = self.today
        eq_(True, Announcement(**self.active).is_active)
Пример #3
0
 def test_for_authentication_document(self):
     # Demonstrate the publishable form of an Announcement.
     #
     # 'start' and 'finish' will be ignored, as will the extra value
     # that has no meaning within Announcement.
     announcement = Announcement(extra="extra value", **self.active)
     eq_(dict(id="active", content="A sample announcement."),
         announcement.for_authentication_document
     )
Пример #4
0
 def test_json_ready(self):
     # Demonstrate the form of an Announcement used to store in the database.
     #
     # 'start' and 'finish' will be converted into strings the extra value
     # that has no meaning within Announcement will be ignored.
     announcement = Announcement(extra="extra value", **self.active)
     eq_(
         dict(
             id="active",
             content="A sample announcement.",
             start=announcement.start.strftime(AnnouncementListValidator.DATE_FORMAT),
             finish=announcement.finish.strftime(AnnouncementListValidator.DATE_FORMAT),
         ),
         announcement.json_ready
     )
    def test_format(self):
        # Test our ability to format the output of validate_announcements for storage
        # in the database.

        validator = AnnouncementListValidator()
        announcements = [self.active, self.forthcoming]

        # Convert the announcements into a single JSON string.
        ready_for_storage = validator.format_as_string(announcements)

        # Now examine the string by converting it back from JSON to a list.
        as_list = json.loads(ready_for_storage)

        # The list contains dictionary representations of self.active
        # and self.forthcoming. But they're not exactly the same as
        # self.active and self.forthcoming -- they were converted into
        # Announcement objects and then back to dictionaries using
        # Announcement.json_ready.
        assert [Announcement(**x).json_ready for x in announcements] == as_list