1+ import os
12import unittest
23import uuid
34import warnings
@@ -898,7 +899,7 @@ def test_create_column_fail(self, m):
898899 self .course .create_custom_column (column = {})
899900
900901 # create_discussion_topic()
901- def test_create_discussion_topic (self , m ):
902+ def test_create_discussion_topic_no_file (self , m ):
902903 register_uris ({"course" : ["create_discussion_topic" ]}, m )
903904
904905 title = "Topic 1"
@@ -908,6 +909,40 @@ def test_create_discussion_topic(self, m):
908909 self .assertEqual (title , discussion .title )
909910 self .assertEqual (discussion .course_id , 1 )
910911
912+ def test_create_discussion_topic_file_path (self , m ):
913+ register_uris ({"course" : ["create_discussion_topic" ]}, m )
914+
915+ filepath = os .path .join ("tests" , "fixtures" , "generic_file.txt" )
916+
917+ title = "Topic 1"
918+ discussion = self .course .create_discussion_topic (attachment = filepath )
919+ self .assertIsInstance (discussion , DiscussionTopic )
920+ self .assertTrue (hasattr (discussion , "course_id" ))
921+ self .assertEqual (title , discussion .title )
922+ self .assertEqual (discussion .course_id , 1 )
923+
924+ def test_create_discussion_topic_file_path_invalid (self , m ):
925+ register_uris ({"course" : ["create_discussion_topic" ]}, m )
926+
927+ filepath = "this/path/doesnt/exist"
928+
929+ with self .assertRaises (IOError ):
930+ self .course .create_discussion_topic (attachment = filepath )
931+
932+ def test_create_discussion_topic_file_obj (self , m ):
933+ register_uris ({"course" : ["create_discussion_topic" ]}, m )
934+
935+ filepath = os .path .join ("tests" , "fixtures" , "generic_file.txt" )
936+
937+ title = "Topic 1"
938+ with open (filepath , "rb" ) as f :
939+ discussion = self .course .create_discussion_topic (attachment = f )
940+
941+ self .assertIsInstance (discussion , DiscussionTopic )
942+ self .assertTrue (hasattr (discussion , "course_id" ))
943+ self .assertEqual (title , discussion .title )
944+ self .assertEqual (discussion .course_id , 1 )
945+
911946 # reorder_pinned_topics()
912947 def test_reorder_pinned_topics (self , m ):
913948 # Custom matcher to test that params are set correctly
@@ -1583,8 +1618,6 @@ def test_get_outcome_import_status_latest(self, m):
15831618
15841619 # import_outcome()
15851620 def test_import_outcome_filepath (self , m ):
1586- import os
1587-
15881621 register_uris ({"course" : ["import_outcome" ]}, m )
15891622
15901623 filepath = os .path .join ("tests" , "fixtures" , "test_import_outcome.csv" )
@@ -1598,8 +1631,6 @@ def test_import_outcome_filepath(self, m):
15981631 self .assertEqual (outcome_import .data ["import_type" ], "instructure_csv" )
15991632
16001633 def test_import_outcome_binary (self , m ):
1601- import os
1602-
16031634 register_uris ({"course" : ["import_outcome" ]}, m )
16041635
16051636 filepath = os .path .join ("tests" , "fixtures" , "test_import_outcome.csv" )
0 commit comments