コード例 #1
0
 def testInvalidRegexAutoBisect(self):
     with self.assertRaisesRegex(validator.InvalidPattern, 'no argument'):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Regex",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: {
                                   match: [{regex: ".*"}]
                                }
                                auto_triage {
                                  rules: {
                                    match: {regex: ".*"}
                                  }
                                }
                                auto_bisection {
                                  rules: {
                                    match: {regex: "*"}
                                  }
                                }
                              }
                            ]
                          """)
     with self.assertRaisesRegex(validator.InvalidPattern, 'no argument'):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Regex",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: {
                                   match: [{regex: ".*"}]
                                   exclude: [{regex: ".*"}]
                                }
                                auto_triage {
                                  rules: {
                                    match: {regex: ".*"}
                                  }
                                }
                                auto_bisection {
                                  rules: {
                                    match: {regex: ".*"}
                                    exclude: {regex: "*"}
                                  }
                                }
                              }
                            ]
                          """)
コード例 #2
0
 def testGoodCase(self):
     subscriptions = validator.Validate("""
       subscriptions: [{
         name: "Release Team"
         contact_email: "*****@*****.**"
         bug_labels: ["release-blocker"]
         bug_components: ["Sample>Component"]
           rules: { match: [{glob: "project/**"}] }
       },
       {
         name: "Memory Team",
         contact_email: "*****@*****.**",
         bug_labels: ["memory-regressions"],
         rules: { match: [{regex: "^project/.*memory_.*$"}] },
         anomaly_configs: [
           {
             min_relative_change: 0.01
             rules: {
               match: {
                 regex: "^project/platform/.*/memory_peak$"
               }
             }
           }
         ]
       }]""")
     self.assertIsNotNone(subscriptions)
コード例 #3
0
 def testValidAutoTriageAndAutoBisect(self):
     _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Regex",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: {
                                   match: [{regex: ".*"}]
                                   exclude: [{regex: ".*"}]
                                }
                                auto_triage {
                                  rules: {
                                    match: {regex: ".*"}
                                    exclude: {regex: ".*"}
                                  }
                                }
                                auto_bisection {
                                  rules: {
                                    match: {regex: ".*"}
                                    exclude: {regex: ".*"}
                                  }
                                }
                              }
                            ]
                          """)
コード例 #4
0
ファイル: luci_config.py プロジェクト: owatch01/catapult
  def Transform(config):
    missing_fields = required_fields.difference(config)
    if len(missing_fields):
      raise InvalidConfigError(config, missing_fields)

    # We use a combination of the config set, revision, and content_hash to
    # identify this particular configuration.
    key = client.key(
        'Subscription',
        '{config_set}:{revision}'.format(**config),
        parent=subscription_index_key)
    try:
      sheriff_config = validator.Validate(
          base64.standard_b64decode(config['content']))
    except validator.Error as error:
      raise InvalidContentError(config, error)

    entity = datastore.Entity(
        key=key, exclude_from_indexes=['sheriff_config', 'url'])
    entity.update({
        'config_set': config['config_set'],
        'revision': config['revision'],
        'content_hash': config['content_hash'],
        'url': config['url'],
        'sheriff_config': sheriff_config.SerializeToString()
    })
    return (key, entity)
コード例 #5
0
ファイル: validator_test.py プロジェクト: simatei/catapult
 def testInvalidJSON(self):
     with self.assertRaisesRegexp(validator.InvalidJSON,
                                  'JSON Validation Error'):
         _ = validator.Validate("""
                          {
                          "subscriptions": ...
                          }
                          """)
コード例 #6
0
 def testMissingName(self):
   with self.assertRaises(validator.MissingName):
     _ = validator.Validate("""
                              subscriptions: [
                                {
                                  notification_email: "missing-name@domain",
                                  bug_labels: ["test-blocker"],
                                  bug_components: ["Sample>Component"],
                                  patterns: [{glob: "project/**"}]
                                }
                              ]
                            """)
コード例 #7
0
 def testMissingName(self):
     with self.assertRaises(validator.MissingName):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                contact_email: "missing-name@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: { match: [{glob: "project/**"}] }
                              }
                            ]
                          """)
