Exemple #1
0
    def if_interviewer(self, interviewer_email, slot=None, pk=None):
        interviewer_emails = interviewer_email.split(',')
        if slot:
            if Interview.objects.filter(slot=slot, interviewer__email__in=interviewer_emails):
                return '', 'Interviewer/s already has an interview at given time slot.'

        interviewer_list = []
        try:
            for interviewer_email in interviewer_emails:
                obj, _ = Interviewer.objects.get_or_create(email=interviewer_email)
                interviewer_list.append(obj)

            if pk:
                interview = Interview.objects.get(id=pk)
                interview.interviewer.set(interviewer_list)

                self.check_is_scheduled(interview)

            else:
                interview = Interview.objects.create(slot=slot)
                interview.interviewer.set(interviewer_list)

            return InterviewSerializer(interview).data, ''

        except Exception as e:
            return '', str(e)
Exemple #2
0
    def test_get_interview_by_interviewer(self):
        interviewer_emails = [
            '*****@*****.**', '*****@*****.**'
        ]

        interviewer = Interviewer.objects.create(email=interviewer_emails[0])
        interviewer2 = Interviewer.objects.create(email=interviewer_emails[1])

        candidate = Candidate.objects.create(email='*****@*****.**')
        candidate2 = Candidate.objects.create(email='*****@*****.**')

        interview = Interview.objects.create(slot=10,
                                             candidate=candidate,
                                             is_scheduled=True)
        interview.interviewer.set([interviewer, interviewer2])

        interview = Interview.objects.create(slot=17,
                                             candidate=candidate2,
                                             is_scheduled=True)
        interview.interviewer.set([interviewer2])

        for interviewer_email in interviewer_emails:
            response = self.client.get(
                self.url, {'interviewer_email': interviewer_email},
                format='json')
            serialized_obj = InterviewSerializer(
                Interview.objects.filter(interviewer__email=interviewer_email),
                many=True)

            self.assertEqual(response.data['results'], serialized_obj.data)

        response = self.client.get(self.url, {
            'interviewer_email':
            '{},{}'.format(interviewer_emails[0], interviewer_emails[1])
        },
                                   format='json')

        serialized_obj = InterviewSerializer(Interview.objects.filter(
            interviewer__email__in=interviewer_emails),
                                             many=True)

        self.assertEqual(response.data['results'], serialized_obj.data)
Exemple #3
0
    def test_create_interview_by_candidate(self):

        email = '*****@*****.**'
        slot = 17
        response = self.client.post(self.url, {
            'candidate_email': email,
            'slot': slot
        },
                                    format='json')

        candidate = Candidate.objects.get(email=email)

        interview = Interview.objects.get(slot=slot, candidate=candidate)
        serialized_obj = InterviewSerializer(interview).data

        self.assertDictEqual(response.data, serialized_obj)
Exemple #4
0
    def test_get_interview_by_interviewer_and_candidate(self):
        interviewer_emails = [
            '*****@*****.**', '*****@*****.**'
        ]
        candidate_emails = [
            '*****@*****.**', '*****@*****.**',
            '*****@*****.**'
        ]

        interviewer = Interviewer.objects.create(email=interviewer_emails[0])
        interviewer2 = Interviewer.objects.create(email=interviewer_emails[1])

        candidate = Candidate.objects.create(email=candidate_emails[0])
        candidate2 = Candidate.objects.create(email=candidate_emails[1])
        candidate3 = Candidate.objects.create(email=candidate_emails[2])

        interview = Interview.objects.create(slot=10,
                                             candidate=candidate,
                                             is_scheduled=True)
        interview.interviewer.set([interviewer, interviewer2])

        interview = Interview.objects.create(slot=17,
                                             candidate=candidate2,
                                             is_scheduled=True)
        interview.interviewer.set([interviewer2])

        interview = Interview.objects.create(slot=18,
                                             candidate=candidate3,
                                             is_scheduled=True)
        interview.interviewer.set([interviewer2])

        response = self.client.get(self.url, {
            'interviewer_email': interviewer_emails[1],
            'candidate_email': candidate_emails[1]
        },
                                   format='json')
        serialized_obj = InterviewSerializer(Interview.objects.filter(
            interviewer__email=interviewer_emails[1],
            candidate__email=candidate_emails[1]),
                                             many=True)

        self.assertEqual(response.data['results'], serialized_obj.data)
Exemple #5
0
    def test_create_interview_by_interviewers(self):

        email = '[email protected],[email protected]'
        emails = email.split(',')
        slot = 13
        response = self.client.post(self.url, {
            'interviewer_email': email,
            'slot': slot
        },
                                    format='json')

        try:
            interviewers = Interviewer.objects.filter(email__in=emails)
            interview = Interview.objects.filter(
                slot=slot, interviewer__in=interviewers).distinct().get()
            serialized_obj = InterviewSerializer(interview)

            self.assertDictEqual(response.data, serialized_obj.data)

        except ObjectDoesNotExist:
            self.fail('Creation of Interview object failed.')
Exemple #6
0
    def if_candidate(self, candidate_email, slot=None, pk=None):
        if slot:
            if Interview.objects.filter(slot=slot, candidate__email=candidate_email):
                return '', 'Candidate already has an interview at given time slot.'

        try:
            candidate, _ = Candidate.objects.get_or_create(email=candidate_email)

            if pk:
                interview = Interview.objects.get(id=pk)
                interview.candidate = candidate
                interview.save()

                self.check_is_scheduled(interview)

            else:
                interview, _ = Interview.objects.get_or_create(slot=slot, candidate=candidate)

            return InterviewSerializer(interview).data, ''

        except Exception as e:
            return '', str(e)
Exemple #7
0
    def test_get_interview_by_candidate(self):

        candidate_emails = [
            '*****@*****.**', '*****@*****.**',
            '*****@*****.**'
        ]
        candidate = Candidate.objects.create(email=candidate_emails[0])
        candidate2 = Candidate.objects.create(email=candidate_emails[1])
        candidate3 = Candidate.objects.create(email=candidate_emails[2])

        interviewer = Interviewer.objects.create(
            email='*****@*****.**')
        interviewer2 = Interviewer.objects.create(
            email='*****@*****.**')

        interview = Interview.objects.create(slot=11,
                                             candidate=candidate,
                                             is_scheduled=True)
        interview.interviewer.set([interviewer, interviewer2])

        interview = Interview.objects.create(slot=12,
                                             candidate=candidate3,
                                             is_scheduled=True)
        interview.interviewer.set([interviewer])

        interview = Interview.objects.create(slot=14,
                                             candidate=candidate2,
                                             is_scheduled=True)
        interview.interviewer.set([interviewer2])

        for candidate_email in candidate_emails:
            response = self.client.get(self.url,
                                       {'candidate_email': candidate_email},
                                       format='json')
            serialized_obj = InterviewSerializer(
                Interview.objects.filter(candidate__email=candidate_email),
                many=True)

            self.assertEqual(response.data['results'], serialized_obj.data)