<s> from django . test import TestCase <EOL> from django . core . exceptions import ValidationError <EOL> from oscar . core . compat import get_user_model <EOL> from oscar . apps . catalogue . reviews import models <EOL> from oscar . test . factories import create_product <EOL> from oscar . test . factories import UserFactory <EOL> User = get_user_model ( ) <EOL> class TestAnAnonymousReview ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . product = create_product ( ) <EOL> self . data = { <EOL> '<STR_LIT>' : self . product , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' <EOL> } <EOL> def review ( self , ** kwargs ) : <EOL> if kwargs : <EOL> data = self . data . copy ( ) <EOL> data . update ( kwargs ) <EOL> else : <EOL> data = self . data <EOL> return models . ProductReview ( ** data ) <EOL> def test_can_be_created ( self ) : <EOL> review = self . review ( ) <EOL> review . full_clean ( ) <EOL> def test_requires_a_title ( self ) : <EOL> review = self . review ( title = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , review . full_clean ) <EOL> def test_requires_a_body ( self ) : <EOL> review = self . review ( body = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , review . full_clean ) <EOL> def test_requires_a_name ( self ) : <EOL> review = self . review ( name = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , review . full_clean ) <EOL> def test_requires_an_email_address ( self ) : <EOL> review = self . review ( email = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , review . full_clean ) <EOL> def test_requires_non_whitespace_title ( self ) : <EOL> review = self . review ( title = "<STR_LIT:U+0020>" ) <EOL> self . assertRaises ( ValidationError , review . full_clean ) <EOL> def test_starts_with_no_votes ( self ) : <EOL> review = self . review ( ) <EOL> review . save ( ) <EOL> self . assertFalse ( review . has_votes ) <EOL> self . assertEqual ( <NUM_LIT:0> , review . num_up_votes ) <EOL> self . assertEqual ( <NUM_LIT:0> , review . num_down_votes ) <EOL> def test_has_reviewer_name_property ( self ) : <EOL> review = self . review ( name = "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" , review . reviewer_name ) <EOL> class TestAUserReview ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . product = create_product ( ) <EOL> self . user = UserFactory ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" ) <EOL> self . data = { <EOL> '<STR_LIT>' : self . product , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT:user>' : self . user <EOL> } <EOL> def review ( self , ** kwargs ) : <EOL> if kwargs : <EOL> data = self . data . copy ( ) <EOL> data . update ( kwargs ) <EOL> else : <EOL> data = self . data <EOL> return models . ProductReview ( ** data ) <EOL> def test_can_be_created ( self ) : <EOL> review = self . review ( ) <EOL> review . full_clean ( ) <EOL> def test_requires_a_title ( self ) : <EOL> review = self . review ( title = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , review . full_clean ) <EOL> def test_requires_a_body ( self ) : <EOL> review = self . review ( body = "<STR_LIT>" ) <EOL> self . assertRaises ( ValidationError , review . full_clean ) <EOL> def test_has_reviewer_name_property ( self ) : <EOL> review = self . review ( ) <EOL> self . assertEqual ( "<STR_LIT>" , review . reviewer_name ) <EOL> class TestVotingOnAReview ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . product = create_product ( ) <EOL> self . user = UserFactory ( ) <EOL> self . voter = UserFactory ( ) <EOL> self . review = self . product . reviews . create ( <EOL> title = '<STR_LIT>' , <EOL> score = <NUM_LIT:3> , <EOL> body = "<STR_LIT>" , <EOL> user = self . user ) <EOL> def test_updates_totals_for_upvote ( self ) : <EOL> self . review . vote_up ( self . voter ) <EOL> self . assertTrue ( self . review . has_votes ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . review . total_votes ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . review . delta_votes ) <EOL> def test_updates_totals_for_downvote ( self ) : <EOL> self . review . vote_down ( self . voter ) <EOL> self . assertTrue ( self . review . has_votes ) <EOL> self . assertEqual ( <NUM_LIT:1> , self . review . total_votes ) <EOL> self . assertEqual ( - <NUM_LIT:1> , self . review . delta_votes ) <EOL> def test_is_permitted_for_normal_user ( self ) : <EOL> is_allowed , reason = self . review . can_user_vote ( self . voter ) <EOL> self . assertTrue ( is_allowed , reason ) <EOL> def test_is_not_permitted_for_reviewer ( self ) : <EOL> is_allowed , reason = self . review . can_user_vote ( self . user ) <EOL> self . assertFalse ( is_allowed , reason ) <EOL> def test_is_not_permitted_for_previous_voter ( self ) : <EOL> self . review . vote_up ( self . voter ) <EOL> is_allowed , reason = self . review . can_user_vote ( self . voter ) <EOL> self . assertFalse ( is_allowed , reason ) </s>
