def testPost_WithValidSidParameter(self):
    sheriff_key = self._AddSheriff()
    test_keys = self._AddTests()
    selected_ranges = [(400, 900), (200, 700)]
    selected_keys = self._AddAnomalyEntities(
        selected_ranges, test_keys[0], sheriff_key)

    json_keys = json.dumps(selected_keys)
    state_id = short_uri.GenerateHash(','.join(selected_keys))
    page_state.PageState(id=state_id, value=json_keys).put()

    response = self.testapp.post('/group_report?sid=%s' % state_id)
    alert_list = self.GetJsonValue(response, 'alert_list')

    # Confirm the first N keys are the selected keys.
    first_keys = [alert_list[i]['key'] for i in xrange(len(selected_keys))]
    self.assertSetEqual(set(selected_keys), set(first_keys))
    self.assertEqual(2, len(alert_list))
Beispiel #2
0
    def testPost_WithValidSidParameter(self):
        sheriff_key = self._AddSheriff()
        test_keys = self._AddTests()
        selected_ranges = [(400, 900), (200, 700)]
        selected_keys = self._AddAnomalyEntities(selected_ranges, test_keys[0],
                                                 sheriff_key)

        json_keys = json.dumps(selected_keys)
        state_id = short_uri.GenerateHash(','.join(selected_keys))
        page_state.PageState(id=state_id, value=json_keys).put()

        response = self.testapp.post('/group_report?sid=%s' % state_id)
        alert_list = self.GetJsonValue(response, 'alert_list')

        self.assertEqual(unicode(selected_keys[1], 'utf-8'),
                         alert_list[0].get('key'))
        self.assertEqual(unicode(selected_keys[0], 'utf-8'),
                         alert_list[1].get('key'))
        self.assertEqual(2, len(alert_list))
Beispiel #3
0
    def _GetQueryStringForOldUri(self):
        """Gets a new query string if old URI parameters are present.

    SID is a hash string generated from a page state dictionary which is
    created here from old URI request parameters.

    Returns:
      A query string if request parameters are from old URI, otherwise None.
    """
        masters = self.request.get('masters')
        bots = self.request.get('bots')
        tests = self.request.get('tests')
        checked = self.request.get('checked')

        if not (masters and bots and tests):
            return None

        # Page state is a list of chart state.  Chart state is
        # a list of pair of test path and selected series which is used
        # to generate a chart on /report page.
        state = _CreatePageState(masters, bots, tests, checked)

        # Replace default separators to remove whitespace.
        state_json = json.dumps(state, separators=(',', ':'))
        state_id = short_uri.GenerateHash(state_json)

        # Save page state.
        if not ndb.Key(page_state.PageState, state_id).get():
            page_state.PageState(id=state_id, value=state_json).put()

        query_string = 'sid=' + state_id
        if self.request.get('start_rev'):
            query_string += '&start_rev=' + self.request.get('start_rev')
        if self.request.get('end_rev'):
            query_string += '&end_rev=' + self.request.get('end_rev')
        if self.request.get('rev'):
            query_string += '&rev=' + self.request.get('rev')
        return query_string