Example #1
0
 def test_fingerprint(self):
   payload = Payload()
   payload.add_field('foo', PrimitiveField())
   fingerprint1 = payload.fingerprint()
   self.assertEqual(fingerprint1, payload.fingerprint())
   payload.add_field('bar', PrimitiveField())
   fingerprint2 = payload.fingerprint()
   self.assertNotEqual(fingerprint1, fingerprint2)
   self.assertEqual(fingerprint2, payload.fingerprint())
   payload.freeze()
   self.assertEqual(fingerprint2, payload.fingerprint())
Example #2
0
 def payload_for_scope(self, scope):
   """Returns a payload representing the options for the given scope."""
   payload = Payload()
   for (name, _, kwargs) in self.registration_args_iter_for_scope(scope):
     if not kwargs.get('fingerprint', False):
       continue
     val = self.for_scope(scope)[name]
     val_type = kwargs.get('type', '')
     if val_type == Options.file:
       field = FileField(val)
     elif val_type == Options.target_list:
       field = TargetListField(val)
     else:
       field = PrimitiveField(val)
     payload.add_field(name, field)
   payload.freeze()
   return payload
Example #3
0
 def test_field_duplication(self):
   payload = Payload()
   payload.add_field('foo', PrimitiveField())
   payload.freeze()
   with self.assertRaises(PayloadFieldAlreadyDefinedError):
     payload.add_field('foo', PrimitiveField())
Example #4
0
 def test_freeze(self):
   payload = Payload()
   payload.add_field('foo', PrimitiveField())
   payload.freeze()
   with self.assertRaises(PayloadFrozenError):
     payload.add_field('bar', PrimitiveField())
 def _make_payload_from_sources(self, sources):
   p = Payload()
   p.add_field('sources', SourcesField('', sources))
   p.freeze()
   return p
Example #6
0
 def _make_payload_from_sources(self, sources):
     p = Payload()
     p.add_field('sources', SourcesField('', sources))
     p.freeze()
     return p