コード例 #8
0
 def testMissingPattern(self):
     with self.assertRaises(validator.MissingPatterns):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "No Patterns",
                                contact_email: "no-patterns@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"]
                              }
                            ]
                          """)
コード例 #9
0
 def testMissingEmail(self):
     with self.assertRaises(validator.MissingEmail):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Missing Email",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: { match: [{glob: "project/**"}] }
                              }
                            ]
                          """)
コード例 #10
0
 def testInvalidRegexMatch(self):
     with self.assertRaisesRegex(validator.InvalidPattern, 'no argument'):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Regex",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: { match: [{regex: "*"}] }
                              }
                            ]
                          """)
コード例 #11
0
 def testMissingEmptyPattern(self):
   with self.assertRaises(validator.MissingPatterns):
     _ = validator.Validate("""
                              subscriptions: [
                                {
                                  name: "Empty List Patterns",
                                  notification_email: "no-patterns@domain",
                                  bug_labels: ["test-blocker"],
                                  bug_components: ["Sample>Component"],
                                  patterns: []
                                }
                              ]
                            """)
コード例 #12
0
def UnionAsBinaryStringWithIndexedOffsetData(o, schema, path):
    representation = cStringIO.StringIO()
    for idx, possibleSchemaType in enumerate(schema['optionTypes']):
        if len(validator.Validate(possibleSchemaType, o)) == 0:
            binaryIndex = uint32.pack(idx)
            representation.write(binaryIndex)
            itemRepresentation, indexedOffsetData = RepresentAsBinaryWithIndexedOffsetData(o, possibleSchemaType, FsdDataPathObject('<%s>' % possibleSchemaType['type'], parent=path))
            if not indexedOffsetData.isEmpty():
                indexedOffsetData.AddOffset(len(binaryIndex))
            representation.write(itemRepresentation)
            return (representation.getvalue(), indexedOffsetData)

    raise ValueError('Could not represent %s as any type in union' % str(o))
コード例 #13
0
 def testInvalidEmptyGlob(self):
     with self.assertRaisesRegex(validator.InvalidPattern,
                                 'glob must not be empty'):
         _ = validator.Validate("""
                            subscriptions: [
                              {
                                name: "Empty Glob",
                                contact_email: "bad-pattern@domain",
                                bug_labels: ["test-blocker"],
                                bug_components: ["Sample>Component"],
                                rules: { match: [{glob: ""}] }
                              }
                            ]
                          """)
コード例 #14
0
 def testInvalidUndefinedPattern(self):
   with self.assertRaisesRegexp(validator.InvalidPattern,
                                'must provide either \'glob\' or \'regex\''):
     _ = validator.Validate("""
                              subscriptions: [
                                {
                                  name: "Bad Pattern",
                                  notification_email: "bad-pattern@domain",
                                  bug_labels: ["test-blocker"],
                                  bug_components: ["Sample>Component"],
                                  patterns: [{}]
                                }
                              ]
                            """)
コード例 #15
0
 def testInvalidEmptyRegex(self):
   with self.assertRaisesRegexp(validator.InvalidPattern,
                                'regex must not be empty'):
     _ = validator.Validate("""
                              subscriptions: [
                                {
                                  name: "Empty Regex",
                                  notification_email: "bad-pattern@domain",
                                  bug_labels: ["test-blocker"],
                                  bug_components: ["Sample>Component"],
                                  patterns: [{regex: ""}]
                                }
                              ]
                            """)
コード例 #16
0
ファイル: validator_test.py プロジェクト: simatei/catapult
 def testMissingPattern(self):
     with self.assertRaises(validator.MissingPatterns):
         _ = validator.Validate("""
                          {
                            "subscriptions": [
                              {
                                "name": "No Patterns",
                                "notification_email": "no-patterns@domain",
                                "bug_labels": ["test-blocker"],
                                "bug_components": ["Sample>Component"]
                              }
                            ]
                          }
                          """)
コード例 #17
0
ファイル: validator_test.py プロジェクト: simatei/catapult
 def testMissingName(self):
     with self.assertRaises(validator.MissingName):
         _ = validator.Validate("""
                          {
                            "subscriptions": [
                              {
                                "notification_email": "missing-name@domain",
                                "bug_labels": ["test-blocker"],
                                "bug_components": ["Sample>Component"],
                                "patterns": [{"glob": "project/**"}]
                              }
                            ]
                          }
                          """)
コード例 #18
0
ファイル: validator_test.py プロジェクト: simatei/catapult
 def testMissingEmail(self):
     with self.assertRaises(validator.MissingEmail):
         _ = validator.Validate("""
                          {
                            "subscriptions": [
                              {
                                "name": "Missing Email",
                                "bug_labels": ["test-blocker"],
                                "bug_components": ["Sample>Component"],
                                "patterns": [{"glob": "project/**"}]
                              }
                            ]
                          }
                          """)
コード例 #19
0
ファイル: validator_test.py プロジェクト: simatei/catapult
 def testInvalidEmptyRegex(self):
     with self.assertRaisesRegexp(validator.InvalidPattern,
                                  'regex must not be empty'):
         _ = validator.Validate("""
                          {
                            "subscriptions": [
                              {
                                "name": "Empty Regex",
                                "notification_email": "bad-pattern@domain",
                                "bug_labels": ["test-blocker"],
                                "bug_components": ["Sample>Component"],
                                "patterns": [{"regex": ""}]
                              }
                            ]
                          }
                          """)
コード例 #20
0
 def testValidAnomalyConfigs(self):
     _ = validator.Validate("""
   subscriptions: [
     {
       name: "Subscription"
       contact_email: "user@domain"
       bug_labels: ["test-blocker"],
       bug_components: ["Sample>Component"],
       rules: {
         match: [{regex: ".*"}]
       }
       anomaly_configs {
         rules {
           match: [{regex: ".*"}]
         }
       }
     }
   ]""")
コード例 #21
0
ファイル: __init__.py プロジェクト: simatei/catapult
 def Validate():  # pylint: disable=unused-variable
     validation_request = request.get_json()
     if validation_request is None:
         return u'Invalid request.', 400
     for member in ('config_set', 'path', 'content'):
         if member not in validation_request:
             return u'Missing \'%s\' member in request.' % (member), 400
     try:
         _ = validator.Validate(validation_request['content'])
     except validator.Error as error:
         return jsonify({
             'messages': [{
                 'path': validation_request['path'],
                 'severity': 'ERROR',
                 'text': '%s' % (error)
             }]
         })
     return jsonify({})
コード例 #22
0
ファイル: validator_test.py プロジェクト: simatei/catapult
 def testGoodCase(self):
     subscriptions = validator.Validate("""{
       "subscriptions": [{
         "name": "Release Team",
         "notification_email": "*****@*****.**",
         "bug_labels": ["release-blocker"],
         "bug_components": ["Sample>Component"],
         "patterns": [{"glob": "project/**"}]
       },
       {
         "name": "Memory Team",
         "notification_email": "*****@*****.**",
         "bug_labels": ["memory-regressions"],
         "patterns": [{"regex": "^project/.*memory_.*$"}],
         "anomaly_configs": [
           {
             "min_relative_change": 0.01,
             "patterns": [{"regex": "^project/platform/.*/memory_peak$"}]
           }
         ]
       }]}""")
     self.assertIsNotNone(subscriptions)
コード例 #23
0
 def testMonorailProjectId(self):
     subscriptions = validator.Validate("""
       subscriptions: [{
         name: "Non-Chromium Team"
         contact_email: "*****@*****.**"
         bug_labels: ["release-blocker"]
         bug_components: ["Sample>Component"]
         monorail_project_id: "not-chromium"
         patterns: [{glob: "project/**"}]
       },
       {
         name: "Memory Team",
         contact_email: "*****@*****.**",
         bug_labels: ["memory-regressions"],
         patterns: [{regex: "^project/.*memory_.*$"}],
         anomaly_configs: [
           {
             min_relative_change: 0.01
             patterns: [{regex: "^project/platform/.*/memory_peak$"}]
           }
         ]
       }]""")
     self.assertIsNotNone(subscriptions)
コード例 #24
0
ファイル: api.py プロジェクト: stingaci/python-midpoint
 def __init__(self, cfg_file='./midpoint.cfg', logFile=None):
     self.logger = Logger()
     self.connection = {}
     self.validate = validator.Validate(self.logger)
     self.read_config(cfg_file)
コード例 #25
0
 def testInvalidJSON(self):
     with self.assertRaisesRegex(validator.InvalidConfig,
                                 'SheriffConfig Validation Error'):
         _ = validator.Validate("""
                          subscriptions: ...
                          """)