<s> from django . test . client import RequestFactory <EOL> from django . contrib . sites . models import Site <EOL> from mezzanine . utils . sites import current_site_id <EOL> from actstream . models import Action <EOL> from raspberryio . qanda . tests . base import QandaBaseTestCase <EOL> from raspberryio . qanda . models import Question , Answer <EOL> from raspberryio . qanda . forms import QuestionForm , AnswerForm <EOL> class QuestionFormTestCase ( QandaBaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . request_factory = RequestFactory ( ) <EOL> self . question = self . create_question ( ) <EOL> def test_edit_invalid ( self ) : <EOL> request = self . request_factory . post ( '<STR_LIT:/>' , { } ) <EOL> form = QuestionForm ( request . POST , instance = self . question ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT:title>' ] , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( Action . objects . count ( ) , <NUM_LIT:0> , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_create_invalid ( self ) : <EOL> request = self . request_factory . post ( '<STR_LIT:/>' , { } ) <EOL> site = Site . objects . get ( id = current_site_id ) <EOL> question = Question ( user = self . create_user ( ) , site = site ) <EOL> form = QuestionForm ( request . POST , instance = question ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT:title>' ] , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( Action . objects . count ( ) , <NUM_LIT:0> , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_edit_valid ( self ) : <EOL> post_data = { <EOL> '<STR_LIT:title>' : self . get_random_string ( ) , <EOL> '<STR_LIT>' : self . get_random_string ( ) , <EOL> } <EOL> request = self . request_factory . post ( '<STR_LIT:/>' , post_data ) <EOL> form = QuestionForm ( request . POST , instance = self . question ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> self . assertEqual ( Action . objects . count ( ) , <NUM_LIT:0> , <EOL> '<STR_LIT>' <EOL> ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_create_valid ( self ) : <EOL> post_data = { <EOL> '<STR_LIT:title>' : self . get_random_string ( ) , <EOL> '<STR_LIT>' : self . get_random_string ( ) , <EOL> } <EOL> request = self . request_factory . post ( '<STR_LIT:/>' , post_data ) <EOL> site = Site . objects . get ( id = current_site_id ) <EOL> question = Question ( user = self . create_user ( ) , site = site ) <EOL> form = QuestionForm ( request . POST , instance = question ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> self . assertEqual ( Action . objects . count ( ) , <NUM_LIT:1> , <EOL> '<STR_LIT>' <EOL> ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> class AnswerFormTestCase ( QandaBaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . request_factory = RequestFactory ( ) <EOL> self . question = self . create_question ( ) <EOL> self . answer = self . create_answer ( question = self . question ) <EOL> def test_edit_invalid ( self ) : <EOL> request = self . request_factory . post ( '<STR_LIT:/>' , { } ) <EOL> form = AnswerForm ( request . POST , instance = self . answer ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( Action . objects . count ( ) , <NUM_LIT:0> , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_create_invalid ( self ) : <EOL> request = self . request_factory . post ( '<STR_LIT:/>' , { } ) <EOL> answer = Answer ( user = self . create_user ( ) , question = self . question ) <EOL> form = AnswerForm ( request . POST , instance = answer ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( Action . objects . count ( ) , <NUM_LIT:0> , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_edit_valid ( self ) : <EOL> post_data = { <EOL> '<STR_LIT>' : self . get_random_string ( ) , <EOL> } <EOL> request = self . request_factory . post ( '<STR_LIT:/>' , post_data ) <EOL> form = AnswerForm ( request . POST , instance = self . answer ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> self . assertEqual ( Action . objects . count ( ) , <NUM_LIT:0> , <EOL> '<STR_LIT>' <EOL> ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_create_valid ( self ) : <EOL> post_data = { <EOL> '<STR_LIT>' : self . get_random_string ( ) , <EOL> } <EOL> request = self . request_factory . post ( '<STR_LIT:/>' , post_data ) <EOL> answer = Answer ( user = self . create_user ( ) , question = self . question ) <EOL> form = AnswerForm ( request . POST , instance = answer ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> self . assertEqual ( Action . objects . count ( ) , <NUM_LIT:1> , <EOL> '<STR_LIT>' <EOL> ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) </s>
