def test_send_activity_summary(self):
     # put some data into datastore
     ActivitySummaryModel(id=ACTIVITY_SUMMARY_MODEL_ID_KEY).put()
     data = ActivitySummaryModel.get_data()
     formatted_data = pprint.pformat(data)
     send_email(subject="activity summary",
                body="activity summary: " + "\n\n" + formatted_data)
     ActivitySummaryModel.reset()
Esempio n. 2
0
 def send_activity_summary(self):
     msg = "Sending activity summary email at %s ..." % get_current_timestamp_str(
     )
     logging.info(msg)
     formatted_data = pprint.pformat(ActivitySummaryModel.get_data())
     send_email(subject="activity summary",
                body="activity summary: " + "\n\n" + formatted_data)
     ActivitySummaryModel.reset()
     logging.info("Finished sending activity summary.")
     self.response.out.write(msg)
 def test_update_overview_check_running_builds(self):
     # put some data into datastore
     asm = ActivitySummaryModel(id=ACTIVITY_SUMMARY_MODEL_ID_KEY,
                                overview_update_counter=72,
                                sent_emails_counter=4,
                                stopped_builds_counter=1,
                                overview_update_counter_total=3448,
                                sent_emails_counter_total=593,
                                stopped_builds_counter_total=134)
     asm.put()
     self.jenkins.update_overview_check_running_builds()
     asm = ActivitySummaryModel.get_data()
     assert asm["overview_update_counter"] == 73
     assert asm["overview_update_counter_total"] == 3449
 def test_initialization(self):
     initialization()
     d = ActivitySummaryModel.get_data()
     items = ('sent_emails_counter_total',
              'stopped_builds_counter',
              'sent_emails_counter',
              'stopped_builds_counter_total',
              'overview_update_counter_total',
              'overview_update_counter')
     for i in items:
         assert d[i] == 0
     b = BuildsStatisticsModel.get_builds_data()
     assert b["num_builds"] == 0
     assert b["builds"] == {}
    def test_activity_summary_model(self):
        asm = ActivitySummaryModel(id=ACTIVITY_SUMMARY_MODEL_ID_KEY,
                                   overview_update_counter=72,
                                   sent_emails_counter=4,
                                   stopped_builds_counter=1,
                                   overview_update_counter_total=3448,
                                   sent_emails_counter_total=593,
                                   stopped_builds_counter_total=134,
                                   builds_stats_update_counter=65,
                                   builds_stats_update_counter_total=165)
        asm.put()
        ActivitySummaryModel.reset()
        asm = ActivitySummaryModel.get_data()
        assert asm["overview_update_counter"] == 0
        assert asm["sent_emails_counter"] == 0
        assert asm["builds_stats_update_counter"] == 0
        assert asm["overview_update_counter_total"] == 3448
        assert asm["stopped_builds_counter_total"] == 134
        assert asm["builds_stats_update_counter_total"] == 165

        ActivitySummaryModel.increase_counters(which_counters=["overview_update_counter"])

        asm = ActivitySummaryModel.get_data()
        assert asm["overview_update_counter"] == 1
        assert asm["overview_update_counter_total"] == 3449

        ActivitySummaryModel.increase_counters(which_counters=["sent_emails_counter",
                                                               "stopped_builds_counter",
                                                               "builds_stats_update_counter"])
        asm = ActivitySummaryModel.get_data()
        assert asm["sent_emails_counter"] == 1
        assert asm["sent_emails_counter_total"] == 594
        assert asm["stopped_builds_counter_total"] == 135
        assert asm["stopped_builds_counter"] == 1
        assert asm["builds_stats_update_counter_total"] == 166
        assert asm["builds_stats_update_counter"] == 1
Esempio n. 6
0
 def get_builds_stats(self):
     try:
         arg = self.request.get("days_limit", 1)
         days_limit = int(arg)
     except Exception as ex:
         self.response.out.write("wrong argument: '%s'" % arg)
         return
     resp = BuildsStatisticsModel.get_builds_data(days_limit=days_limit)
     asm = ActivitySummaryModel.get_data()
     if asm:
         resp["builds_statistics_model_last_update_at"] = \
             asm["builds_statistics_model_last_update_at"]
     self.response.headers["Content-Type"] = "application/json"
     # seconds (10minutes)
     self.response.headers[
         "Cache-Control"] = "max-age=600"  # , must-revalidate, private"
     # self.response.cache_control = 'public'
     # self.response.cache_control.max_age = 600
     self.response.out.write(json.dumps(resp))
Esempio n. 7
0
def initialization():
    """
    Initialize datastore types.

    """
    msg = "Initialization run at %s ..." % get_current_timestamp_str()
    log.info(msg)
    if ActivitySummaryModel.get_data() is None:
        log.debug("ActivitySummaryModel initialization ...")
        activity = ActivitySummaryModel(id=ACTIVITY_SUMMARY_MODEL_ID_KEY)
        activity.put()
        log.debug("Finished ActivitySummaryModel initialization.")
    else:
        log.debug("ActivitySummaryModel is already initialized.")
    if len(BuildsStatisticsModel.query().fetch(keys_only=True)) == 0:
        deferred.defer(get_jenkins_instance().builds_stats_init)
        log.debug("Finished BuildsStatisticsModel initialization.")
    else:
        log.debug("BuildStatisticsModel is already initialized.")
    return msg
 def test_get_activity_summary(self):
     resp = ActivitySummaryModel.get_data()
     json.dumps(resp)
 def test_send_activity_summary_no_data(self):
     data = ActivitySummaryModel.get_data()
     formatted_data = pprint.pformat(data)
     send_email(subject="activity summary",
                body="activity summary: " + "\n\n" + formatted_data)
Esempio n. 10
0
 def get_activity_summary(self):
     resp = ActivitySummaryModel.get_data()
     self.response.headers["Content-Type"] = "application/json"
     self.response.out.write(json.dumps(resp))