def test_params_no_list(self): event = Event(Trail(), 222).set_timestamp(TIMESTAMP) with self.assertRaises(TypeError): event.add_static_params(333) with self.assertRaises(TypeError): event.add_variable_params("test parameter")
def test_one_variable_param(self): event = Event(Trail(), 222).set_timestamp(TIMESTAMP) event.add_variable_param("test parameter") self.assertEqual(event.serialize(), EVENT_STRING_ONE_VAR)
def test_two_variable_params(self): event = Event(Trail(), 222).set_timestamp(TIMESTAMP) event.add_variable_params(["test parameter", "other test parameter"]) self.assertEqual(event.serialize(), EVENT_STRING_TWO_VAR) # Now just check that __str__ doesn't throw self.assertGreater(len(str(event)), 0)
def test_one_static_param(self): event = Event(Trail(), 222).set_timestamp(TIMESTAMP) event.add_static_param(333) self.assertEqual(event.serialize(), EVENT_STRING_ONE_STATIC)
def test_two_static_params(self): event = Event(Trail(), 222).set_timestamp(TIMESTAMP) event.add_static_params([333, 444]) self.assertEqual(event.serialize(), EVENT_STRING_TWO_STATIC)
def test_empty(self): event = Event(Trail(), 222).set_timestamp(TIMESTAMP) self.assertEqual(event.serialize(), EVENT_STRING_EMPTY)
def test_ordering(self): trail = Trail() event_static_first = Event(trail, 222).set_timestamp(TIMESTAMP) event_static_first.add_static_params([333, 444]) event_static_first.add_variable_params( ["test parameter", "other test parameter"]) event_static_first.set_instance_id(555) event_variable_first = Event(trail, 222).set_timestamp(TIMESTAMP) event_variable_first.add_variable_params( ["test parameter", "other test parameter"]) event_variable_first.set_instance_id(555) event_variable_first.add_static_params([333, 444]).set_timestamp(TIMESTAMP) self.assertEqual(event_static_first.serialize(), event_variable_first.serialize()) self.assertEqual(event_static_first.serialize(), EVENT_STRING_ALL)
def test_compressed_variable_param(self): event = Event(Trail(), 222).set_timestamp(TIMESTAMP) event.add_variable_param("test parameter", compress=COMPRESS_ZLIB) self.assertEqual(event.serialize(), EVENT_STRING_COMPRESSED_VAR)
def test_unknown_compression(self): event = Event(Trail(), 222).set_timestamp(TIMESTAMP) with self.assertRaises(ValueError): event.add_variable_param("test parameter", compress='bogus_compression')
def test_ordering(self): trail = Trail() event_static_first = Event(trail, 222).set_timestamp(TIMESTAMP) event_static_first.add_static_params([333, 444]) event_static_first.add_variable_params(["test parameter", "other test parameter"]) event_static_first.set_instance_id(555) event_variable_first = Event(trail, 222).set_timestamp(TIMESTAMP) event_variable_first.add_variable_params(["test parameter", "other test parameter"]) event_variable_first.set_instance_id(555) event_variable_first.add_static_params([333, 444]).set_timestamp(TIMESTAMP) self.assertEqual(event_static_first.serialize(), event_variable_first.serialize()) self.assertEqual(event_static_first.serialize(), EVENT_STRING_ALL)
def test_interfaces(self): trail = Trail() event_constructor = Event(trail, 222, 555, [333, 444], ["test parameter", "other test parameter" ]).set_timestamp(TIMESTAMP) event_plurals = Event(trail, 222).set_timestamp(TIMESTAMP) event_plurals.set_instance_id(555) event_plurals.add_static_params([333, 444]) event_plurals.add_variable_params( ["test parameter", "other test parameter"]) event_singles = Event(trail, 222).set_timestamp(TIMESTAMP) event_singles.set_instance_id(555) event_singles.add_static_param(333).add_static_param(444) event_singles.add_variable_param("test parameter")\ .add_variable_param("other test parameter") self.assertEqual(event_constructor.serialize(), event_plurals.serialize()) self.assertEqual(event_constructor.serialize(), event_singles.serialize()) self.assertEqual(event_constructor.serialize(), EVENT_STRING_ALL)
def test_interfaces(self): trail = Trail() event_constructor = Event( trail, 222, 555, [333, 444], ["test parameter", "other test parameter"]).set_timestamp(TIMESTAMP) event_plurals = Event(trail, 222).set_timestamp(TIMESTAMP) event_plurals.set_instance_id(555) event_plurals.add_static_params([333, 444]) event_plurals.add_variable_params(["test parameter", "other test parameter"]) event_singles = Event(trail, 222).set_timestamp(TIMESTAMP) event_singles.set_instance_id(555) event_singles.add_static_param(333).add_static_param(444) event_singles.add_variable_param("test parameter")\ .add_variable_param("other test parameter") self.assertEqual(event_constructor.serialize(), event_plurals.serialize()) self.assertEqual(event_constructor.serialize(), event_singles.serialize()) self.assertEqual(event_constructor.serialize(), EVENT_STRING_ALL)