class TestDeleteDomain(TestCase): def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = Location( domain=domain_name, site_code='testcode', name='test1', location_type='facility' ) location.save() self.locations[domain_name] = location.sql_location user = CommCareUser.create( domain=domain_name, username='******'.format(domain_name), password='******' ) FacilityInCharge.objects.create( user_id=user.get_id, location=location.sql_location ) def setUp(self): self.domain = Domain(name="test", is_active=True) self.domain.save() self.domain2 = Domain(name="test2", is_active=True) self.domain2.save() self.locations = {} LocationType.objects.create( domain='test', name='facility', ) LocationType.objects.create( domain='test2', name='facility', ) self._create_data('test') self._create_data('test2') def test_pre_delete_signal_receiver(self): self.domain.delete() self.assertEqual(FacilityInCharge.objects.filter(location=self.locations['test']).count(), 0) self.assertEqual(FacilityInCharge.objects.filter(location=self.locations['test2']).count(), 1) def tearDown(self): self.domain2.delete()
class TestSubscription(BaseAccountingTest): def setUp(self): super(TestSubscription, self).setUp() self.billing_contact = generator.arbitrary_web_user() self.dimagi_user = generator.arbitrary_web_user(is_dimagi=True) self.domain = Domain(name='test') self.domain.save() self.currency = generator.init_default_currency() self.account = generator.billing_account(self.dimagi_user, self.billing_contact) self.subscription, self.subscription_length = generator.generate_domain_subscription_from_date( datetime.date.today(), self.account, self.domain.name ) def test_creation(self): self.assertIsNotNone(self.subscription) def test_no_activation(self): tasks.activate_subscriptions(based_on_date=self.subscription.date_start - datetime.timedelta(30)) subscription = Subscription.objects.get(id=self.subscription.id) self.assertFalse(subscription.is_active) def test_activation(self): tasks.activate_subscriptions(based_on_date=self.subscription.date_start) subscription = Subscription.objects.get(id=self.subscription.id) self.assertTrue(subscription.is_active) def test_no_deactivation(self): tasks.activate_subscriptions(based_on_date=self.subscription.date_start) tasks.deactivate_subscriptions(based_on_date=self.subscription.date_end - datetime.timedelta(30)) subscription = Subscription.objects.get(id=self.subscription.id) self.assertTrue(subscription.is_active) def test_deactivation(self): tasks.deactivate_subscriptions(based_on_date=self.subscription.date_end) subscription = Subscription.objects.get(id=self.subscription.id) self.assertFalse(subscription.is_active) def test_deletions(self): self.assertRaises(models.ProtectedError, self.account.delete) self.assertRaises(models.ProtectedError, self.subscription.plan_version.delete) self.assertRaises(models.ProtectedError, self.subscription.subscriber.delete) def tearDown(self): self.billing_contact.delete() self.dimagi_user.delete() self.domain.delete() generator.delete_all_subscriptions() generator.delete_all_accounts() super(TestSubscription, self).tearDown()
class TestDeleteDomain(TestCase): def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = Location(domain=domain_name, site_code='testcode', name='test1', location_type='facility') location.save() self.locations[domain_name] = location.sql_location user = CommCareUser.create(domain=domain_name, username='******'.format(domain_name), password='******') FacilityInCharge.objects.create(user_id=user.get_id, location=location.sql_location) def setUp(self): self.domain = Domain(name="test", is_active=True) self.domain.save() self.domain2 = Domain(name="test2", is_active=True) self.domain2.save() self.locations = {} LocationType.objects.create( domain='test', name='facility', ) LocationType.objects.create( domain='test2', name='facility', ) self._create_data('test') self._create_data('test2') def test_pre_delete_signal_receiver(self): self.domain.delete() self.assertEqual( FacilityInCharge.objects.filter( location=self.locations['test']).count(), 0) self.assertEqual( FacilityInCharge.objects.filter( location=self.locations['test2']).count(), 1) def tearDown(self): self.domain2.delete()
class TestDeleteDomain(TestCase): def setUp(self): self.domain = Domain(name="test", is_active=True) self.domain.save() self.domain2 = Domain(name="test2", is_active=True) self.domain2.save() StockDataCheckpoint.objects.create( domain='test', api='test', limit=100, offset=0 ) StockDataCheckpoint.objects.create( domain='test2', api='test', limit=100, offset=0 ) MigrationCheckpoint.objects.create( domain='test', api='test', limit=100, offset=0 ) MigrationCheckpoint.objects.create( domain='test2', api='test', limit=100, offset=0 ) def test_pre_delete_signal_receiver(self): self.domain.delete() self.assertEqual(MigrationCheckpoint.objects.filter(domain='test').count(), 0) self.assertEqual(StockDataCheckpoint.objects.filter(domain='test').count(), 0) self.assertEqual(MigrationCheckpoint.objects.filter(domain='test2').count(), 1) self.assertEqual(StockDataCheckpoint.objects.filter(domain='test2').count(), 1) def tearDown(self): self.domain2.delete()
class TestDeleteDomain(TestCase): def _create_data(self, domain_name, i): product = Product(domain=domain_name, name='test-{}'.format(i)) product.save() location = Location( domain=domain_name, site_code='testcode-{}'.format(i), name='test-{}'.format(i), location_type='facility' ) location.save() SupplyPointCase.create_from_location(domain_name, location) report = StockReport.objects.create( type='balance', domain=domain_name, form_id='fake', date=datetime.utcnow() ) StockTransaction.objects.create( report=report, product_id=product.get_id, sql_product=SQLProduct.objects.get(product_id=product.get_id), section_id='stock', type='stockonhand', case_id=location.linked_supply_point().get_id, stock_on_hand=100 ) def setUp(self): self.domain = Domain(name="test", is_active=True) self.domain.save() self.domain2 = Domain(name="test2", is_active=True) self.domain2.save() LocationType.objects.create( domain='test', name='facility', ) LocationType.objects.create( domain='test2', name='facility', ) LocationType.objects.create( domain='test', name='facility2', ) LocationType.objects.create( domain='test2', name='facility2', ) for i in xrange(2): self._create_data('test', i) self._create_data('test2', i) def _assert_sql_counts(self, domain, number): self.assertEqual(StockTransaction.objects.filter(report__domain=domain).count(), number) self.assertEqual(StockReport.objects.filter(domain=domain).count(), number) self.assertEqual(SQLLocation.objects.filter(domain=domain).count(), number) self.assertEqual(SQLProduct.objects.filter(domain=domain).count(), number) self.assertEqual(DocDomainMapping.objects.filter(domain_name=domain).count(), number) self.assertEqual(LocationType.objects.filter(domain=domain).count(), number) def test_sql_objects_deletion(self): self._assert_sql_counts('test', 2) self.domain.delete() self._assert_sql_counts('test', 0) self._assert_sql_counts('test2', 2) def tearDown(self): self.domain2.delete()
class TestUserRoleSubscriptionChanges(BaseAccountingTest): min_subscription_length = 3 def setUp(self): super(TestUserRoleSubscriptionChanges, self).setUp() self.domain = Domain( name="test-sub-changes", is_active=True, ) self.domain.save() UserRole.init_domain_with_presets(self.domain.name) self.user_roles = UserRole.by_domain(self.domain.name) self.custom_role = UserRole.get_or_create_with_permissions( self.domain.name, Permissions(edit_apps=True, edit_web_users=True), "Custom Role" ) self.custom_role.save() self.read_only_role = UserRole.get_read_only_role_by_domain(self.domain.name) self.admin_user = generator.arbitrary_web_user() self.admin_user.add_domain_membership(self.domain.name, is_admin=True) self.admin_user.save() self.web_users = [] self.commcare_users = [] for role in [self.custom_role] + self.user_roles: web_user = generator.arbitrary_web_user() web_user.add_domain_membership(self.domain.name, role_id=role.get_id) web_user.save() self.web_users.append(web_user) commcare_user = generator.arbitrary_commcare_user( domain=self.domain.name) commcare_user.set_role(self.domain.name, role.get_qualified_id()) commcare_user.save() self.commcare_users.append(commcare_user) self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name,created_by=self.admin_user.username)[0] self.advanced_plan = DefaultProductPlan.get_default_plan_by_domain( self.domain.name,edition=SoftwarePlanEdition.ADVANCED) def test_cancellation(self): subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.advanced_plan, web_user=self.admin_user.username ) self._change_std_roles() subscription.cancel_subscription(web_user=self.admin_user.username) custom_role = UserRole.get(self.custom_role.get_id) self.assertTrue(custom_role.is_archived) # disable this part of the test until we improve the UX for notifying # downgraded users of their privilege changes # custom_web_user = WebUser.get(self.web_users[0].get_id) # custom_commcare_user = CommCareUser.get(self.commcare_users[0].get_id) # self.assertEqual( # custom_web_user.get_domain_membership(self.domain.name).role_id, # self.read_only_role.get_id # ) # self.assertIsNone( # custom_commcare_user.get_domain_membership(self.domain.name).role_id # ) self._assertInitialRoles() self._assertStdUsers() def test_resubscription(self): subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.advanced_plan, web_user=self.admin_user.username ) self._change_std_roles() subscription.cancel_subscription(web_user=self.admin_user.username) custom_role = UserRole.get(self.custom_role.get_id) self.assertTrue(custom_role.is_archived) subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.advanced_plan, web_user=self.admin_user.username ) custom_role = UserRole.get(self.custom_role.get_id) self.assertFalse(custom_role.is_archived) # disable this part of the test until we improve the UX for notifying # downgraded users of their privilege changes # custom_web_user = WebUser.get(self.web_users[0].get_id) # custom_commcare_user = CommCareUser.get(self.commcare_users[0].get_id) # self.assertEqual( # custom_web_user.get_domain_membership(self.domain.name).role_id, # self.read_only_role.get_id # ) # self.assertIsNone( # custom_commcare_user.get_domain_membership(self.domain.name).role_id # ) self._assertInitialRoles() self._assertStdUsers() subscription.cancel_subscription(web_user=self.admin_user.username) def _change_std_roles(self): for u in self.user_roles: user_role = UserRole.get(u.get_id) user_role.permissions = Permissions( view_reports=True, edit_commcare_users=True, edit_apps=True, edit_data=True ) user_role.save() def _assertInitialRoles(self): for u in self.user_roles: user_role = UserRole.get(u.get_id) self.assertEqual( user_role.permissions, UserRolePresets.get_permissions(user_role.name) ) def _assertStdUsers(self): for ind, wu in enumerate(self.web_users[1:]): web_user = WebUser.get(wu.get_id) self.assertEqual( web_user.get_domain_membership(self.domain.name).role_id, self.user_roles[ind].get_id ) for ind, cc in enumerate(self.commcare_users[1:]): commcare_user = CommCareUser.get(cc.get_id) self.assertEqual( commcare_user.get_domain_membership(self.domain.name).role_id, self.user_roles[ind].get_id ) def tearDown(self): self.domain.delete() self.admin_user.delete() generator.delete_all_subscriptions() generator.delete_all_accounts()
class TestDeleteDomain(TestCase): def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = Location( domain=domain_name, site_code='testcode', name='test1', location_type='facility' ) location.save() self.locations[domain_name] = location.get_id DeliveryGroupReport.objects.create( location_id=location.get_id, quantity=1, message='test', delivery_group='A' ) SupplyPointWarehouseRecord.objects.create( supply_point=location.get_id, create_date=datetime.utcnow() ) Alert.objects.create( text='test', expires=datetime.utcnow(), date=datetime.utcnow(), location_id=location.get_id ) organization_summary = OrganizationSummary.objects.create( date=datetime.utcnow(), location_id=location.get_id ) GroupSummary.objects.create( org_summary=organization_summary ) ProductAvailabilityData.objects.create( product=product.get_id, date=datetime.utcnow(), location_id=location.get_id ) SupplyPointStatus.objects.create( location_id=location.get_id, status_type='del_fac', status_value='received' ) HistoricalLocationGroup.objects.create( location_id=location.sql_location, group='A', date=datetime.utcnow().date() ) ReportRun.objects.create( domain=domain_name, start=datetime.utcnow(), end=datetime.utcnow(), start_run=datetime.utcnow() ) ILSNotes.objects.create( location=location.sql_location, domain=domain_name, user_name='test', date=datetime.utcnow(), text='test' ) SupervisionDocument.objects.create( domain=domain_name, document='test', data_type='test', name='test' ) def setUp(self): self.domain = Domain(name="test", is_active=True) self.domain.save() self.domain2 = Domain(name="test2", is_active=True) self.domain2.save() self.locations = {} LocationType.objects.create( domain='test', name='facility', ) LocationType.objects.create( domain='test2', name='facility', ) self._create_data('test') self._create_data('test2') def test_pre_delete_signal_receiver(self): self.domain.delete() self.assertEqual(ProductAvailabilityData.objects.filter(location_id=self.locations['test']).count(), 0) self.assertEqual(ProductAvailabilityData.objects.filter(location_id=self.locations['test2']).count(), 1) self.assertEqual(OrganizationSummary.objects.filter(location_id=self.locations['test']).count(), 0) self.assertEqual(OrganizationSummary.objects.filter(location_id=self.locations['test2']).count(), 1) self.assertEqual(GroupSummary.objects.filter(org_summary__location_id=self.locations['test']).count(), 0) self.assertEqual(GroupSummary.objects.filter(org_summary__location_id=self.locations['test2']).count(), 1) self.assertEqual(Alert.objects.filter(location_id=self.locations['test']).count(), 0) self.assertEqual(Alert.objects.filter(location_id=self.locations['test2']).count(), 1) self.assertEqual(DeliveryGroupReport.objects.filter(location_id=self.locations['test']).count(), 0) self.assertEqual(DeliveryGroupReport.objects.filter(location_id=self.locations['test2']).count(), 1) self.assertEqual(SupplyPointWarehouseRecord.objects.filter(supply_point=self.locations['test']).count(), 0) self.assertEqual(SupplyPointWarehouseRecord.objects.filter( supply_point=self.locations['test2'] ).count(), 1) self.assertEqual(SupplyPointStatus.objects.filter(location_id=self.locations['test']).count(), 0) self.assertEqual(SupplyPointStatus.objects.filter(location_id=self.locations['test2']).count(), 1) self.assertEqual(HistoricalLocationGroup.objects.filter( location_id__location_id=self.locations['test'] ).count(), 0) self.assertEqual(HistoricalLocationGroup.objects.filter( location_id__location_id=self.locations['test2'] ).count(), 1) self.assertEqual(ReportRun.objects.filter(domain='test').count(), 0) self.assertEqual(ReportRun.objects.filter(domain='test2').count(), 1) self.assertEqual(ILSNotes.objects.filter(domain='test').count(), 0) self.assertEqual(ILSNotes.objects.filter(domain='test2').count(), 1) self.assertEqual(SupervisionDocument.objects.filter(domain='test').count(), 0) self.assertEqual(SupervisionDocument.objects.filter(domain='test2').count(), 1) def tearDown(self): self.domain2.delete()
class TestUserRoleSubscriptionChanges(BaseAccountingTest): min_subscription_length = 3 def setUp(self): super(TestUserRoleSubscriptionChanges, self).setUp() self.domain = Domain( name="test-sub-changes", is_active=True, ) self.domain.save() UserRole.init_domain_with_presets(self.domain.name) self.user_roles = UserRole.by_domain(self.domain.name) self.custom_role = UserRole.get_or_create_with_permissions( self.domain.name, Permissions(edit_apps=True, edit_web_users=True), "Custom Role") self.custom_role.save() self.read_only_role = UserRole.get_read_only_role_by_domain( self.domain.name) self.admin_user = generator.arbitrary_web_user() self.admin_user.add_domain_membership(self.domain.name, is_admin=True) self.admin_user.save() self.web_users = [] self.commcare_users = [] for role in [self.custom_role] + self.user_roles: web_user = generator.arbitrary_web_user() web_user.add_domain_membership(self.domain.name, role_id=role.get_id) web_user.save() self.web_users.append(web_user) commcare_user = generator.arbitrary_commcare_user( domain=self.domain.name) commcare_user.set_role(self.domain.name, role.get_qualified_id()) commcare_user.save() self.commcare_users.append(commcare_user) self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.admin_user.username)[0] self.advanced_plan = DefaultProductPlan.get_default_plan_by_domain( self.domain.name, edition=SoftwarePlanEdition.ADVANCED) def test_cancellation(self): subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.advanced_plan, web_user=self.admin_user.username) self._change_std_roles() subscription.cancel_subscription(web_user=self.admin_user.username) custom_role = UserRole.get(self.custom_role.get_id) self.assertTrue(custom_role.is_archived) # disable this part of the test until we improve the UX for notifying # downgraded users of their privilege changes # custom_web_user = WebUser.get(self.web_users[0].get_id) # custom_commcare_user = CommCareUser.get(self.commcare_users[0].get_id) # self.assertEqual( # custom_web_user.get_domain_membership(self.domain.name).role_id, # self.read_only_role.get_id # ) # self.assertIsNone( # custom_commcare_user.get_domain_membership(self.domain.name).role_id # ) self._assertInitialRoles() self._assertStdUsers() def test_resubscription(self): subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.advanced_plan, web_user=self.admin_user.username) self._change_std_roles() subscription.cancel_subscription(web_user=self.admin_user.username) custom_role = UserRole.get(self.custom_role.get_id) self.assertTrue(custom_role.is_archived) subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.advanced_plan, web_user=self.admin_user.username) custom_role = UserRole.get(self.custom_role.get_id) self.assertFalse(custom_role.is_archived) # disable this part of the test until we improve the UX for notifying # downgraded users of their privilege changes # custom_web_user = WebUser.get(self.web_users[0].get_id) # custom_commcare_user = CommCareUser.get(self.commcare_users[0].get_id) # self.assertEqual( # custom_web_user.get_domain_membership(self.domain.name).role_id, # self.read_only_role.get_id # ) # self.assertIsNone( # custom_commcare_user.get_domain_membership(self.domain.name).role_id # ) self._assertInitialRoles() self._assertStdUsers() subscription.cancel_subscription(web_user=self.admin_user.username) def _change_std_roles(self): for u in self.user_roles: user_role = UserRole.get(u.get_id) user_role.permissions = Permissions(view_reports=True, edit_commcare_users=True, edit_apps=True, edit_data=True) user_role.save() def _assertInitialRoles(self): for u in self.user_roles: user_role = UserRole.get(u.get_id) self.assertEqual(user_role.permissions, UserRolePresets.get_permissions(user_role.name)) def _assertStdUsers(self): for ind, wu in enumerate(self.web_users[1:]): web_user = WebUser.get(wu.get_id) self.assertEqual( web_user.get_domain_membership(self.domain.name).role_id, self.user_roles[ind].get_id) for ind, cc in enumerate(self.commcare_users[1:]): commcare_user = CommCareUser.get(cc.get_id) self.assertEqual( commcare_user.get_domain_membership(self.domain.name).role_id, self.user_roles[ind].get_id) def tearDown(self): self.domain.delete() self.admin_user.delete() generator.delete_all_subscriptions() generator.delete_all_accounts()
class TestDeleteDomain(TestCase): def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = Location(domain=domain_name, site_code='testcode', name='test1', location_type='facility') location.save() self.locations[domain_name] = location.get_id DeliveryGroupReport.objects.create(location_id=location.get_id, quantity=1, message='test', delivery_group='A') SupplyPointWarehouseRecord.objects.create( supply_point=location.get_id, create_date=datetime.utcnow()) Alert.objects.create(text='test', expires=datetime.utcnow(), date=datetime.utcnow(), location_id=location.get_id) organization_summary = OrganizationSummary.objects.create( date=datetime.utcnow(), location_id=location.get_id) GroupSummary.objects.create(org_summary=organization_summary) ProductAvailabilityData.objects.create(product=product.get_id, date=datetime.utcnow(), location_id=location.get_id) SupplyPointStatus.objects.create(location_id=location.get_id, status_type='del_fac', status_value='received') HistoricalLocationGroup.objects.create( location_id=location.sql_location, group='A', date=datetime.utcnow().date()) ReportRun.objects.create(domain=domain_name, start=datetime.utcnow(), end=datetime.utcnow(), start_run=datetime.utcnow()) ILSNotes.objects.create(location=location.sql_location, domain=domain_name, user_name='test', date=datetime.utcnow(), text='test') SupervisionDocument.objects.create(domain=domain_name, document='test', data_type='test', name='test') def setUp(self): self.domain = Domain(name="test", is_active=True) self.domain.save() self.domain2 = Domain(name="test2", is_active=True) self.domain2.save() self.locations = {} LocationType.objects.create( domain='test', name='facility', ) LocationType.objects.create( domain='test2', name='facility', ) self._create_data('test') self._create_data('test2') def test_pre_delete_signal_receiver(self): self.domain.delete() self.assertEqual( ProductAvailabilityData.objects.filter( location_id=self.locations['test']).count(), 0) self.assertEqual( ProductAvailabilityData.objects.filter( location_id=self.locations['test2']).count(), 1) self.assertEqual( OrganizationSummary.objects.filter( location_id=self.locations['test']).count(), 0) self.assertEqual( OrganizationSummary.objects.filter( location_id=self.locations['test2']).count(), 1) self.assertEqual( GroupSummary.objects.filter( org_summary__location_id=self.locations['test']).count(), 0) self.assertEqual( GroupSummary.objects.filter( org_summary__location_id=self.locations['test2']).count(), 1) self.assertEqual( Alert.objects.filter(location_id=self.locations['test']).count(), 0) self.assertEqual( Alert.objects.filter(location_id=self.locations['test2']).count(), 1) self.assertEqual( DeliveryGroupReport.objects.filter( location_id=self.locations['test']).count(), 0) self.assertEqual( DeliveryGroupReport.objects.filter( location_id=self.locations['test2']).count(), 1) self.assertEqual( SupplyPointWarehouseRecord.objects.filter( supply_point=self.locations['test']).count(), 0) self.assertEqual( SupplyPointWarehouseRecord.objects.filter( supply_point=self.locations['test2']).count(), 1) self.assertEqual( SupplyPointStatus.objects.filter( location_id=self.locations['test']).count(), 0) self.assertEqual( SupplyPointStatus.objects.filter( location_id=self.locations['test2']).count(), 1) self.assertEqual( HistoricalLocationGroup.objects.filter( location_id__location_id=self.locations['test']).count(), 0) self.assertEqual( HistoricalLocationGroup.objects.filter( location_id__location_id=self.locations['test2']).count(), 1) self.assertEqual(ReportRun.objects.filter(domain='test').count(), 0) self.assertEqual(ReportRun.objects.filter(domain='test2').count(), 1) self.assertEqual(ILSNotes.objects.filter(domain='test').count(), 0) self.assertEqual(ILSNotes.objects.filter(domain='test2').count(), 1) self.assertEqual( SupervisionDocument.objects.filter(domain='test').count(), 0) self.assertEqual( SupervisionDocument.objects.filter(domain='test2').count(), 1) def tearDown(self): self.domain2.delete()
class TestDeleteDomain(TestCase): def _create_data(self, domain_name, i): product = Product(domain=domain_name, name='test-{}'.format(i)) product.save() location = Location(domain=domain_name, site_code='testcode-{}'.format(i), name='test-{}'.format(i), location_type='facility') location.save() SupplyPointCase.create_from_location(domain_name, location) report = StockReport.objects.create(type='balance', domain=domain_name, form_id='fake', date=datetime.utcnow()) StockTransaction.objects.create( report=report, product_id=product.get_id, sql_product=SQLProduct.objects.get(product_id=product.get_id), section_id='stock', type='stockonhand', case_id=location.linked_supply_point().get_id, stock_on_hand=100) def setUp(self): self.domain = Domain(name="test", is_active=True) self.domain.save() self.domain2 = Domain(name="test2", is_active=True) self.domain2.save() LocationType.objects.create( domain='test', name='facility', ) LocationType.objects.create( domain='test2', name='facility', ) LocationType.objects.create( domain='test', name='facility2', ) LocationType.objects.create( domain='test2', name='facility2', ) for i in xrange(2): self._create_data('test', i) self._create_data('test2', i) def _assert_sql_counts(self, domain, number): self.assertEqual( StockTransaction.objects.filter(report__domain=domain).count(), number) self.assertEqual( StockReport.objects.filter(domain=domain).count(), number) self.assertEqual( SQLLocation.objects.filter(domain=domain).count(), number) self.assertEqual( SQLProduct.objects.filter(domain=domain).count(), number) self.assertEqual( DocDomainMapping.objects.filter(domain_name=domain).count(), number) self.assertEqual( LocationType.objects.filter(domain=domain).count(), number) def test_sql_objects_deletion(self): self._assert_sql_counts('test', 2) self.domain.delete() self._assert_sql_counts('test', 0) self._assert_sql_counts('test2', 2) def tearDown(self): self.domain2.delete()