99
1010class TopicAdminTestCase (WebTest ):
1111 fixtures = ['projects.json' ]
12+ def create_test_topic (self , name = u'Emma Goldman' ):
13+ project = main_models .Project .objects .get (slug = 'emma' );
14+ node , topic = main_models .Topic .objects .create_along_with_node (
15+ name , project , project .members .get ())
16+ return topic
1217 def test_create_topic (self ):
1318 "A user should be able to create a topic with a unique name."
1419 topic_name = u'Emma Goldman'
@@ -33,6 +38,63 @@ def test_create_topic(self):
3338 self .assertEqual (error_messages [0 ].text .strip (),
3439 u'Topic with this preferred name already exists.' )
3540
41+ def test_add_citation (self ):
42+ topic = self .create_test_topic ()
43+ document = main_models .Document .objects .create (
44+ description = "a test document" ,
45+ project_id = topic .project_id ,
46+ creator_id = topic .creator_id ,
47+ last_updater_id = topic .last_updater_id )
48+ url = reverse ('admin:main_topic_change' ,
49+ kwargs = {'project_slug' : 'emma' , 'topic_node_id' : topic .topic_node_id })
50+
51+ form = self .app .get (url , user = 'barry' ).forms [1 ]
52+ form ['citation-0-document' ] = document .id
53+ form ['citation-0-notes' ] = 'it was an interesting thing I found in here'
54+
55+ resp = form .submit ().follow ()
56+ topic = main_models .Topic .objects .get (id = topic .id )
57+ self .assertEqual (topic .summary_cites .count (), 1 )
58+ self .assertEqual (topic .summary_cites .get ().document_id , document .id )
59+ self .assertEqual (topic .summary_cites .get ().object_id , topic .id )
60+
61+ def test_add_related_topics (self ):
62+ topic = self .create_test_topic ()
63+
64+ # This is to make sure topic id counter and topic node id counter are
65+ # off. hope you can handle that
66+ main_models .TopicNode .objects .create (_preferred_name = 'dummy' ,
67+ creator_id = 1 , last_updater_id = 1 )
68+
69+ topic_2 = self .create_test_topic (name = u'Alexander Berkman' )
70+ topic_3 = self .create_test_topic (name = u'Ben Reitman' )
71+
72+ url = reverse ('admin:main_topic_change' ,
73+ kwargs = {'project_slug' : 'emma' , 'topic_node_id' : topic .topic_node_id })
74+
75+ # Add one topic
76+ form = self .app .get (url , user = 'barry' ).forms [1 ]
77+ form ['topicassignment-0-topic_id' ] = topic_2 .topic_node_id
78+ resp = form .submit ().follow ()
79+ self .assertEqual (topic .related_topics .count (), 1 )
80+ self .assertEqual (topic .related_topics .get ().topic_id , topic_2 .id )
81+
82+ # Add another topic
83+ form = self .app .get (url , user = 'barry' ).forms [1 ]
84+ form ['topicassignment-1-topic_id' ] = topic_3 .topic_node_id
85+ resp = form .submit ().follow ()
86+ self .assertEqual (topic .related_topics .count (), 2 )
87+ self .assertEqual (sorted ([topic_2 .id , topic_3 .id ]),
88+ sorted (topic .related_topics .values_list ('topic_id' , flat = True )))
89+
90+ # Delete both topics
91+ form = self .app .get (url , user = 'barry' ).forms [1 ]
92+ form ['topicassignment-0-DELETE' ] = 'true'
93+ form ['topicassignment-1-DELETE' ] = 'true'
94+ resp = form .submit ().follow ()
95+ self .assertEqual (topic .related_topics .count (), 0 )
96+
97+
3698 def test_create_empty_topic_error (self ):
3799 "A user should not be able to create a topic with an empty name."
38100 add_url = reverse ('admin:main_topic_add' , kwargs = {'project_slug' : 'emma' })
0 commit comments