示例#1
0
 def test_edit_rate_class_add_material(self):
     rate_class = RateClassFactory()
     material = MaterialFactory(rate_class=None)
     # Add the material to the rate class through the form
     self.run_form(rate_class, [material])
     # Verify that the material is now associated to the rate class
     material.refresh_from_db()
     self.assertEqual(material.rate_class, rate_class)
示例#2
0
 def test_edit_rate_class_reassign_material(self):
     # Create a rate class and material
     rate_class = RateClassFactory()
     material = MaterialFactory()
     old_rate_class = material.rate_class
     # Add the material to the rate class through the form
     self.run_form(rate_class, [material])
     material.refresh_from_db()
     # Verify that the rate class for the material was updated
     self.assertEqual(material.rate_class, rate_class)
     # Verify that the reverse relation holds as well
     self.assertTrue(material in rate_class.materials.all())
     # Verify that the material is no longer associated to the old rate class
     old_rate_class.refresh_from_db()
     self.assertFalse(material in old_rate_class.materials.all())