Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_set_attribute(self):
u = TestUser()
self.assertFalse(hasattr(u, 'custom_attribute'))
# Set attribute initially
changed = set_attribute(u, 'custom_attribute', 'value')
self.assertTrue(changed)
self.assertEqual(u.custom_attribute, 'value')
# 'Update' to the same value again
changed_same = set_attribute(u, 'custom_attribute', 'value')
self.assertFalse(changed_same)
self.assertEqual(u.custom_attribute, 'value')
# Update to a different value
changed_different = set_attribute(u, 'custom_attribute', 'new_value')
self.assertTrue(changed_different)
self.assertEqual(u.custom_attribute, 'new_value')
def test_set_attribute(self):
u = TestUser()
self.assertFalse(hasattr(u, 'custom_attribute'))
# Set attribute initially
changed = set_attribute(u, 'custom_attribute', 'value')
self.assertTrue(changed)
self.assertEqual(u.custom_attribute, 'value')
# 'Update' to the same value again
changed_same = set_attribute(u, 'custom_attribute', 'value')
self.assertFalse(changed_same)
self.assertEqual(u.custom_attribute, 'value')
# Update to a different value
changed_different = set_attribute(u, 'custom_attribute', 'new_value')
self.assertTrue(changed_different)
self.assertEqual(u.custom_attribute, 'new_value')
def test_set_attribute(self):
u = TestUser()
self.assertFalse(hasattr(u, 'custom_attribute'))
# Set attribute initially
changed = set_attribute(u, 'custom_attribute', 'value')
self.assertTrue(changed)
self.assertEqual(u.custom_attribute, 'value')
# 'Update' to the same value again
changed_same = set_attribute(u, 'custom_attribute', 'value')
self.assertFalse(changed_same)
self.assertEqual(u.custom_attribute, 'value')
# Update to a different value
changed_different = set_attribute(u, 'custom_attribute', 'new_value')
self.assertTrue(changed_different)
self.assertEqual(u.custom_attribute, 'new_value')