11from django .core .exceptions import ValidationError
22from mock import patch , Mock
33
4+ from core .collections .models import Collection , CollectionReference
45from core .common .constants import ACCESS_TYPE_NONE , HEAD
56from core .common .tasks import delete_organization
67from core .common .tests import OCLTestCase
8+ from core .concepts .models import Concept
9+ from core .concepts .tests .factories import ConceptFactory
10+ from core .mappings .models import Mapping
11+ from core .mappings .tests .factories import MappingFactory
712from core .orgs .constants import ORG_OBJECT_TYPE
813from core .orgs .models import Organization
914from core .orgs .tests .factories import OrganizationFactory
15+ from core .sources .models import Source
1016from core .sources .tests .factories import OrganizationSourceFactory
1117from core .collections .tests .factories import OrganizationCollectionFactory
1218from core .users .tests .factories import UserProfileFactory
@@ -124,7 +130,20 @@ def test_org_active_inactive_should_affect_children(self):
124130 self .assertTrue (collection .is_active )
125131
126132 def test_delete_organization_task (self ):
127- org = OrganizationFactory ()
133+ org = OrganizationFactory (mnemonic = 'to-be-deleted-org' )
134+ source = OrganizationSourceFactory (mnemonic = 'to-be-deleted-source' , organization = org )
135+ collection = OrganizationCollectionFactory (mnemonic = 'to-be-deleted-coll' , organization = org )
136+ concept = ConceptFactory (mnemonic = 'to-be-deleted-concept' , parent = source )
137+ mapping = MappingFactory (mnemonic = 'to-be-deleted-mapping' , parent = source )
138+ collection .add_references ([concept .uri , mapping .uri ])
139+
140+ self .assertEqual (org .source_set .count (), 1 )
141+ self .assertEqual (org .collection_set .count (), 1 )
142+ self .assertEqual (source .concepts_set .count (), 2 )
143+ self .assertEqual (source .mappings_set .count (), 2 )
144+ self .assertEqual (collection .references .count (), 2 )
145+ self .assertEqual (collection .concepts .count (), 1 )
146+ self .assertEqual (collection .mappings .count (), 1 )
128147
129148 delete_organization (0 )
130149
@@ -133,6 +152,11 @@ def test_delete_organization_task(self):
133152 delete_organization (org .id )
134153
135154 self .assertFalse (Organization .objects .filter (id = org .id ).exists ())
155+ self .assertFalse (Source .objects .filter (mnemonic = 'to-be-deleted-source' ).exists ())
156+ self .assertFalse (Collection .objects .filter (mnemonic = 'to-be-deleted-coll' ).exists ())
157+ self .assertFalse (Concept .objects .filter (mnemonic = 'to-be-deleted-concept' ).exists ())
158+ self .assertFalse (Mapping .objects .filter (mnemonic = 'to-be-deleted-mapping' ).exists ())
159+ self .assertEqual (CollectionReference .objects .count (), 0 )
136160
137161 def test_logo_url (self ):
138162 self .assertIsNone (Organization (logo_path = None ).logo_url )
0 commit comments