def test_serialize(self): ''' simple function for converting dataclass to dict ''' instance = ActivityObject(id='a', type='b') serialized = instance.serialize() self.assertIsInstance(serialized, dict) self.assertEqual(serialized['id'], 'a') self.assertEqual(serialized['type'], 'b')
def test_serialize(self, _): """simple function for converting dataclass to dict""" instance = ActivityObject(id="a", type="b") serialized = instance.serialize() self.assertIsInstance(serialized, dict) self.assertEqual(serialized["id"], "a") self.assertEqual(serialized["type"], "b")
def test_to_model(self): ''' the big boy of this module. it feels janky to test this with actual models rather than a test model, but I don't know how to make a test model so here we are. ''' instance = ActivityObject(id='a', type='b') with self.assertRaises(ActivitySerializerError): instance.to_model(models.User) # test setting simple fields self.assertEqual(self.user.name, '') update_data = activitypub.Person(**self.user.to_activity()) update_data.name = 'New Name' update_data.to_model(models.User, self.user) self.assertEqual(self.user.name, 'New Name')
def test_init_extra_fields(self, _): """init ignoring additional fields""" instance = ActivityObject(id="a", type="b", fish="c") self.assertTrue(hasattr(instance, "id")) self.assertTrue(hasattr(instance, "type"))
def test_init_missing(self, _): """init with missing required params""" with self.assertRaises(ActivitySerializerError): ActivityObject()
def test_init(self, _): """simple successfuly init""" instance = ActivityObject(id="a", type="b") self.assertTrue(hasattr(instance, "id")) self.assertTrue(hasattr(instance, "type"))
def test_to_model_invalid_model(self, _): """catch mismatch between activity type and model type""" instance = ActivityObject(id="a", type="b") with self.assertRaises(ActivitySerializerError): instance.to_model(model=models.User)
def test_to_model_invalid_model(self): ''' catch mismatch between activity type and model type ''' instance = ActivityObject(id='a', type='b') with self.assertRaises(ActivitySerializerError): instance.to_model(models.User)
def test_init_extra_fields(self): ''' init ignoring additional fields ''' instance = ActivityObject(id='a', type='b', fish='c') self.assertTrue(hasattr(instance, 'id')) self.assertTrue(hasattr(instance, 'type'))
def test_init_missing(self): ''' init with missing required params ''' with self.assertRaises(ActivitySerializerError): ActivityObject()
def test_init(self): ''' simple successfuly init ''' instance = ActivityObject(id='a', type='b') self.assertTrue(hasattr(instance, 'id')) self.assertTrue(hasattr(instance, 'type'))