@@ -857,29 +857,29 @@ def test_post_303(self, s3_exists_mock):
857857 def test_post_202 (self , s3_exists_mock , export_collection_mock ):
858858 s3_exists_mock .return_value = False
859859 response = self .client .post (
860- self .collection_v1 .uri + 'export/' ,
860+ self .collection_v1 .uri + 'export/?includeRetired=False ' ,
861861 HTTP_AUTHORIZATION = 'Token ' + self .token ,
862862 format = 'json'
863863 )
864864
865865 self .assertEqual (response .status_code , 202 )
866866 s3_exists_mock .assert_called_once_with (f"username/coll_v1.{ self .v1_updated_at } .zip" )
867- export_collection_mock .delay .assert_called_once_with (self .collection_v1 .id )
867+ export_collection_mock .delay .assert_called_once_with (self .collection_v1 .id , False )
868868
869869 @patch ('core.collections.views.export_collection' )
870870 @patch ('core.common.services.S3.exists' )
871871 def test_post_409 (self , s3_exists_mock , export_collection_mock ):
872872 s3_exists_mock .return_value = False
873873 export_collection_mock .delay .side_effect = AlreadyQueued ('already-queued' )
874874 response = self .client .post (
875- self .collection_v1 .uri + 'export/' ,
875+ self .collection_v1 .uri + 'export/?includeRetired=False ' ,
876876 HTTP_AUTHORIZATION = 'Token ' + self .token ,
877877 format = 'json'
878878 )
879879
880880 self .assertEqual (response .status_code , 409 )
881881 s3_exists_mock .assert_called_once_with (f"username/coll_v1.{ self .v1_updated_at } .zip" )
882- export_collection_mock .delay .assert_called_once_with (self .collection_v1 .id )
882+ export_collection_mock .delay .assert_called_once_with (self .collection_v1 .id , False )
883883
884884
885885class CollectionVersionListViewTest (OCLAPITestCase ):
@@ -999,6 +999,62 @@ def test_export_collection(self, s3_mock): # pylint: disable=too-many-locals
999999 import shutil
10001000 shutil .rmtree (latest_temp_dir )
10011001
1002+ @patch ('core.common.utils.S3' )
1003+ def test_unretired_export_collection (self , s3_mock ): # pylint: disable=too-many-locals
1004+ s3_mock .url_for = Mock (return_value = 'https://s3-url' )
1005+ s3_mock .upload_file = Mock ()
1006+ source = OrganizationSourceFactory ()
1007+ concept1 = ConceptFactory (parent = source )
1008+ concept2 = ConceptFactory (parent = source )
1009+ mapping = MappingFactory (from_concept = concept2 , to_concept = concept1 , parent = source )
1010+ collection = OrganizationCollectionFactory ()
1011+ collection .add_references ([concept1 .uri , concept2 .uri , mapping .uri ])
1012+ collection .refresh_from_db ()
1013+
1014+ export_collection (collection .id , include_retired = False ) # pylint: disable=no-value-for-parameter
1015+
1016+ latest_temp_dir = get_latest_dir_in_path ('/tmp/' )
1017+ zipped_file = zipfile .ZipFile (latest_temp_dir + '/export.zip' )
1018+ exported_data = json .loads (zipped_file .read ('export.json' ).decode ('utf-8' ))
1019+
1020+ self .assertEqual (
1021+ exported_data ,
1022+ {** CollectionVersionExportSerializer (collection ).data , 'concepts' : ANY , 'mappings' : ANY , 'references' : ANY }
1023+ )
1024+
1025+ exported_concepts = exported_data ['concepts' ]
1026+ expected_concepts = ConceptVersionExportSerializer (
1027+ [concept2 .get_latest_version (), concept1 .get_latest_version ()], many = True
1028+ ).data
1029+
1030+ self .assertEqual (len (exported_concepts ), 2 )
1031+ self .assertIn (expected_concepts [0 ], exported_concepts )
1032+ self .assertIn (expected_concepts [1 ], exported_concepts )
1033+
1034+ exported_mappings = exported_data ['mappings' ]
1035+ expected_mappings = MappingDetailSerializer ([mapping .get_latest_version ()], many = True ).data
1036+
1037+ self .assertEqual (len (exported_mappings ), 1 )
1038+ self .assertEqual (expected_mappings , exported_mappings )
1039+
1040+ exported_references = exported_data ['references' ]
1041+ expected_references = CollectionReferenceSerializer (collection .references .all (), many = True ).data
1042+
1043+ self .assertEqual (len (exported_references ), 3 )
1044+ self .assertIn (exported_references [0 ], expected_references )
1045+ self .assertIn (exported_references [1 ], expected_references )
1046+ self .assertIn (exported_references [2 ], expected_references )
1047+
1048+ s3_upload_key = collection .exclude_retired_export_path
1049+ s3_mock .upload_file .assert_called_once_with (
1050+ key = s3_upload_key , file_path = latest_temp_dir + '/export.zip' , binary = True ,
1051+ metadata = {'ContentType' : 'application/zip' }, headers = {'content-type' : 'application/zip' }
1052+ )
1053+ s3_mock .url_for .assert_called_once_with (s3_upload_key )
1054+
1055+ import shutil
1056+ shutil .rmtree (latest_temp_dir )
1057+
10021058
10031059class CollectionConceptsViewTest (OCLAPITestCase ):
10041060 def setUp (self ):
0 commit comments