Created
March 5, 2014 04:24
-
-
Save divad12/5fd40c6278548fd43ac5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rmc.models as m | |
import rmc.test.lib as testlib | |
def gen_professor(**kwargs): | |
attrs = dict({ | |
'id': 'meredith_swift', # I'm a cat meow meow!!!! | |
'first_name': 'Meredith', | |
'last_name': 'Swift', | |
}, **kwargs) | |
return m.Professor(**attrs) | |
class ProfessorTest(testlib.ModelTestCase): | |
def test_save_ratings(self): | |
prof_meredith = gen_professor() | |
# Taylor approves of her new roommate, professor Meredith. | |
prof_meredith.passion.update_aggregate_after_replacement(None, 1) | |
prof_meredith.save() | |
# But Meredith exhibits bad posture, so Taylor retracts her old rating. | |
prof_meredith.passion.update_aggregate_after_replacement(1, None) | |
prof_meredith.save() | |
# Now we are internally in an inconsistent state, but the fault has not | |
# propagated to the user as an error yet. | |
# Meredith learns how to moves her ears on command and Taylor is happy. | |
prof_meredith.passion.update_aggregate_after_replacement(None, 1) | |
prof_meredith.save() | |
# But Ed is dejected after Meredith gives him a look of disapproval. | |
prof_meredith.passion.update_aggregate_after_replacement(None, 0) | |
prof_meredith.save() | |
# Meredith meowed on about how Taylor can't sing, which Taylor thought | |
# was mean, so she changed her old approval to a disapproval. | |
prof_meredith.passion.update_aggregate_after_replacement(1, 0) | |
# Now the fault gets manifested into an exception. | |
prof_meredith.save() | |
# At this point we get: | |
# ValidationError: ValidationError(rating.Float value is too small: ['passion']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running this will produce the following output: