Beispiel #1
0
    def __init__(self, *args, **kwargs):
        user = kwargs.pop("user")
        super(WorkItemForm, self).__init__(*args, **kwargs)

        queryset = Job.get_jobs_open_on(datetime.date.today())

        queryset = queryset.filter(Q(available_all_users=True) | Q(users__id=user.id)).distinct()
        queryset = queryset.order_by('name')
        self.fields["job"].queryset = queryset

        self.fields["hours"].widget.attrs['class'] = 'form-control'
        self.fields["text"].widget.attrs['class'] = 'form-control'

        self.fields["hours"].widget.attrs['placeholder'] = 'Hours Worked'
        self.fields["text"].widget.attrs['placeholder'] = 'Work Description'

        self.fields["text"].widget.attrs['rows'] = '6'

        if args:
            data = args[0]
        else:
            data = kwargs.get('data')

        if data:
            repo_id = data.get('repo')
            if repo_id:
                repo = Repo.objects.get(github_id=repo_id)
                self.fields["issue"].queryset = Issue.objects.filter(repo=repo)
Beispiel #2
0
    def test_get_queryset(self):

        oldest_job = Job.objects.all().order_by('open_date')[0]
        today = datetime.date.today()
        date_list = [today - datetime.timedelta(days=x) for x in range(0, (today - oldest_job.open_date).days)]

        for date in date_list:
            expected_qs = Job.get_jobs_open_on(date)
            response = self.client.get('/worklog/api/jobs/', {'date': date})
            actual_qs = [value["id"] for value in response.data]
            expected_qs = [value.id for value in expected_qs]
            self.assertEqual(list(actual_qs), list(expected_qs))

        job_names = Job.objects.all().values_list('name', flat=True)

        for name in job_names:
            expected_qs = Job.objects.filter(name=name)
            response = self.client.get('/worklog/api/jobs/', {'name': name})
            actual_qs = [value["id"] for value in response.data]
            expected_qs = [value.id for value in expected_qs]
            self.assertEqual(list(actual_qs), list(expected_qs))

        for user in range(1, 30):
            expected_qs = Job.objects.filter(Q(users__id=user) | Q(available_all_users=True)).distinct().order_by('pk')
            response = self.client.get('/worklog/api/jobs/', {'user': user})
            actual_qs = [value["id"] for value in response.data]
            expected_qs = [value.id for value in expected_qs]
            self.assertEqual(list(actual_qs), list(expected_qs))

        # make a for loop that pics a random date and random job value
        # then loop through for each user
        for x in range(1, 10):
            random_date = date_list[randrange(len(date_list))]
            random_job = job_names[randrange(len(job_names))]
            for user in range(1, 10):
                query_params = {'date': random_date, 'name': random_job, 'user': user}
                expected_qs = Job.get_jobs_open_on(random_date)
                expected_qs = expected_qs.filter(name=random_job)
                expected_qs = expected_qs.filter(Q(users__id=user) | Q(available_all_users=True)).distinct().order_by('pk')
                response = self.client.get('/worklog/api/jobs/', query_params)
                actual_qs = [value["id"] for value in response.data]
                expected_qs = [value.id for value in expected_qs]
                self.assertEqual(list(actual_qs), list(expected_qs))
Beispiel #3
0
	def validate_job(self, attrs, source):

		if attrs[source] is None:
			raise serializers.ValidationError("This field is required.")

		open_jobs = Job.get_jobs_open_on(datetime.date.today())

		if not open_jobs.get(name=attrs[source]):
			raise serializers.ValidationError("Job must be open.")

		return attrs
Beispiel #4
0
 def __init__(self, *args, **kwargs):
     reminder = kwargs.pop("reminder")
     user = kwargs.pop("logged_in_user");
     super(WorkItemForm,self).__init__(*args,**kwargs)
     
     if reminder:
         queryset = reminder.get_available_jobs()
     else:
         queryset = Job.get_jobs_open_on(datetime.date.today())
     
     queryset = queryset.filter(Q(available_all_users=True)|Q(users__id=user.id)).distinct()
     queryset = queryset.order_by('name')
     self.fields["job"].queryset = queryset
Beispiel #5
0
    def validate_job(self, value):

        if value is None:
            raise serializers.ValidationError("This field is required.")

        open_jobs = Job.get_jobs_open_on(datetime.date.today())

        try:
            open_jobs.get(name=value)
        except ObjectDoesNotExist:
            raise serializers.ValidationError("Job must be open.")

        return value
Beispiel #6
0
    def test_basic_get(self):
        with self.scoped_login('master', 'password'):
            response = self.client.get('/worklog/' + str(self.today) + '/')

            qs = Job.get_jobs_open_on(self.today)

            self.assertEquals(qs.count(),4)
            names = list(job.name for job in qs)
            self.assertTrue("Job_Today" in names)
            self.assertTrue("Job_OneDay" in names)
            self.assertTrue("Job_LastWeek" in names)
            self.assertTrue("Job_LastWeek2" in names)

            self.assertEquals(len(response.context['items']),0)
Beispiel #7
0
    def setUp(self):

        self._factory = APIRequestFactory()

        factories.UserFactory.create_batch(10)
        factories.WorkItemFactory.create_batch(10)
        factories.JobFactory.create_batch(10)

        self.user_pks = list(User.objects.all().values_list('pk', flat=True))
        self.workitem_pks = list(WorkItem.objects.all().values_list('pk', flat=True))
        self.job_pks = list(Job.get_jobs_open_on(datetime.date.today()).values_list('pk', flat=True))
        self.repo_pks = list(Repo.objects.all().values_list('pk', flat=True))
        self.issue_pks = list(Issue.objects.all().values_list('pk', flat=True))

        auth_user = User.objects.get(pk=self.user_pks[0])
        self.client.force_authenticate(user=auth_user)
Beispiel #8
0
    def setUp(self):
        self.serializer = WorkItemSerializer()

        factories.UserFactory.create_batch(10)
        factories.WorkItemFactory.create_batch(10)
        factories.JobFactory.create_batch(10)
        factories.RepoFactory.create_batch(10)
        factories.IssueFactory.create_batch(10)

        self.jobs = Job.objects.all()
        self.open_jobs = Job.get_jobs_open_on(datetime.date.today())
        self.closed_jobs = Job.objects.exclude(pk__in=self.open_jobs.values_list('pk', flat=True))

        self.repos = list(Repo.objects.all())
        self.issues = list(Issue.objects.all())

        for issue in self.issues:
            if issue.repo != self.repos[0]:
                self.repo_issue_mismatch = {'repo': self.repos[0], 'issue': issue}
                break