def testGet_WithNamespacedKey_ShowsPageWithBothVersions(self):
     namespaced_stored_object.Set('foo', 'XXXYYY')
     namespaced_stored_object.SetExternal('foo', 'XXXinternalYYY')
     response = self.testapp.get('/edit_site_config?key=foo')
     self.assertEqual(1, len(response.html('form')))
     self.assertIn('XXXYYY', response.body)
     self.assertIn('XXXinternalYYY', response.body)
 def testPost_WithKey_UpdatesNamespacedValues(self):
   namespaced_stored_object.Set('foo', 'XXXinternalYYY')
   namespaced_stored_object.SetExternal('foo', 'XXXYYY')
   self.testapp.post('/edit_site_config', {
       'key': 'foo',
       'external_value': '{"x": "y"}',
       'internal_value': '{"x": "yz"}',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   self.assertEqual({'x': 'yz'}, namespaced_stored_object.Get('foo'))
   self.assertEqual({'x': 'y'}, namespaced_stored_object.GetExternal('foo'))
示例#3
0
    def setUp(self):
        super(DescribeTest, self).setUp()
        self.SetUpApp([(r'/api/describe', describe.DescribeHandler)])
        self.SetCurrentClientIdOAuth(api_auth.OAUTH_CLIENT_ID_WHITELIST[0])

        external_key = update_test_suite_descriptors.CacheKey(
            'external', TEST_SUITE_NAME)
        namespaced_stored_object.SetExternal(
            external_key, {
                'measurements': ['measurement'],
                'bots': ['external:bot'],
                'cases': ['case'],
                'caseTags': {}
            })

        testing_common.AddTests(
            ['external'], ['bot'],
            {'test_suite': {
                'measurement': {
                    'case': {},
                }
            }})

        self.SetCurrentUserOAuth(testing_common.INTERNAL_USER)
        self.SetCurrentUser(testing_common.INTERNAL_USER.email())
        testing_common.AddTests(
            ['internal'], ['bot'],
            {'test_suite': {
                'measurement': {
                    'case': {},
                }
            }})
        t = utils.TestKey('internal/bot/test_suite').get()
        t.internal_only = True
        t.put()

        namespaced_stored_object.Set(
            external_key, {
                'measurements': ['measurement'],
                'bots': ['external:bot'],
                'cases': ['case'],
                'caseTags': {}
            })

        internal_key = update_test_suite_descriptors.CacheKey(
            'internal', TEST_SUITE_NAME)
        namespaced_stored_object.Set(
            internal_key, {
                'measurements': ['measurement'],
                'bots': ['internal:bot'],
                'cases': ['case'],
                'caseTags': {}
            })
示例#4
0
def SetCache(test_path, rows):
    """Sets the saved graph revisions data for a test.

  Args:
    test_path: A test path string.
    rows: A list of [revision, value, timestamp] triplets.
  """
    # This first set generally only sets the internal-only cache.
    namespaced_stored_object.Set(_CACHE_KEY % test_path, rows)

    # If this is an internal_only query for externally available data,
    # set the cache for that too.
    if datastore_hooks.IsUnalteredQueryPermitted():
        test = utils.TestKey(test_path).get()
        if test and not test.internal_only:
            namespaced_stored_object.SetExternal(_CACHE_KEY % test_path, rows)
示例#5
0
  def post(self):
    """Accepts posted values, makes changes, and shows the form again."""
    key = self.request.get('key')

    if not utils.IsInternalUser():
      self.RenderHtml('edit_site_config.html', {
          'error': 'Only internal users can post to this end-point.'
      })
      return

    if not key:
      self.RenderHtml('edit_site_config.html', {})
      return

    new_value_json = self.request.get('value').strip()
    new_external_value_json = self.request.get('external_value').strip()
    new_internal_value_json = self.request.get('internal_value').strip()

    template_params = {
        'key': key,
        'value': new_value_json,
        'external_value': new_external_value_json,
        'internal_value': new_internal_value_json,
    }

    try:
      new_value = json.loads(new_value_json or 'null')
      new_external_value = json.loads(new_external_value_json or 'null')
      new_internal_value = json.loads(new_internal_value_json or 'null')
    except ValueError:
      template_params['error'] = 'Invalid JSON in at least one field.'
      self.RenderHtml('edit_site_config.html', template_params)
      return

    old_value = stored_object.Get(key)
    old_external_value = namespaced_stored_object.GetExternal(key)
    old_internal_value = namespaced_stored_object.Get(key)

    stored_object.Set(key, new_value)
    namespaced_stored_object.SetExternal(key, new_external_value)
    namespaced_stored_object.Set(key, new_internal_value)

    _SendNotificationEmail(
        key, old_value, old_external_value, old_internal_value,
        new_value, new_external_value, new_internal_value)

    self.RenderHtml('edit_site_config.html', template_params)
 def testPost_SendsNotificationEmail(self):
     namespaced_stored_object.SetExternal('foo', {'x': 10, 'y': 2})
     namespaced_stored_object.Set('foo', {'z': 3, 'x': 1})
     self.testapp.post(
         '/edit_site_config', {
             'key': 'foo',
             'external_value': '{"x": 1, "y": 2}',
             'internal_value': '{"x": 1, "z": 3, "y": 2}',
             'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
         })
     messages = self.mail_stub.get_sent_messages()
     self.assertEqual(1, len(messages))
     self.assertEqual('*****@*****.**', messages[0].sender)
     self.assertEqual('*****@*****.**',
                      messages[0].to)
     self.assertEqual('Config "foo" changed by [email protected]',
                      messages[0].subject)
     self.assertIn(
         'Non-namespaced value diff:\n'
         '  null\n'
         '\n'
         'Externally-visible value diff:\n'
         '  {\n'
         '-   "x": 10, \n'
         '?         -\n'
         '\n'
         '+   "x": 1, \n'
         '    "y": 2\n'
         '  }\n'
         '\n'
         'Internal-only value diff:\n'
         '  {\n'
         '    "x": 1, \n'
         '+   "y": 2, \n'
         '    "z": 3\n'
         '  }\n', str(messages[0].body))
 def testSetExternal_InternalUser_ExternalVersionSet(self):
     self.SetCurrentUser('*****@*****.**')
     namespaced_stored_object.SetExternal('foo', 12345)
     self.assertIsNone(stored_object.Get('internal_only__foo'))
     self.assertEqual(12345, stored_object.Get('externally_visible__foo'))