def setUp(self): self.regular_user = get_user_model().objects.create( username='******') userdata = UserData(user=self.regular_user) userdata.start_date = datetime.date(2014, 1, 1) userdata.end_date = datetime.date(2016, 1, 1) userdata.save()
def test_ReportingPeriodList_json_missing_timesheet(self): """ Check that the ReportingPeriodList shows users that have missing time cards """ # Create a user self.regular_user = User.objects.create(username='******') userdata = UserData(user=self.regular_user) userdata.save() reporting_periods = client().get(reverse('ReportingPeriodList')).data start_date = reporting_periods[0]['start_date'] res = client().get( reverse('ReportingPeriodAudit', kwargs={'reporting_period_start_date': start_date})).data self.assertEqual(len(res), 1)
def test_ReportingPeriodList_json_no_longer_employed(self): """ Check that the ReportingPeriodList shows users that have missing time cards """ # Create a user, but set the user as unemployed self.regular_user = User.objects.create(username='******') userdata = UserData(user=self.regular_user) userdata.current_employee = False userdata.save() reporting_periods = client().get(reverse('ReportingPeriodList')).data start_date = reporting_periods[0]['start_date'] res = client().get( reverse('ReportingPeriodAudit', kwargs={'reporting_period_start_date': start_date})).data self.assertEqual(len(res), 0)
def test_ReportingPeriodList_json_missing_timesheet(self): """ Check that the ReportingPeriodList shows users that have missing time cards """ # Create a user self.regular_user = get_user_model().objects.create( username='******') userdata = UserData(user=self.regular_user) userdata.save() reporting_periods = self.app.get(reverse('ReportingPeriodList')) start_date = reporting_periods.json['results'][0]['start_date'] res = self.app.get( reverse('ReportingPeriodAudit', kwargs={'reporting_period_start_date': start_date})) self.assertEqual(res.json['count'], 1)
def setUp(self): self.regular_user = get_user_model().objects.create( username="******") self.regular_user.save() UserData(user=self.regular_user, start_date=datetime.datetime(2014, 1, 1), end_date=datetime.datetime(2016, 1, 1)).save()
def test_ReportingPeriodList_json_missing_timesheet(self): """ Check that the ReportingPeriodList shows users that have missing time cards """ # Create a user self.regular_user = get_user_model().objects.create( username='******') userdata = UserData(user=self.regular_user) userdata.save() reporting_periods = self.app.get(reverse('ReportingPeriodList')) start_date = reporting_periods.json['results'][0]['start_date'] res = self.app.get(reverse( 'ReportingPeriodAudit', kwargs={'reporting_period_start_date': start_date} ) ) self.assertEqual(res.json['count'], 1)
def setUp(self): self.reporting_period = hours.models.ReportingPeriod.objects.create( start_date=datetime.date(2015, 1, 1), end_date=datetime.date(2015, 1, 7), exact_working_hours=40) self.user = get_user_model().objects.get(id=1) self.userdata = UserData.objects.create(user=self.user) self.timecard = hours.models.Timecard.objects.create( user=self.user, submitted=True, reporting_period=self.reporting_period) self.project_1 = projects.models.Project.objects.get(name="openFEC") self.project_2 = projects.models.Project.objects.get( name="Peace Corps") self.timecard_object_1 = hours.models.TimecardObject.objects.create( timecard=self.timecard, project=self.project_1, hours_spent=12) self.timecard_object_2 = hours.models.TimecardObject.objects.create( timecard=self.timecard, project=self.project_2, hours_spent=28) self.regular_user = get_user_model().objects.create( username='******', email='*****@*****.**', is_superuser=False, ) self.regular_user.save() UserData( user=self.regular_user, start_date=datetime.date(2015, 1, 1), end_date=datetime.date(2017, 1, 1), ).save() self.former_employee = get_user_model().objects.create( username='******', email='*****@*****.**', is_superuser=False, ) self.regular_user.save() UserData( user=self.former_employee, start_date=datetime.date(2015, 1, 1), end_date=datetime.date(2017, 1, 1), current_employee=False, ).save()
def test_project_choice_filtering(self): """Tests that the project choices are filtered to only include those assigned to the user's organization and those with no organization assignment.""" # additional test setup org_18f = Organization.objects.create(name='18F') org_18f.save() org_coe = Organization.objects.create(name='CoE') org_coe.save() accounting_code = projects.models.AccountingCode.objects.get(pk=1) project_18f = projects.models.Project.objects.create( name='an 18f project', accounting_code=accounting_code, organization=org_18f) project_18f.save() project_coe = projects.models.Project.objects.create( name='a coe project', accounting_code=accounting_code, organization=org_coe) project_coe.save() project_none = projects.models.Project.objects.create( name='a project with no org assignment', accounting_code=accounting_code, ) project_none.save() user_18f = get_user_model().objects.create(username='******') user_18f.save() UserData(user=user_18f, organization=org_18f).save() date = self.reporting_period.start_date.strftime('%Y-%m-%d') response = self.app.get( reverse('reportingperiod:UpdateTimesheet', kwargs={'reporting_period': date}), user=user_18f, ) project_18f_found = False project_coe_found = False project_none_found = False str_formset = str(response.context['formset']).split('\n') for line in str_formset: if line.find(f'option value="{project_18f.id}"') > 0: project_18f_found = True if line.find(f'option value="{project_coe.id}"') > 0: project_coe_found = True if line.find(f'option value="{project_none.id}"') > 0: project_none_found = True self.assertTrue(project_18f_found) self.assertFalse(project_coe_found) self.assertTrue(project_none_found)
def setUp(self): self.regular_user = get_user_model().objects.create( username='******') userdata = UserData(user=self.regular_user) userdata.start_date = datetime.date(2014, 1, 1) userdata.end_date = datetime.date(2016, 1, 1) userdata.unit = 1 userdata.is_18f_employee = True userdata.save()
def create_user(self, username, password=None, is_staff=False, is_superuser=False, email=None, groups=(), start_date=datetime.datetime(2014, 1, 1), end_date=datetime.datetime(2016, 1, 1)): try: user = User.objects.get(username=username) except User.DoesNotExist: user = User.objects.create_user(username=username, password=password, email=email) try: UserData.objects.get(user=user) except UserData.DoesNotExist: UserData(user=user, start_date=start_date, end_date=end_date).save() for groupname in groups: group = Group.objects.get(name=groupname) group.user_set.add(user) group.save() if is_staff: user.is_staff = True user.save() if is_superuser: user.is_staff = True user.is_superuser = True user.save() return user