def test_expected_number_of_queries(self): user = User.objects.filter( profile__organization__county__slug='alameda').first() to_org = Organization.objects.get(slug='ebclc') application = models.Application.objects.filter( organization__slug='a_pubdef').first() with self.assertNumQueries(8): TransferService.transfer_application( user, application, to_org, 'there was a temporal anomaly')
def test_expected_number_of_queries(self): user = User.objects.filter( profile__organization__county__slug='alameda').first() to_org = Organization.objects.get(slug='ebclc') application = models.Application.objects.filter( organization__slug='a_pubdef').first() with self.assertNumQueries(4): TransferService.transfer_application( user, application, to_org, 'there was a temporal anomaly')
def test_results_for_org_who_has_outgoing_transfers(self): user = User.objects.filter( profile__organization__slug='a_pubdef').first() to_org = Organization.objects.get(slug='ebclc') application = models.Application.objects.filter( organization__county__slug='alameda').first() TransferService.transfer_application(user, application, to_org, 'food replicator malfunction') with self.assertNumQueries(8): results = AppsService.get_applications_index_for_org_user(user, 1) self.assertTrue(any([app['was_transferred_out'] for app in results]))
def test_all_results_for_org_who_has_outgoing_transfers(self): user = User.objects.filter( profile__organization__slug='a_pubdef').first() to_org = Organization.objects.get(slug='ebclc') application = models.Application.objects.filter( organization__county__slug='alameda').first() TransferService.transfer_application( user, application, to_org, 'food replicator malfunction') with self.assertNumQueries(5): results = AppsService.get_all_applications_for_org_user(user, 1) self.assertTrue( any([ app['was_transferred_out'] for app in results ]))
def test_creates_expected_objects(self): user = User.objects.filter( profile__organization__slug='a_pubdef').first() to_org = Organization.objects.get(slug='ebclc') application = models.Application.objects.filter( organization__slug='a_pubdef').first() TransferService.transfer_application( user, application, to_org, 'because of subspace interference') new_application = models.Application.objects.filter( incoming_transfers__status_update__author=user).first() self.assertTrue(new_application.pk) self.assertEqual(new_application.incoming_transfers.count(), 1) transfer = new_application.incoming_transfers.first() self.assertEqual( transfer.status_update.status_type.pk, models.status_type.TRANSFERRED) self.assertEqual( transfer.status_update.application.organization.county.slug, 'alameda') self.assertEqual(transfer.reason, 'because of subspace interference') self.assertTrue(application.was_transferred_out)
def test_results_for_org_who_has_incoming_transfers(self): author = User.objects.filter( profile__organization__slug='a_pubdef').first() to_org = Organization.objects.get(slug='ebclc') applications = models.Application.objects.filter( organization__slug='a_pubdef') for application in applications: TransferService.transfer_application(author, application, to_org, 'temporal anomalies') user = User.objects.filter(profile__organization__slug='ebclc')[0] with self.assertNumQueries(17): results = AppsService.get_applications_index_for_org_user(user, 1) transferred_apps = [ app for app in results if app['incoming_transfers'] ] self.assertTrue(transferred_apps) transfer = transferred_apps[0]['incoming_transfers'][0] self.assertEqual(transfer['organization_name'], author.profile.organization.name) self.assertEqual(transfer['author_name'], author.profile.name) self.assertEqual(transfer['reason'], 'temporal anomalies')
def test_all_results_for_org_who_has_incoming_transfers(self): author = User.objects.filter( profile__organization__slug='a_pubdef').first() to_org = Organization.objects.get(slug='ebclc') applications = models.Application.objects.filter( organization__slug='a_pubdef') for application in applications: TransferService.transfer_application( author, application, to_org, 'temporal anomalies') user = User.objects.filter( profile__organization__slug='ebclc')[0] with self.assertNumQueries(16): results = AppsService.get_all_applications_for_org_user(user, 1) transferred_apps = [ app for app in results if app['incoming_transfers']] self.assertTrue(transferred_apps) transfer = transferred_apps[0]['incoming_transfers'][0] self.assertEqual( transfer['organization_name'], author.profile.organization.name) self.assertEqual( transfer['author_name'], author.profile.name) self.assertEqual( transfer['reason'], 'temporal anomalies')
def test_creates_expected_objects(self): user = User.objects.filter( profile__organization__slug='a_pubdef').first() to_org = Organization.objects.get(slug='ebclc') application = models.Application.objects.filter( organization__slug='a_pubdef').first() with self.assertLogs( 'project.services.logging_service', logging.INFO) as logs: TransferService.transfer_application( user, application, to_org, 'because of subspace interference') new_application = models.Application.objects.filter( incoming_transfers__status_update__author=user).first() self.assertTrue(new_application.pk) self.assertEqual(new_application.incoming_transfers.count(), 1) transfer = new_application.incoming_transfers.first() self.assertEqual( transfer.status_update.status_type.slug, 'transferred') self.assertEqual( transfer.status_update.application.organization.county.slug, 'alameda') self.assertEqual(transfer.reason, 'because of subspace interference') self.assertTrue(application.was_transferred_out) assertInLogsCount(logs, {'event_name=app_transferred': 1})
def test_creates_expected_objects(self): user = User.objects.filter( profile__organization__slug='a_pubdef').first() to_org = Organization.objects.get(slug='ebclc') application = models.Application.objects.filter( organization__slug='a_pubdef').first() with self.assertLogs('project.services.logging_service', logging.INFO) as logs: TransferService.transfer_application( user, application, to_org, 'because of subspace interference') new_application = models.Application.objects.filter( incoming_transfers__status_update__author=user).first() self.assertTrue(new_application.pk) self.assertEqual(new_application.incoming_transfers.count(), 1) transfer = new_application.incoming_transfers.first() self.assertEqual(transfer.status_update.status_type.slug, 'transferred') self.assertEqual( transfer.status_update.application.organization.county.slug, 'alameda') self.assertEqual(transfer.reason, 'because of subspace interference') self.assertTrue(application.was_transferred_out) assertInLogsCount(logs, {'event_name=app_transferred': 1})
def test_number_of_queries_if_transferred_in(self): author = User.objects.filter( profile__organization__slug='a_pubdef').first() application = models.Application.objects.filter( organization__slug='a_pubdef').first() to_org = Organization.objects.get(slug='ebclc') receiving_user = User.objects.filter( profile__organization__slug='ebclc').first() transfer, *other = TransferService.transfer_application( author, application, to_org, 'holodeck malfunction') app = transfer.new_application new_updates_count = random.randint(1, 7) for i in range(new_updates_count): factories.StatusUpdateFactory.create(application=app, author=receiving_user) with self.assertNumQueriesLessThanEqual(14): AppsService.get_serialized_application_history_events( application, receiving_user)
def test_number_of_queries_if_transferred_in(self): author = User.objects.filter( profile__organization__slug='a_pubdef').first() application = models.Application.objects.filter( organization__slug='a_pubdef').first() to_org = Organization.objects.get(slug='ebclc') receiving_user = User.objects.filter( profile__organization__slug='ebclc').first() transfer, *other = TransferService.transfer_application( author, application, to_org, 'holodeck malfunction') app = transfer.new_application new_updates_count = random.randint(1, 7) for i in range(new_updates_count): factories.StatusUpdateFactory.create( application=app, author=receiving_user) with self.assertNumQueriesLessThanEqual(14): AppsService.get_serialized_application_history_events( application, receiving_user)