def setUp(self): agency = Agency(name='General Services Administration') agency.save() self.user = User.objects.create(username='******', first_name='aaron', last_name='snow') self.billable_accounting_code = AccountingCode(code='abc', agency=agency, office='18F', billable=True) self.billable_accounting_code.save() self.non_billable_accounting_code = AccountingCode(code='def', agency=agency, office='18F', billable=False) self.non_billable_accounting_code.save() self.organization = Organization(name='test-org', active=True, description='a test org') self.organization.save() self.profit_loss_account = ProfitLossAccount( name='PIF', accounting_string='This_is_a_string', as_start_date=datetime.date(2016, 10, 1), as_end_date=datetime.date(2017, 9, 30)) self.profit_loss_account.save() self.project = Project(accounting_code=self.billable_accounting_code, profit_loss_account=self.profit_loss_account, name='Test Project', start_date='2016-01-01', end_date='2016-02-01', agreement_URL='https://thisisaurl.com', project_lead=self.user) self.project.save() self.project_no_url = Project( accounting_code=self.billable_accounting_code, name='Test_no_url Project', start_date='2016-02-01', end_date='2016-02-02', agreement_URL='', project_lead=self.user) self.project_no_url.save() self.project_no_lead = Project( accounting_code=self.billable_accounting_code, name='Test_no_url Project', start_date='2016-02-01', end_date='2016-02-02', agreement_URL='https://thisisaurl.com', project_lead=None) self.project_no_lead.save() self.app.set_user(self.user)
def setUp(self): agency = Agency(name='General Services Administration') agency.save() user = User.objects.create( username='******', first_name='aaron', last_name='snow' ) accounting_code = AccountingCode( code='abc', agency=agency, office='18F', billable=True ) accounting_code.save() profit_loss_account = ProfitLossAccount(name='PIF') profit_loss_account.save() self.project = Project( accounting_code=accounting_code, profit_loss_account=profit_loss_account, name='Test Project', start_date='2016-01-01', end_date='2016-02-01', agreement_URL = 'https://thisisaurl.com', project_lead = user ) self.project.save() self.project_no_url = Project( accounting_code=accounting_code, name='Test_no_url Project', start_date='2016-02-01', end_date='2016-02-02', agreement_URL = '', project_lead = user ) self.project_no_url.save() self.project_no_lead = Project( accounting_code=accounting_code, name='Test_no_url Project', start_date='2016-02-01', end_date='2016-02-02', agreement_URL = 'https://thisisaurl.com', project_lead = None ) self.project_no_lead.save()
class ProjectsTest(WebTest): def setUp(self): agency = Agency(name='General Services Administration') agency.save() self.user = User.objects.create(username='******', first_name='aaron', last_name='snow') self.billable_accounting_code = AccountingCode(code='abc', agency=agency, office='18F', billable=True) self.billable_accounting_code.save() self.non_billable_accounting_code = AccountingCode(code='def', agency=agency, office='18F', billable=False) self.non_billable_accounting_code.save() self.organization = Organization(name='test-org', active=True, description='a test org') self.organization.save() self.profit_loss_account = ProfitLossAccount( name='PIF', accounting_string='This_is_a_string', as_start_date=datetime.date(2016, 10, 1), as_end_date=datetime.date(2017, 9, 30)) self.profit_loss_account.save() self.project = Project(accounting_code=self.billable_accounting_code, profit_loss_account=self.profit_loss_account, name='Test Project', start_date='2016-01-01', end_date='2016-02-01', agreement_URL='https://thisisaurl.com', project_lead=self.user) self.project.save() self.project_no_url = Project( accounting_code=self.billable_accounting_code, name='Test_no_url Project', start_date='2016-02-01', end_date='2016-02-02', agreement_URL='', project_lead=self.user) self.project_no_url.save() self.project_no_lead = Project( accounting_code=self.billable_accounting_code, name='Test_no_url Project', start_date='2016-02-01', end_date='2016-02-02', agreement_URL='https://thisisaurl.com', project_lead=None) self.project_no_lead.save() self.app.set_user(self.user) def test_model(self): """ Check that the project model stores data correctly and links to AccountingCode model properly. """ retrieved = Project.objects.get(pk=self.project.pk) self.assertEqual(retrieved.accounting_code.agency.name, 'General Services Administration') self.assertEqual(retrieved.accounting_code.office, '18F') self.assertEqual(retrieved.start_date, datetime.date(2016, 1, 1)) self.assertEqual(retrieved.end_date, datetime.date(2016, 2, 1)) self.assertTrue(retrieved.accounting_code.billable) self.assertEqual(retrieved.profit_loss_account.name, 'PIF') self.assertEqual(str(retrieved.profit_loss_account), 'PIF - Revenue (10/2016 - 9/2017)') def test_is_billable(self): """ Check that the is_billable method works. """ retrieved = Project.objects.get(name='Test Project') self.assertTrue(retrieved.is_billable()) retrieved.accounting_code.billable = False retrieved.accounting_code.save() self.assertFalse(retrieved.is_billable()) def test_get_profit_and_loss(self): """ Check that the profit_loss_account method works. """ retrieved = Project.objects.get(name='Test Project') self.assertEqual(retrieved.get_profit_loss_account(), 'PIF') retrieved.profit_loss_account.name = "Acq" retrieved.profit_loss_account.save() self.assertEqual(retrieved.get_profit_loss_account(), 'Acq') def test_projects_list_view(self): """ Check that the project list view is open and the saved project are listed. """ response = self.app.get(reverse('ProjectListView')) anchor = response.html.find('a', href='/projects/{0}'.format( self.project.id)) self.assertIsNotNone(anchor) def test_projects_list_view_with_alert(self): """ Check that the project list view is open and the saved project is listed with an alert. """ project_alert = ProjectAlert(title='Test Alert', description='This is a test alert.') project_alert.save() self.project.alerts.add(project_alert) response = self.app.get(reverse('ProjectListView')) span = response.html.find('span') self.assertIsNotNone(span) def test_projects_list_view_with_alert_including_url(self): """ Check that the project list view is open and the saved project is listed with an alert that has a URL. """ project_alert = ProjectAlert(title='Test Alert', description='This is a test alert.', destination_url='http://www.gsa.gov/') project_alert.save() self.project.alerts.add(project_alert) response = self.app.get(reverse('ProjectListView')) anchor = response.html.find('a', href='http://www.gsa.gov/') span = response.html.find('span') self.assertIsNotNone(span) self.assertIsNotNone(anchor) def test_project_detail_view_with_alert(self): """ Check that the project list view is open and the saved project is listed with an alert. """ project_alert = ProjectAlert(title='Test Alert', description='This is a test alert.') project_alert.save() self.project.alerts.add(project_alert) response = self.app.get( reverse('ProjectView', kwargs={'pk': self.project.id})) span = response.html.find('span') self.assertIsNotNone(span) def test_project_detail_view_with_alert_including_url(self): """ Check that the project list view is open and the saved project is listed with an alert that has a URL. """ project_alert = ProjectAlert(title='Test Alert', description='This is a test alert.', destination_url='http://www.gsa.gov/') project_alert.save() self.project.alerts.add(project_alert) response = self.app.get( reverse('ProjectView', kwargs={'pk': self.project.id})) anchor = response.html.find('a', href='http://www.gsa.gov/') span = response.html.find('span') self.assertIsNotNone(span) self.assertIsNotNone(anchor) def test_notes_required_enables_notes_displayed(self): """ Test when the notes_required attribute is enabled on a Project instance that the notes_displayed attribute is automatically enabled. """ project = Project.objects.get(name='Test Project') self.assertFalse(project.notes_displayed) project.notes_required = True project.save() self.assertTrue(project.notes_displayed) def test_agreement_url_displays_correctly(self): response = self.app.get( reverse('ProjectView', kwargs={'pk': self.project.id})) url = response.html.find('a', href=self.project.agreement_URL) self.assertEqual( str(url), '<a href="{0}"> Google Drive folder </a>'.format( self.project.agreement_URL)) def test_no_agreement_url(self): response = self.app.get( reverse('ProjectView', kwargs={'pk': self.project_no_url.id})) test_string = 'No agreement URL available' self.assertContains(response, test_string) def test_no_project_lead(self): response = self.app.get( reverse('ProjectView', kwargs={'pk': self.project_no_lead.id})) test_string = 'No project lead available' self.assertContains(response, test_string) def test_billable_project_requires_organization(self): project = Project(accounting_code=self.billable_accounting_code, profit_loss_account=self.profit_loss_account, name='Billable Project', start_date='2016-01-01', end_date='2016-02-01', agreement_URL='https://thisisaurl.com', project_lead=self.user) with self.assertRaises(ValidationError): project.full_clean() project.organization = self.organization try: project.full_clean() except ValidationError: self.fail('full_clean raised a ValidationError') def test_non_billable_project_not_requires_organization(self): project = Project(accounting_code=self.non_billable_accounting_code, profit_loss_account=self.profit_loss_account, name='Billable Project', start_date='2016-01-01', end_date='2016-02-01', agreement_URL='https://thisisaurl.com', project_lead=self.user) try: project.full_clean() except ValidationError: self.fail('full_clean raised a validation error')