예제 #1
0
    def test_news_notification(self):
        assessment = self.course.add_assessment()
        assessment.title = 'Assessment'
        assessment.html_content = 'assessment content'
        assessment.availability = courses.AVAILABILITY_AVAILABLE
        self.course.save()
        self.certificate_criteria.append(
            {'assessment_id': assessment.unit_id, 'pass_percent': 70.0})
        actions.submit_assessment(
            self, assessment.unit_id,
            {'answers': '', 'score': 70, 'assessment_type': assessment.unit_id},
            presubmit_checks=False)

        news_items = news.StudentNewsDao.get_news_items()
        self.assertEquals(1, len(news_items))
        item = news_items[0]
        now_ts = utc.now_as_timestamp()
        self.assertEquals(certificate.CERTIFICATE_HANDLER_PATH, item.url)
        self.assertEquals(certificate.RESOURCE_KEY, item.resource_key)
        self.assertAlmostEqual(
            now_ts, utc.datetime_to_timestamp(item.when), delta=10)

        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals(
            [news_tests_lib.NewsItem(
                'Course completion certificate earned!',
                certificate.CERTIFICATE_HANDLER_PATH, True)],
            news_tests_lib.extract_news_items_from_soup(soup))
    def test_announcement_news(self):
        actions.login('*****@*****.**')
        actions.register(self, 'John Doe')
        time.sleep(1)
        locale = 'de'
        announcement = self._add_announcement_and_translation(
            locale, is_draft=True)
        sent_data = {
            'key': str(announcement.key()),
            'title': 'Test Announcement',
            'date': utc.to_text(seconds=utc.now_as_timestamp()),
            'is_draft': False,
        }
        actions.login(self.ADMIN_EMAIL)
        response = self._put_announcement(sent_data)
        actions.login('*****@*****.**')

        # Verify announcement news item using news API directly
        news_items = news.CourseNewsDao.get_news_items()
        self.assertEquals(1, len(news_items))
        item = news_items[0]
        now_timestamp = utc.now_as_timestamp()
        self.assertEquals(
            announcements.AnnouncementsStudentHandler.URL.lstrip('/'), item.url)
        self.assertEquals(
            str(announcements.TranslatableResourceAnnouncement.key_for_entity(
                announcement)),
            item.resource_key)
        self.assertAlmostEqual(
            now_timestamp, utc.datetime_to_timestamp(item.when), delta=10)

        # Verify announcement news item looking at HTTP response to /course
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals(
            [news_tests_lib.NewsItem(
                'Test Announcement',
                announcements.AnnouncementsStudentHandler.URL.lstrip('/'),
                True)],
            news_tests_lib.extract_news_items_from_soup(soup))

        # Verify announcement news item translated title.
        self._set_prefs_locale(locale)
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals(
            [news_tests_lib.NewsItem(
                'TEST ANNOUNCEMENT',
                announcements.AnnouncementsStudentHandler.URL.lstrip('/'),
                True)],
            news_tests_lib.extract_news_items_from_soup(soup))

        # Delete the announcement; news item should also go away.
        actions.login(self.ADMIN_EMAIL)
        self._delete_announcement(str(announcement.key()))
        actions.login('*****@*****.**')
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals([], news_tests_lib.extract_news_items_from_soup(soup))
 def should_start_jobs():
     now_timestamp = utc.hour_start(utc.now_as_timestamp())
     status = StartAvailabilityJobsStatus.get_singleton()
     last_run = utc.hour_start(
         utc.datetime_to_timestamp(status.last_run))
     if now_timestamp > last_run:
         status.last_run = utc.timestamp_to_datetime(now_timestamp)
         StartAvailabilityJobsStatus.update_singleton(status)
         return True
     return False
예제 #4
0
 def should_start_jobs():
     now_timestamp = utc.hour_start(utc.now_as_timestamp())
     status = StartAvailabilityJobsStatus.get_singleton()
     last_run = utc.hour_start(
         utc.datetime_to_timestamp(status.last_run))
     if now_timestamp > last_run:
         status.last_run = utc.timestamp_to_datetime(now_timestamp)
         StartAvailabilityJobsStatus.update_singleton(status)
         return True
     return False
예제 #5
0
 def map(cls, student):
     if student.is_enrolled:
         yield (TotalEnrollmentEntity.COUNTING, 1)
         bin_seconds_since_epoch = BinnedEnrollmentsDTO.bin(
             utc.datetime_to_timestamp(student.enrolled_on))
         yield (bin_seconds_since_epoch, 1)
