Пример #1
0
    def testExtractStepBadValue(self):
        step_msg = encoding.JsonToMessage(
            base.MESSAGE_MODULE.Step, """{
  "kind": "Kind",
  "name": "Name",
  "properties": {
    "object_value": {
      "@type": "OutputReference",
      "output_name": 1337,
      "step_name": "s1"
    }
  }
}""")
        result = step_json._ExtractStep(step_msg)
        self.assertEqual('Kind', result['kind'])
        self.assertEqual('Name', result['name'])
        self.assertEqual(
            {
                'object_value': {
                    '@type':
                    'OutputReference',
                    'output_name':
                    'No decoding provided '
                    'for: <JsonValue\n integer_value: '
                    '1337>',
                    'step_name':
                    's1'
                }
            }, result['properties'])
Пример #2
0
 def testExtractStepNoProperties(self):
     step_msg = base.MESSAGE_MODULE.Step(
         kind='Kind',
         name='Name',
     )
     result = step_json._ExtractStep(step_msg)
     self.assertEqual('Kind', result['kind'])
     self.assertEqual('Name', result['name'])
     self.assertEqual({}, result['properties'])
Пример #3
0
 def testExtractStepEmptyProperties(self):
     step_msg = base.MESSAGE_MODULE.Step(
         kind='Kind',
         name='Name',
         properties=base.MESSAGE_MODULE.Step.PropertiesValue(
             additionalProperties=[]))
     result = step_json._ExtractStep(step_msg)
     self.assertEqual('Kind', result['kind'])
     self.assertEqual('Name', result['name'])
     self.assertEqual({}, result['properties'])
Пример #4
0
    def testExtractStepStringProperty(self):
        step_msg = encoding.JsonToMessage(
            base.MESSAGE_MODULE.Step, """{
  "kind": "Kind",
  "name": "Name",
  "properties": {
    "string_value": {
      "@type": "http://schema.org/Text",
      "value": "Hello"
    }
  }
}""")
        result = step_json._ExtractStep(step_msg)
        self.assertEqual('Kind', result['kind'])
        self.assertEqual('Name', result['name'])
        self.assertEqual({'string_value': 'Hello'}, result['properties'])
Пример #5
0
    def testExtractStepBooleanProperty(self):
        step_msg = encoding.JsonToMessage(
            base.MESSAGE_MODULE.Step, """{
  "kind": "Kind",
  "name": "Name",
  "properties": {
    "bool_value": {
      "@type": "http://schema.org/Boolean",
      "value": true
    }
  }
}""")
        result = step_json._ExtractStep(step_msg)
        self.assertEqual('Kind', result['kind'])
        self.assertEqual('Name', result['name'])
        self.assertEqual({'bool_value': True}, result['properties'])
Пример #6
0
    def testExtractStepBadDecoratedObject(self):
        step_msg = encoding.JsonToMessage(
            base.MESSAGE_MODULE.Step, """{
  "kind": "Kind",
  "name": "Name",
  "properties": {
    "object_value": {
      "@type": "http://schema.org/Text"
    }
  }
}""")
        result = step_json._ExtractStep(step_msg)
        self.assertEqual('Kind', result['kind'])
        self.assertEqual('Name', result['name'])
        pattern = (
            'Missing value for type \\[http://schema.org/Text] in proto '
            '\\[<JsonValue\n object_value: '
            '<JsonObject\n properties: \\['
            '<Property\n key: u?\'@type\'\n value: '
            '<JsonValue\n string_value: u?\'http://schema.org/Text\'>>]>>]')
        self.assertRegexpMatches(result['properties']['object_value'], pattern)
Пример #7
0
    def testExtractStepStringList(self):
        step_msg = encoding.JsonToMessage(
            base.MESSAGE_MODULE.Step, """{
  "kind": "Kind",
  "name": "Name",
  "properties": {
    "array_value": [
      {
        "@type": "http://schema.org/Text",
        "value": "Hello"
      },
      {
        "@type": "http://schema.org/Text",
        "value": "World"
      }
    ]
  }
}""")
        result = step_json._ExtractStep(step_msg)
        self.assertEqual('Kind', result['kind'])
        self.assertEqual('Name', result['name'])
        self.assertEqual({'array_value': ['Hello', 'World']},
                         result['properties'])
Пример #8
0
    def testExtractStepObject(self):
        step_msg = encoding.JsonToMessage(
            base.MESSAGE_MODULE.Step, """{
  "kind": "Kind",
  "name": "Name",
  "properties": {
    "object_value": {
      "@type": "OutputReference",
      "output_name": "output",
      "step_name": "s1"
    }
  }
}""")
        result = step_json._ExtractStep(step_msg)
        self.assertEqual('Kind', result['kind'])
        self.assertEqual('Name', result['name'])
        self.assertEqual(
            {
                'object_value': {
                    '@type': 'OutputReference',
                    'output_name': 'output',
                    'step_name': 's1'
                }
            }, result['properties'])