@@ -875,29 +875,29 @@ def test_post_303(self, s3_exists_mock):
875875 def test_post_202(self, s3_exists_mock, export_collection_mock):
876876 s3_exists_mock.return_value = False
877877 response = self.client.post(
878- '/collections/coll/v1/export/',
878+ '/collections/coll/v1/export/?includeRetired=False ',
879879 HTTP_AUTHORIZATION='Token ' + self.token,
880880 format='json'
881881 )
882882
883883 self.assertEqual(response.status_code, 202)
884884 s3_exists_mock.assert_called_once_with("username/coll_v1.{}.zip".format(self.v1_updated_at))
885- export_collection_mock.delay.assert_called_once_with(self.collection_v1.id)
885+ export_collection_mock.delay.assert_called_once_with(self.collection_v1.id, False )
886886
887887 @patch('core.collections.views.export_collection')
888888 @patch('core.common.services.S3.exists')
889889 def test_post_409(self, s3_exists_mock, export_collection_mock):
890890 s3_exists_mock.return_value = False
891891 export_collection_mock.delay.side_effect = AlreadyQueued('already-queued')
892892 response = self.client.post(
893- '/collections/coll/v1/export/',
893+ '/collections/coll/v1/export/?includeRetired=False ',
894894 HTTP_AUTHORIZATION='Token ' + self.token,
895895 format='json'
896896 )
897897
898898 self.assertEqual(response.status_code, 409)
899899 s3_exists_mock.assert_called_once_with("username/coll_v1.{}.zip".format(self.v1_updated_at))
900- export_collection_mock.delay.assert_called_once_with(self.collection_v1.id)
900+ export_collection_mock.delay.assert_called_once_with(self.collection_v1.id, False )
901901
902902
903903class CollectionVersionListViewTest(OCLAPITestCase):
@@ -1017,6 +1017,62 @@ def test_export_collection(self, s3_mock): # pylint: disable=too-many-locals
10171017 import shutil
10181018 shutil.rmtree(latest_temp_dir)
10191019
1020+ @patch('core.common.utils.S3')
1021+ def test_unretired_export_collection(self, s3_mock): # pylint: disable=too-many-locals
1022+ s3_mock.url_for = Mock(return_value='https://s3-url')
1023+ s3_mock.upload_file = Mock()
1024+ source = OrganizationSourceFactory()
1025+ concept1 = ConceptFactory(parent=source)
1026+ concept2 = ConceptFactory(parent=source)
1027+ mapping = MappingFactory(from_concept=concept2, to_concept=concept1, parent=source)
1028+ collection = OrganizationCollectionFactory()
1029+ collection.add_references([concept1.uri, concept2.uri, mapping.uri])
1030+ collection.refresh_from_db()
1031+
1032+ export_collection(collection.id, include_retired=False) # pylint: disable=no-value-for-parameter
1033+
1034+ latest_temp_dir = get_latest_dir_in_path('/tmp/')
1035+ zipped_file = zipfile.ZipFile(latest_temp_dir + '/export.zip')
1036+ exported_data = json.loads(zipped_file.read('export.json').decode('utf-8'))
1037+
1038+ self.assertEqual(
1039+ exported_data,
1040+ {**CollectionVersionExportSerializer(collection).data, 'concepts': ANY, 'mappings': ANY, 'references': ANY}
1041+ )
1042+
1043+ exported_concepts = exported_data['concepts']
1044+ expected_concepts = ConceptVersionExportSerializer(
1045+ [concept2.get_latest_version(), concept1.get_latest_version()], many=True
1046+ ).data
1047+
1048+ self.assertEqual(len(exported_concepts), 2)
1049+ self.assertIn(expected_concepts[0], exported_concepts)
1050+ self.assertIn(expected_concepts[1], exported_concepts)
1051+
1052+ exported_mappings = exported_data['mappings']
1053+ expected_mappings = MappingDetailSerializer([mapping.get_latest_version()], many=True).data
1054+
1055+ self.assertEqual(len(exported_mappings), 1)
1056+ self.assertEqual(expected_mappings, exported_mappings)
1057+
1058+ exported_references = exported_data['references']
1059+ expected_references = CollectionReferenceSerializer(collection.references.all(), many=True).data
1060+
1061+ self.assertEqual(len(exported_references), 3)
1062+ self.assertIn(exported_references[0], expected_references)
1063+ self.assertIn(exported_references[1], expected_references)
1064+ self.assertIn(exported_references[2], expected_references)
1065+
1066+ s3_upload_key = collection.exclude_retired_export_path
1067+ s3_mock.upload_file.assert_called_once_with(
1068+ key=s3_upload_key, file_path=latest_temp_dir + '/export.zip', binary=True,
1069+ metadata={'ContentType': 'application/zip'}, headers={'content-type': 'application/zip'}
1070+ )
1071+ s3_mock.url_for.assert_called_once_with(s3_upload_key)
1072+
1073+ import shutil
1074+ shutil.rmtree(latest_temp_dir)
1075+
10201076
10211077class CollectionConceptsViewTest(OCLAPITestCase):
10221078 def setUp(self):
0 commit comments