예제 #6
0
 def inc(cls, namespace_name, date_time, offset=1):
     """Increments the Datastore value of a counter in a specific bin."""
     dto = cls.load_or_default(namespace_name)
     dto.inc(utc.datetime_to_timestamp(date_time), offset=offset)
     cls._save(dto)  # Save altered/new DTO as entity.
     return dto
예제 #7
0
 def set(cls, namespace_name, date_time, count):
     """Sets the Datastore value of a counter in a specific bin."""
     dto = cls.load_or_default(namespace_name)
     dto.set(utc.datetime_to_timestamp(date_time), count)
     cls._save(dto)  # Save altered/new DTO as entity.
     return dto
예제 #8
0
 def get(cls, namespace_name, date_time):
     """Returns value of a binned enrollment counter from the Datastore."""
     return cls.load_or_default(namespace_name).get(
         utc.datetime_to_timestamp(date_time))
예제 #9
0
 def map(cls, student):
     if student.is_enrolled:
         yield (TotalEnrollmentEntity.COUNTING, 1)
         bin_seconds_since_epoch = BinnedEnrollmentsDTO.bin(
             utc.datetime_to_timestamp(student.enrolled_on))
         yield (bin_seconds_since_epoch, 1)
예제 #10
0
 def inc(cls, namespace_name, date_time, offset=1):
     """Increments the Datastore value of a counter in a specific bin."""
     dto = cls.load_or_default(namespace_name)
     dto.inc(utc.datetime_to_timestamp(date_time), offset=offset)
     cls._save(dto) # Save altered/new DTO as entity.
     return dto
예제 #11
0
 def set(cls, namespace_name, date_time, count):
     """Sets the Datastore value of a counter in a specific bin."""
     dto = cls.load_or_default(namespace_name)
     dto.set(utc.datetime_to_timestamp(date_time), count)
     cls._save(dto) # Save altered/new DTO as entity.
     return dto
예제 #12
0
 def get(cls, namespace_name, date_time):
     """Returns value of a binned enrollment counter from the Datastore."""
     return cls.load_or_default(namespace_name).get(
         utc.datetime_to_timestamp(date_time))
    def test_announcement_news(self):
        actions.login('*****@*****.**')
        actions.register(self, 'John Doe')
        time.sleep(1)
        locale = 'de'
        announcement = self._add_announcement_and_translation(locale,
                                                              is_draft=True)
        sent_data = {
            'key': str(announcement.key()),
            'title': 'Test Announcement',
            'date': utc.to_text(seconds=utc.now_as_timestamp()),
            'is_draft': False,
        }
        actions.login(self.ADMIN_EMAIL)
        response = self._put_announcement(sent_data)
        actions.login('*****@*****.**')

        # Verify announcement news item using news API directly
        news_items = news.CourseNewsDao.get_news_items()
        self.assertEquals(1, len(news_items))
        item = news_items[0]
        now_timestamp = utc.now_as_timestamp()
        self.assertEquals(
            announcements.AnnouncementsStudentHandler.URL.lstrip('/'),
            item.url)
        self.assertEquals(
            str(
                announcements.TranslatableResourceAnnouncement.key_for_entity(
                    announcement)), item.resource_key)
        self.assertAlmostEqual(now_timestamp,
                               utc.datetime_to_timestamp(item.when),
                               delta=10)

        # Verify announcement news item looking at HTTP response to /course
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals([
            news_tests_lib.NewsItem(
                'Test Announcement',
                announcements.AnnouncementsStudentHandler.URL.lstrip('/'),
                True)
        ], news_tests_lib.extract_news_items_from_soup(soup))

        # Verify announcement news item translated title.
        self._set_prefs_locale(locale)
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals([
            news_tests_lib.NewsItem(
                'TEST ANNOUNCEMENT',
                announcements.AnnouncementsStudentHandler.URL.lstrip('/'),
                True)
        ], news_tests_lib.extract_news_items_from_soup(soup))

        # Delete the announcement; news item should also go away.
        actions.login(self.ADMIN_EMAIL)
        self._delete_announcement(str(announcement.key()))
        actions.login('*****@*****.**')
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals([],
                          news_tests_lib.extract_news_items_from_soup(soup))