From 1378898d371e4bc0c4cae8c5caa065630b7e1679 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Tue, 3 Oct 2023 01:47:26 +0530 Subject: [PATCH 01/38] Updated Backend To Accomodate Internships --- CDC_Backend/APIs/admin.py | 20 +- CDC_Backend/APIs/adminViews.py | 308 ++++++++++++++++++++++++------- CDC_Backend/APIs/companyViews.py | 31 ++++ CDC_Backend/APIs/constants.py | 7 + CDC_Backend/APIs/models.py | 14 ++ CDC_Backend/APIs/serializers.py | 141 ++++++++++++++ CDC_Backend/APIs/studentUrls.py | 17 +- CDC_Backend/APIs/studentViews.py | 76 ++++++-- CDC_Backend/APIs/utils.py | 42 ++++- setup.sh | 2 +- 10 files changed, 562 insertions(+), 96 deletions(-) mode change 100644 => 100755 setup.sh diff --git a/CDC_Backend/APIs/admin.py b/CDC_Backend/APIs/admin.py index 3cb49a0..7e72dc7 100644 --- a/CDC_Backend/APIs/admin.py +++ b/CDC_Backend/APIs/admin.py @@ -138,6 +138,13 @@ class PlacementApplicationResources(resources.ModelResource): class PlacementAdmin(ExportMixin, SimpleHistoryAdmin): resource_class = PlacementApplicationResources +class InternshipApplicationResources(resources.ModelResource): + class Meta: + model = InternshipApplication + exclude = ('id', 'changed_by') +class InternshipApplicationAdmin(ExportMixin, SimpleHistoryAdmin): + resource_class = InternshipApplicationResources + @admin.register(PlacementApplication) class PlacementApplication(PlacementAdmin): @@ -151,7 +158,18 @@ class PlacementApplication(PlacementAdmin): def Student(self, obj): return model_admin_url(obj.student) +@admin.register(InternshipApplication) +class InternshipApplication(InternshipApplicationAdmin): + list_display = ('id', 'Internship', 'Student', 'selected') + search_fields = ('id',) + ordering = ('id',) + list_filter = ('selected',) + def Internship(self, obj): + return model_admin_url(obj.internship) + + def Student(self, obj): + return model_admin_url(obj.student) class PrePlacementResources(resources.ModelResource): class Meta: @@ -178,7 +196,7 @@ class InternshipResources(resources.ModelResource): class Meta: model = Internship exclude = ('id', 'changed_by', 'is_company_details_pdf', 'is_description_pdf', - 'is_compensation_details_pdf', 'is_selection_procedure_details_pdf') + 'is_stipend_details_pdf', 'is_selection_procedure_details_pdf') class InternAdmin(ExportMixin, SimpleHistoryAdmin): diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index e935e8d..a834b01 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -12,9 +12,18 @@ from .utils import * def markStatus(request, id, email, user_type): try: data = request.data + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] #not to break the code + else: + opening_type= "Placement" + if opening_type == "Internship": + applications = InternshipApplication.objects.filter(internship_id=data[OPENING_ID]) + else: + applications = PlacementApplication.objects.filter(placement_id=data[OPENING_ID]) # Getting all application from db for this opening - applications = PlacementApplication.objects.filter(placement_id=data[OPENING_ID]) + # applications = PlacementApplication.objects.filter(placement_id=data[OPENING_ID]) for i in data[STUDENT_LIST]: + # print(i[STUDENT_ID]) issue is using student id instead of roll no both may not be same application = applications.filter(student__roll_no=i[STUDENT_ID]) # Filtering student's application if len(application) > 0: application = application[0] @@ -27,14 +36,23 @@ def markStatus(request, id, email, user_type): raise ValueError("Student already selected") email = str(application.student.roll_no) + "@iitdh.ac.in" # Only allowing for IITDh emails - subject = STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT.format( - company_name=application.placement.company_name, - id=application.id) - data = { - "company_name": application.placement.company_name, - "designation": application.placement.designation, - "student_name": application.student.name - } + if opening_type == "Internship": + subject = STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT.format( + company_name=application.internship.company_name,id=application.id) + data = { + "company_name": application.internship.company_name, + "designation": application.internship.designation, + "student_name": application.student.name + } + else: + subject = STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT.format( + company_name=application.placement.company_name, + id=application.id) + data = { + "company_name": application.placement.company_name, + "designation": application.placement.designation, + "student_name": application.student.name + } if application.selected: # Sending corresponding email to students sendEmail(email, subject, data, STUDENT_APPLICATION_STATUS_SELECTED_TEMPLATE) else: @@ -64,13 +82,22 @@ def getDashboard(request, id, email, user_type): previous = placements.exclude(deadline_datetime__gt=timezone.now()).filter( offer_accepted=True, email_verified=True) new = placements.filter(offer_accepted__isnull=True, email_verified=True) + internships=Internship.objects.all().order_by('-created_at') + ongoing_internships = internships.filter(deadline_datetime__gt=timezone.now(), offer_accepted=True, email_verified=True) + previous_internships = internships.exclude(deadline_datetime__gt=timezone.now()).filter( + offer_accepted=True, email_verified=True) + new_internships = internships.filter(offer_accepted__isnull=True, email_verified=True) ongoing = PlacementSerializerForAdmin(ongoing, many=True).data previous = PlacementSerializerForAdmin(previous, many=True).data new = PlacementSerializerForAdmin(new, many=True).data + ongoing_internships = InternshipSerializerForAdmin(ongoing_internships, many=True).data + previous_internships = InternshipSerializerForAdmin(previous_internships, many=True).data + new_internships = InternshipSerializerForAdmin(new_internships, many=True).data return Response( {'action': "Get Dashboard - Admin", 'message': "Data Found", "ongoing": ongoing, "previous": previous, - "new": new}, + "new": new, "ongoing_internships": ongoing_internships, "previous_internships": previous_internships, + "new_internships": new_internships}, status=status.HTTP_200_OK) except Http404: return Response({'action': "Get Dashboard - Admin", 'message': 'Student Not Found'}, @@ -87,7 +114,15 @@ def getDashboard(request, id, email, user_type): def updateDeadline(request, id, email, user_type): try: data = request.data - opening = get_object_or_404(Placement, pk=data[OPENING_ID]) + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] + else: + opening_type= "Placement" + if opening_type == "Internship": + opening = get_object_or_404(Internship, pk=data[OPENING_ID]) + else: + opening = get_object_or_404(Placement, pk=data[OPENING_ID]) + # Updating deadline date with correct format in datetime field opening.deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z') opening.changed_by = get_object_or_404(User, id=id) @@ -110,7 +145,14 @@ def updateOfferAccepted(request, id, email, user_type): try: data = request.data offer_accepted = data[OFFER_ACCEPTED] - opening = get_object_or_404(Placement, pk=data[OPENING_ID]) + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] + else: + opening_type= "Placement" + if opening_type == "Internship": + opening = get_object_or_404(Internship, pk=data[OPENING_ID]) + else: + opening = get_object_or_404(Placement, pk=data[OPENING_ID]) if opening.offer_accepted is None: opening.offer_accepted = offer_accepted == "true" opening.changed_by = get_object_or_404(User, id=id) @@ -140,7 +182,14 @@ def updateOfferAccepted(request, id, email, user_type): def updateEmailVerified(request, id, email, user_type): try: data = request.data - opening = get_object_or_404(Placement, pk=data[OPENING_ID]) + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] + else: + opening_type= "Placement" + if opening_type == "Internship": + opening = get_object_or_404(Internship, pk=data[OPENING_ID]) + else: + opening = get_object_or_404(Placement, pk=data[OPENING_ID]) opening.email_verified = True if data[EMAIL_VERIFIED] == "true" else False opening.changed_by = get_object_or_404(User, id=id) opening.save() @@ -161,7 +210,14 @@ def updateEmailVerified(request, id, email, user_type): def deleteAdditionalInfo(request, id, email, user_type): try: data = request.data - opening = get_object_or_404(Placement, pk=data[OPENING_ID]) + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] + else: + opening_type= "Placement" + if opening_type == "Internship": + opening = get_object_or_404(Internship, pk=data[OPENING_ID]) + else: + opening = get_object_or_404(Placement, pk=data[OPENING_ID]) if data[FIELD] in opening.additional_info: opening.additional_info.remove(data[FIELD]) opening.changed_by = get_object_or_404(User, id=id) @@ -188,7 +244,14 @@ def deleteAdditionalInfo(request, id, email, user_type): def addAdditionalInfo(request, id, email, user_type): try: data = request.data - opening = get_object_or_404(Placement, pk=data[OPENING_ID]) + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] + else: + opening_type= "Placement" + if opening_type == "Internship": + opening = get_object_or_404(Internship, pk=data[OPENING_ID]) + else: + opening = get_object_or_404(Placement, pk=data[OPENING_ID]) if data[FIELD] not in opening.additional_info: opening.additional_info.append(data[FIELD]) opening.save() @@ -215,11 +278,20 @@ def addAdditionalInfo(request, id, email, user_type): def getApplications(request, id, email, user_type): try: data = request.GET - opening = get_object_or_404(Placement, pk=data[OPENING_ID]) - applications = PlacementApplication.objects.filter(placement=opening) - serializer = PlacementApplicationSerializerForAdmin(applications, many=True) + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] + else: + opening_type= "Placement" + if opening_type == "Internship": + opening = get_object_or_404(Internship, pk=data[OPENING_ID]) + applications = InternshipApplication.objects.filter(internship=opening) + serializer = InternshipApplicationSerializerForAdmin(applications, many=True) + else: + opening = get_object_or_404(Placement, pk=data[OPENING_ID]) + applications = PlacementApplication.objects.filter(placement=opening) + serializer = PlacementApplicationSerializerForAdmin(applications, many=True) return Response({'action': "Get Applications", 'message': 'Data Found', 'applications': serializer.data}, - status=status.HTTP_200_OK) + status=status.HTTP_200_OK) except Http404: return Response({'action': "Get Applications", 'message': 'Opening Not Found'}, status=status.HTTP_404_NOT_FOUND) @@ -235,68 +307,136 @@ def getApplications(request, id, email, user_type): def submitApplication(request, id, email, user_type): try: data = request.data - student = get_object_or_404(Student, pk=data[STUDENT_ID]) - opening = get_object_or_404(Placement, pk=data[OPENING_ID]) - student_user = get_object_or_404(User, id=student.id) - if data[APPLICATION_ID] == "": - application = PlacementApplication() - application.id = generateRandomString() - application.placement = opening - application.student = student - if data[RESUME_FILE_NAME] in student.resumes: - application.resume = data[RESUME_FILE_NAME] - else: - raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") - additional_info = {} - for i in opening.additional_info: - if i not in data[ADDITIONAL_INFO]: - raise AttributeError(i + " not found in Additional Info") - else: - additional_info[i] = data[ADDITIONAL_INFO][i] - application.additional_info = json.dumps(additional_info) - data = { - "name": student.name, - "company_name": opening.company_name, - "application_type": "Placement", - "additional_info": dict(json.loads(application.additional_info)), - } - subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) - application.changed_by = get_object_or_404(User, id=id) - application.save() - sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE) - return Response({'action': "Add Student Application", 'message': "Application added"}, - status=status.HTTP_200_OK) + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] else: - application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID]) - if application: + opening_type= "Placement" + student = get_object_or_404(Student, pk=data[STUDENT_ID]) + if opening_type == "Internship": + opening = get_object_or_404(Internship, pk=data[OPENING_ID]) + student_user = get_object_or_404(User, id=student.id) + if data[APPLICATION_ID] == "": + application = InternshipApplication() + application.id = generateRandomString() + application.internship = opening + application.student = student if data[RESUME_FILE_NAME] in student.resumes: application.resume = data[RESUME_FILE_NAME] else: raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") - application.resume = data[RESUME_FILE_NAME] additional_info = {} for i in opening.additional_info: if i not in data[ADDITIONAL_INFO]: raise AttributeError(i + " not found in Additional Info") else: additional_info[i] = data[ADDITIONAL_INFO][i] + application.additional_info = json.dumps(additional_info) + data = { + "name": student.name, + "company_name": opening.company_name, + "application_type": "Internship", + "additional_info": dict(json.loads(application.additional_info)), + } + subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) + application.changed_by = get_object_or_404(User, id=id) + application.save() + sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE) + return Response({'action': "Add Student Application", 'message': "Application added For Internship"}, + status=status.HTTP_200_OK) + else: + application = get_object_or_404(InternshipApplication, id=data[APPLICATION_ID]) + if application: + if data[RESUME_FILE_NAME] in student.resumes: + application.resume = data[RESUME_FILE_NAME] + else: + raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") + application.resume = data[RESUME_FILE_NAME] + additional_info = {} + for i in opening.additional_info: + if i not in data[ADDITIONAL_INFO]: + raise AttributeError(i + " not found in Additional Info") + else: + additional_info[i] = data[ADDITIONAL_INFO][i] + application.additional_info = json.dumps(additional_info) + data = { + "name": student.name, + "company_name": opening.company_name, + "application_type": "Internship", + "resume": application.resume[16:], + "additional_info_items": dict(json.loads(application.additional_info)), + } + subject = STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) + application.changed_by = get_object_or_404(User, id=id) + application.save() + sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_UPDATED_TEMPLATE) + return Response({'action': "Add Student Application", 'message': "Application updated For Internship"}, + status=status.HTTP_200_OK) + else: + return Response({'action': "Edit Student Application", 'message': "No Application Found For Internship"}, + status=status.HTTP_400_BAD_REQUEST) + else: + opening = get_object_or_404(Placement, pk=data[OPENING_ID]) + student_user = get_object_or_404(User, id=student.id) + if data[APPLICATION_ID] == "": + application = PlacementApplication() + application.id = generateRandomString() + application.placement = opening + application.student = student + if data[RESUME_FILE_NAME] in student.resumes: + application.resume = data[RESUME_FILE_NAME] + else: + raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") + additional_info = {} + for i in opening.additional_info: + if i not in data[ADDITIONAL_INFO]: + raise AttributeError(i + " not found in Additional Info") + else: + additional_info[i] = data[ADDITIONAL_INFO][i] application.additional_info = json.dumps(additional_info) data = { "name": student.name, "company_name": opening.company_name, "application_type": "Placement", - "resume": application.resume[16:], - "additional_info_items": dict(json.loads(application.additional_info)), + "additional_info": dict(json.loads(application.additional_info)), } - subject = STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) + subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) application.changed_by = get_object_or_404(User, id=id) application.save() - sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_UPDATED_TEMPLATE) - return Response({'action': "Add Student Application", 'message': "Application updated"}, - status=status.HTTP_200_OK) + sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE) + return Response({'action': "Add Student Application", 'message': "Application added"}, + status=status.HTTP_200_OK) else: - return Response({'action': "Edit Student Application", 'message': "No Application Found"}, + application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID]) + if application: + if data[RESUME_FILE_NAME] in student.resumes: + application.resume = data[RESUME_FILE_NAME] + else: + raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") + application.resume = data[RESUME_FILE_NAME] + additional_info = {} + for i in opening.additional_info: + if i not in data[ADDITIONAL_INFO]: + raise AttributeError(i + " not found in Additional Info") + else: + additional_info[i] = data[ADDITIONAL_INFO][i] + + application.additional_info = json.dumps(additional_info) + data = { + "name": student.name, + "company_name": opening.company_name, + "application_type": "Placement", + "resume": application.resume[16:], + "additional_info_items": dict(json.loads(application.additional_info)), + } + subject = STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) + application.changed_by = get_object_or_404(User, id=id) + application.save() + sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_UPDATED_TEMPLATE) + return Response({'action': "Add Student Application", 'message': "Application updated"}, + status=status.HTTP_200_OK) + else: + return Response({'action': "Edit Student Application", 'message': "No Application Found"}, status=status.HTTP_400_BAD_REQUEST) except Http404 as e: @@ -320,8 +460,16 @@ def submitApplication(request, id, email, user_type): def generateCSV(request, id, email, user_type): try: data = request.data - placement = get_object_or_404(Placement, id=data[OPENING_ID]) - applications = PlacementApplication.objects.filter(placement=placement) + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] + else: + opening_type= "Placement" + if opening_type == "Internship": + opening = get_object_or_404(Internship, id=data[OPENING_ID]) + applications = InternshipApplication.objects.filter(internship=opening) + else: + opening = get_object_or_404(Placement, id=data[OPENING_ID]) + applications = PlacementApplication.objects.filter(placement=opening) filename = generateRandomString() if not os.path.isdir(STORAGE_DESTINATION_APPLICATION_CSV): os.mkdir(STORAGE_DESTINATION_APPLICATION_CSV) @@ -330,7 +478,7 @@ def generateCSV(request, id, email, user_type): writer = csv.writer(f) header_row = APPLICATION_CSV_COL_NAMES.copy() - header_row.extend(placement.additional_info) + header_row.extend(opening.additional_info) writer.writerow(header_row) for apl in applications: row_details = [] @@ -347,7 +495,7 @@ def generateCSV(request, id, email, user_type): row_details.append(link) row_details.append(apl.selected) - for i in placement.additional_info: + for i in opening.additional_info: row_details.append(json.loads(apl.additional_info)[i]) writer.writerow(row_details) @@ -397,6 +545,10 @@ def addPPO(request, id, email, user_type): def getStudentApplication(request, id, email, user_type): try: data = request.data + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] + else: + opening_type= "Placement" student = get_object_or_404(Student, id=data[STUDENT_ID]) student_serializer = StudentSerializer(student) student_details = { @@ -406,15 +558,29 @@ def getStudentApplication(request, id, email, user_type): "resume_list": student_serializer.data['resume_list'], } # search for the application if there or not - application = PlacementApplication.objects.filter(student=student, + if opening_type == "Internship": + application = InternshipApplication.objects.filter(student=student, + internship=get_object_or_404(Internship, + id=data[OPENING_ID])) + else: + application = PlacementApplication.objects.filter(student=student, placement=get_object_or_404(Placement, id=data[OPENING_ID])) + if application: - serializer = PlacementApplicationSerializer(application[0]) - application_info = { - "id": serializer.data['id'], - "additional_info": serializer.data['additional_info'], - "resume": serializer.data['resume_link'], - } + if opening_type == "Internship": + serializer = InternshipApplicationSerializer(application[0]) + application_info = { + "id": serializer.data['id'], + "additional_info": serializer.data['additional_info'], + "resume": serializer.data['resume_link'], + } + else: + serializer = PlacementApplicationSerializer(application[0]) + application_info = { + "id": serializer.data['id'], + "additional_info": serializer.data['additional_info'], + "resume": serializer.data['resume_link'], + } return Response( {'action': "Get Student Application", 'application_found': "true", "application_info": application_info, "student_details": student_details}, status=status.HTTP_200_OK) diff --git a/CDC_Backend/APIs/companyViews.py b/CDC_Backend/APIs/companyViews.py index bfc9ecc..67fad0b 100644 --- a/CDC_Backend/APIs/companyViews.py +++ b/CDC_Backend/APIs/companyViews.py @@ -321,6 +321,24 @@ def autoFillJnf(request): return Response({'action': "Get AutoFill", 'message': "Something went wrong"}, status=status.HTTP_400_BAD_REQUEST) +@api_view(['GET']) +@precheck([PLACEMENT_ID]) +def autoFillInf(request): + try: + data = request.GET + internship_id = data.get(INTERNSHIP_ID) + opening = get_object_or_404(Internship, id=internship_id) + serializer = AutofillSerializersInternship(opening) + return Response({'action': "Get AutoFill ", 'message': 'Data Found', 'internship_data': serializer.data}, + status=status.HTTP_200_OK) + except Http404: + return Response({'action': "Get AutoFill", 'message': 'Internship Not Found'}, + status=status.HTTP_404_NOT_FOUND) + except Exception as e: + traceback_str = traceback.format_exc() + logger.warning("Get AutoFill: " + traceback_str) + return Response({'action': "Get AutoFill", 'message': "Something went wrong"}, + status=status.HTTP_400_BAD_REQUEST) ## Internships ## @@ -397,6 +415,14 @@ def addInternship(request): internship.is_work_from_home = True else: internship.is_work_from_home = False + + if data[ALLOWED_BATCH] is None or json.loads(data[ALLOWED_BATCH]) == "": + raise ValueError('Allowed Branch cannot be empty') + elif set(json.loads(data[ALLOWED_BATCH])).issubset(BATCHES): + internship.allowed_batch = json.loads(data[ALLOWED_BATCH]) + else: + raise ValueError('Allowed Batch must be a subset of ' + str(BATCHES)) + if data[ALLOWED_BRANCH] is None or json.loads(data[ALLOWED_BRANCH]) == "": raise ValueError('Allowed Branch cannot be empty') elif set(json.loads(data[ALLOWED_BRANCH])).issubset(BRANCHES): @@ -468,6 +494,11 @@ def addInternship(request): internship.selection_procedure_details_pdf_names = selection_procedure_details_pdf internship.additional_facilities = data[OTHER_FACILITIES] + #add additional info + # Only Allowing Fourth Year for Placement + + + internship.academic_requirements = data[OTHER_REQUIREMENTS] diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index 92d869e..0c8e21a 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -21,6 +21,12 @@ BRANCHES = [ "CHEMICAL", "BSMS", ] +BATCHES = [ #change it accordingly + "2023", + "2022", + "2021", + "2020", +] BATCH_CHOICES = [ ["2022", "2022"], ["2021", "2021"], @@ -218,6 +224,7 @@ STIPEND = 'stipend' FACILITIES = 'facilities' OTHER_FACILITIES = 'other_facilities' STIPEND_DETAILS_PDF = 'compensation_details_pdf' +STIPEND_DETAILS_PDF_NAMES = 'stipend_description_pdf_names' SEASONS = ( 'Summer', diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py index 75867a8..f5dbc57 100644 --- a/CDC_Backend/APIs/models.py +++ b/CDC_Backend/APIs/models.py @@ -32,6 +32,7 @@ class Student(models.Model): default=list, blank=True) cpi = models.DecimalField(decimal_places=2, max_digits=4) can_apply = models.BooleanField(default=True, verbose_name='Registered') + can_apply_internship = models.BooleanField(default=True, verbose_name='Internship Registered') #added for internship changed_by = models.ForeignKey(User, blank=True, on_delete=models.RESTRICT, default=None, null=True) degree = models.CharField(choices=DEGREE_CHOICES, blank=False, max_length=10, default=DEGREE_CHOICES[0][0]) history = HistoricalRecords(user_model=User) @@ -318,6 +319,11 @@ class Internship(models.Model): size=TOTAL_BRANCHES, default=list ) + allowed_batch = ArrayField( + models.CharField(max_length=10, choices=BATCH_CHOICES), + size=TOTAL_BATCHES, + default=list + ) sophomore_eligible = models.BooleanField(blank=False, default=False) rs_eligible = models.BooleanField(blank=False, default=False) tentative_no_of_offers = models.IntegerField(blank=False, default=None, null=True) @@ -332,6 +338,11 @@ class Internship(models.Model): default=list, blank=True ) + additional_info = ArrayField(models.CharField(blank=True, max_length=JNF_TEXTMEDIUM_MAX_CHARACTER_COUNT), size=15, + default=list, blank=True) + offer_accepted = models.BooleanField(blank=False, default=None, null=True) + deadline_datetime = models.DateTimeField(blank=False, verbose_name="Deadline Date", default=two_day_after_today) + additional_facilities = models.CharField(blank=True, max_length=JNF_TEXTAREA_MAX_CHARACTER_COUNT, default=None, null=True) academic_requirements = models.CharField(blank=True, max_length=JNF_TEXTAREA_MAX_CHARACTER_COUNT, default=None, null=True) # selection process @@ -388,6 +399,9 @@ class Internship(models.Model): self.additional_facilities = self.additional_facilities.strip()[:JNF_TEXTAREA_MAX_CHARACTER_COUNT] if self.academic_requirements is not None: self.academic_requirements = self.academic_requirements.strip()[:JNF_TEXTAREA_MAX_CHARACTER_COUNT] + if self.additional_info is not None: + self.additional_info = [info.strip()[:JNF_TEXTMEDIUM_MAX_CHARACTER_COUNT] for info in + list(self.additional_info)] # if self.contact_person_designation is not None: # self.contact_person_designation = self.contact_person_designation.strip()[:JNF_SMALLTEXT_MAX_CHARACTER_COUNT] diff --git a/CDC_Backend/APIs/serializers.py b/CDC_Backend/APIs/serializers.py index 19d94bc..39750df 100644 --- a/CDC_Backend/APIs/serializers.py +++ b/CDC_Backend/APIs/serializers.py @@ -99,6 +99,59 @@ class PlacementSerializerForStudent(serializers.ModelSerializer): ] depth = 1 +class InternshipSerializerForStudent(serializers.ModelSerializer): + company_details_pdf_links = serializers.SerializerMethodField() + description_pdf_links = serializers.SerializerMethodField() + compensation_pdf_links = serializers.SerializerMethodField() + selection_procedure_details_pdf_links = serializers.SerializerMethodField() + + def get_company_details_pdf_links(self, obj): + links = [] + for pdf_name in obj.company_details_pdf_names: + ele = {} + link = LINK_TO_STORAGE_COMPANY_ATTACHMENT + urllib.parse.quote(obj.id + "/" + pdf_name) + ele['link'] = link + ele['name'] = pdf_name + links.append(ele) + return links + + def get_description_pdf_links(self, obj): + links = [] + for pdf_name in obj.description_pdf_names: + ele = {} + link = LINK_TO_STORAGE_COMPANY_ATTACHMENT + urllib.parse.quote(obj.id + "/" + pdf_name) + ele['link'] = link + ele['name'] = pdf_name + links.append(ele) + return links + def get_compensation_pdf_links(self, obj): + links = [] + for pdf_name in obj.stipend_description_pdf_names: + ele = {} + link = LINK_TO_STORAGE_COMPANY_ATTACHMENT + urllib.parse.quote(obj.id + "/" + pdf_name) + ele['link'] = link + ele['name'] = pdf_name + links.append(ele) + return links + + def get_selection_procedure_details_pdf_links(self, obj): + links = [] + for pdf_name in obj.selection_procedure_details_pdf_names: + ele = {} + link = LINK_TO_STORAGE_COMPANY_ATTACHMENT + urllib.parse.quote(obj.id + "/" + pdf_name) + ele['link'] = link + ele['name'] = pdf_name + links.append(ele) + return links + + class Meta: + model = Internship + exclude = [CONTACT_PERSON_NAME, PHONE_NUMBER, EMAIL, COMPANY_DETAILS_PDF_NAMES, DESCRIPTION_PDF_NAMES, + STIPEND_DETAILS_PDF_NAMES, SELECTION_PROCEDURE_DETAILS_PDF_NAMES, OFFER_ACCEPTED, + EMAIL_VERIFIED, + ] + depth = 1 + class PlacementSerializerForAdmin(serializers.ModelSerializer): company_details_pdf_links = serializers.SerializerMethodField() @@ -152,6 +205,58 @@ class PlacementSerializerForAdmin(serializers.ModelSerializer): COMPENSATION_DETAILS_PDF_NAMES, SELECTION_PROCEDURE_DETAILS_PDF_NAMES] depth = 1 +class InternshipSerializerForAdmin(serializers.ModelSerializer): + company_details_pdf_links = serializers.SerializerMethodField() + description_pdf_links = serializers.SerializerMethodField() + compensation_pdf_links = serializers.SerializerMethodField() + selection_procedure_details_pdf_links = serializers.SerializerMethodField() + + def get_company_details_pdf_links(self, obj): + links = [] + for pdf_name in obj.company_details_pdf_names: + ele = {} + link = LINK_TO_STORAGE_COMPANY_ATTACHMENT + urllib.parse.quote(obj.id + "/" + pdf_name) + ele['link'] = link + ele['name'] = pdf_name + links.append(ele) + return links + + def get_description_pdf_links(self, obj): + links = [] + for pdf_name in obj.description_pdf_names: + ele = {} + link = LINK_TO_STORAGE_COMPANY_ATTACHMENT + urllib.parse.quote(obj.id + "/" + pdf_name) + ele['link'] = link + ele['name'] = pdf_name + links.append(ele) + return links + + def get_compensation_pdf_links(self, obj): + links = [] + for pdf_name in obj.stipend_description_pdf_names: + ele = {} + link = LINK_TO_STORAGE_COMPANY_ATTACHMENT + urllib.parse.quote(obj.id + "/" + pdf_name) + ele['link'] = link + ele['name'] = pdf_name + links.append(ele) + return links + + def get_selection_procedure_details_pdf_links(self, obj): + links = [] + for pdf_name in obj.selection_procedure_details_pdf_names: + ele = {} + link = LINK_TO_STORAGE_COMPANY_ATTACHMENT + urllib.parse.quote(obj.id + "/" + pdf_name) + ele['link'] = link + ele['name'] = pdf_name + links.append(ele) + return links + + class Meta: + model = Internship + exclude = [COMPANY_DETAILS_PDF_NAMES, DESCRIPTION_PDF_NAMES, SELECTION_PROCEDURE_DETAILS_PDF_NAMES, + STIPEND_DETAILS_PDF_NAMES] + depth = 1 + class PlacementApplicationSerializer(serializers.ModelSerializer): placement = serializers.SerializerMethodField() @@ -168,6 +273,21 @@ class PlacementApplicationSerializer(serializers.ModelSerializer): class Meta: model = PlacementApplication exclude = [STUDENT, 'resume'] +class InternshipApplicationSerializer(serializers.ModelSerializer): + internship = serializers.SerializerMethodField() + resume_link = serializers.SerializerMethodField() + + def get_internship(self, obj): + data = InternshipSerializerForStudent(obj.internship).data + return data + + def get_resume_link(self, obj): + ele = {'link': LINK_TO_STORAGE_RESUME + urllib.parse.quote(str(obj.student.roll_no) + "/" + obj.resume), 'name': obj.resume} + return ele + + class Meta: + model = InternshipApplication + exclude = [STUDENT, 'resume'] class PlacementApplicationSerializerForAdmin(serializers.ModelSerializer): @@ -186,6 +306,22 @@ class PlacementApplicationSerializerForAdmin(serializers.ModelSerializer): model = PlacementApplication exclude = ['placement', 'resume'] +class InternshipApplicationSerializerForAdmin(serializers.ModelSerializer): + student_details = serializers.SerializerMethodField() + resume_link = serializers.SerializerMethodField() + + def get_student_details(self, obj): + data = StudentSerializer(obj.student).data + return data + + def get_resume_link(self, obj): + ele = {'link': LINK_TO_STORAGE_RESUME + urllib.parse.quote(obj.id + "/" + obj.resume), 'name': obj.resume} + return ele + + class Meta: + model = InternshipApplication + exclude = ['internship', 'resume'] + class ContributorSerializer(serializers.ModelSerializer): class Meta: model = Contributor @@ -195,4 +331,9 @@ class ContributorSerializer(serializers.ModelSerializer): class AutofillSerializers(serializers.ModelSerializer): class Meta: model = Placement + fields = '__all__' + +class AutofillSerializersInternship(serializers.ModelSerializer): + class Meta: + model = Internship fields = '__all__' \ No newline at end of file diff --git a/CDC_Backend/APIs/studentUrls.py b/CDC_Backend/APIs/studentUrls.py index f9dee52..07c4710 100644 --- a/CDC_Backend/APIs/studentUrls.py +++ b/CDC_Backend/APIs/studentUrls.py @@ -3,13 +3,14 @@ from django.urls import path from . import studentViews urlpatterns = [ - path('login/', studentViews.login, name="Login"), - path('profile/', studentViews.studentProfile, name="Student Profile"), - path('getDashboard/', studentViews.getDashboard, name="Dashboard"), - path("addResume/", studentViews.addResume, name="Upload Resume"), - path("deleteResume/", studentViews.deleteResume, name="Upload Resume"), - path("submitApplication/", studentViews.submitApplication, name="Submit Application"), - path("deleteApplication/", studentViews.deleteApplication, name="Delete Application"), + path('login/', studentViews.login, name="Login"), #done for intern + path('profile/', studentViews.studentProfile, name="Student Profile"), #done for intern + path('getDashboard/', studentViews.getDashboard, name="Dashboard"), # customised dashboard.. check are we checking registedred check allowed branch/batches filter in + path("addResume/", studentViews.addResume, name="Upload Resume"), #done for intern + path("deleteResume/", studentViews.deleteResume, name="Upload Resume"),#done for intern + path("submitApplication/", studentViews.submitApplication, name="Submit Application"), #done for intern + path("deleteApplication/", studentViews.deleteApplication, name="Delete Application"), #done for intern check for opening type data in headers path("getContributorStats/", studentViews.getContributorStats, name="Get Contributor Stats"), - path("studentAcceptOffer/", studentViews.studentAcceptOffer, name="Student Accept Offer"), + path("studentAcceptOffer/", studentViews.studentAcceptOffer, name="Student Accept Offer"), #same as above check header ] +#store all files.. \ No newline at end of file diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index 62d36b4..a9fb2aa 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -48,6 +48,7 @@ def refresh(request): @isAuthorized(allowed_users=[STUDENT]) def studentProfile(request, id, email, user_type): try: + print(id) studentDetails = get_object_or_404(Student, id=id) data = StudentSerializer(studentDetails).data @@ -110,9 +111,20 @@ def getDashboard(request, id, email, user_type): placementApplications = PlacementApplication.objects.filter(student_id=id) placementApplications = PlacementApplicationSerializer(placementApplications, many=True).data + internships = Internship.objects.filter(allowed_batch__contains=[studentDetails.batch], + allowed_branch__contains=[studentDetails.branch], + deadline_datetime__gte=datetime.datetime.now(), + offer_accepted=True, email_verified=True).order_by('deadline_datetime') + + filtered_internships = internship_eligibility_filters(studentDetails, internships) + print(len(filtered_internships)) + internshipsdata = InternshipSerializerForStudent(filtered_internships, many=True).data + + internshipApplications = InternshipApplication.objects.filter(student_id=id) + internshipApplications = InternshipApplicationSerializer(internshipApplications, many=True).data return Response( {'action': "Get Dashboard - Student", 'message': "Data Found", "placements": placementsdata, - 'placementApplication': placementApplications}, + 'placementApplication': placementApplications, 'internships':internshipsdata,'internshipApplication':internshipApplications}, status=status.HTTP_200_OK) except Http404: return Response({'action': "Get Dashboard - Student", 'message': 'Student Not Found'}, @@ -163,13 +175,14 @@ def deleteResume(request, id, email, user_type): ]) def submitApplication(request, id, email, user_type): try: - data = request.data + data = request.data student = get_object_or_404(Student, id=id) - if not student.can_apply: - return Response({'action': "Submit Application", 'message': "Student Can't Apply"}, - status=status.HTTP_400_BAD_REQUEST) + # Only Allowing Applications for Placements if data[OPENING_TYPE] == PLACEMENT: + if not student.can_apply: #why not checking in admin + return Response({'action': "Submit Application", 'message': "Student Can't Apply"}, + status=status.HTTP_400_BAD_REQUEST) if not len(PlacementApplication.objects.filter( student_id=id, placement_id=data[OPENING_ID])): application = PlacementApplication() @@ -187,6 +200,27 @@ def submitApplication(request, id, email, user_type): application.placement = opening else: raise PermissionError("Application is already Submitted") + elif data[OPENING_TYPE] == INTERNSHIP: + if not student.can_apply_internship: + return Response({'action': "Submit Application", 'message': "Student Can't Apply Internship"}, + status=status.HTTP_400_BAD_REQUEST) + if not len(InternshipApplication.objects.filter( + student_id=id, internship_id=data[OPENING_ID])): + application = InternshipApplication() + opening = get_object_or_404(Internship, id=data[OPENING_ID], + allowed_batch__contains=[student.batch], + allowed_branch__contains=[student.branch], + deadline_datetime__gte=datetime.datetime.now().date() + ) + if not opening.offer_accepted or not opening.email_verified: + raise PermissionError("Internship Not Approved") + + cond_stat, cond_msg = InternshipApplicationConditions(student, opening) + if not cond_stat: + raise PermissionError(cond_msg) + application.internship = opening + else: + raise PermissionError("Application is already Submitted") else: raise ValueError(OPENING_TYPE + " is Invalid") @@ -239,10 +273,22 @@ def submitApplication(request, id, email, user_type): def deleteApplication(request, id, email, user_type): try: data = request.data - application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID], + if OPENING_TYPE in request.data: + opening_type = request.data[OPENING_TYPE] + else: + opening_type = PLACEMENT + if opening_type==INTERNSHIP: #check whether it has header or not + application = get_object_or_404(InternshipApplication, id=data[APPLICATION_ID], student_id=id) - if application.placement.deadline_datetime < timezone.now(): - raise PermissionError("Deadline Passed") + if application.internship.deadline_datetime < timezone.now(): + raise PermissionError("Deadline Passed") + else: + application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID], + student_id=id) + if application.placement.deadline_datetime < timezone.now(): + raise PermissionError("Deadline Passed") + + application.delete() return Response({'action': "Delete Application", 'message': "Application Deleted"}, @@ -283,9 +329,17 @@ def studentAcceptOffer(request, id, email, user_type): company_id = request.data['id'] student_id=request.data['profileInfo']['id'] offer_status = request.data['offerStatus'] - placement_application=PlacementApplication.objects.get(placement=company_id,student=student_id) - placement_application.offer_accepted=offer_status - placement_application.save() + if OPENING_TYPE in request.data: + opening_type = request.data[OPENING_TYPE] + else: + opening_type = PLACEMENT + if opening_type==INTERNSHIP: + application=InternshipApplication.objects.get(internship=company_id,student=student_id) #check syntax + else: + application=PlacementApplication.objects.get(placement=company_id,student=student_id) + + application.offer_accepted=offer_status + application.save() return Response({'action': "Accept Offer", 'message': "Updated Offer Status"}, status=status.HTTP_200_OK) except: diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index cd864d0..53d29a6 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -28,7 +28,7 @@ from rest_framework import status from rest_framework.response import Response from .constants import * -from .models import User, PrePlacementOffer, PlacementApplication, Placement, Student, Internship +from .models import User, PrePlacementOffer, PlacementApplication, Placement, Student, Internship,InternshipApplication logger = logging.getLogger('db') @@ -112,10 +112,12 @@ def isAuthorized(allowed_users=None): def wrapper_func(request, *args, **kwargs): try: headers = request.META + #print(headers) if 'HTTP_AUTHORIZATION' in headers: token_id = headers['HTTP_AUTHORIZATION'][7:] idinfo = id_token.verify_oauth2_token(token_id, requests.Request(), CLIENT_ID) email = idinfo[EMAIL] + # print(idinfo) user = get_object_or_404(User, email=email) if user: user.last_login_time = timezone.now() @@ -167,6 +169,8 @@ def saveFile(file, location): file_name = re.sub(r'[\\/:*?"<>|]', '_', file_name) + # print("Inside saveFile: " + str(file_name)) + if not path.isdir(location): os.makedirs(location) @@ -194,7 +198,7 @@ def sendEmail(email_to, subject, data, template, attachment_jnf_response=None): else: recipient_list = [str(email_to), ] - msg = EmailMultiAlternatives(subject, text_content, email_from, recipient_list) + msg = EmailMultiAlternatives(subject, text_content, email_from,"uttamthummala@gmail.com",bcc=recipient_list) msg.attach_alternative(html_content, "text/html") if attachment_jnf_response: # logger.info(attachment_jnf_response) @@ -246,6 +250,20 @@ def PlacementApplicationConditions(student, placement): logger.warning("Utils - PlacementApplicationConditions: " + str(sys.exc_info())) return False, "_" +def InternshipApplicationConditions(student, internship): + try: + selected_companies = InternshipApplication.objects.filter(student=student, selected=True) + if len(selected_companies)>=1: + print("selected companies > 1") + return False, "You have already secured a Internship" + return True, "Conditions Satisfied" + + except PermissionError as e: + return False, e + except: + logger.warning("Utils - InternshipApplicationConditions: " + str(sys.exc_info())) + return False, "_" + def getTier(compensation_gross, is_psu=False): try: @@ -370,12 +388,27 @@ def placement_eligibility_filters(student, placements): except: logger.warning("Utils - placement_eligibility_filters: " + str(sys.exc_info())) return placements +def internship_eligibility_filters(student, internships): + try: + filtered_internships = [] + for internship in internships.iterator(): + + if InternshipApplicationConditions(student, internship)[0]: + filtered_internships.append(internship) + else: + print("Not applicable") + + return filtered_internships + except: + logger.warning("Utils - internship_eligibility_filters: " + str(sys.exc_info())) + return internships @background_task.background(schedule=2) def send_opening_notifications(placement_id): try: placement = get_object_or_404(Placement, id=placement_id) + emails=[] students = Student.objects.all() for student in students.iterator(): if student.branch in placement.allowed_branch: @@ -393,12 +426,13 @@ def send_opening_notifications(placement_id): "deadline": deadline_datetime.strftime("%A, %-d %B %Y, %-I:%M %p"), "link": PLACEMENT_OPENING_URL.format(id=placement.designation) } - sendEmail(student_user.email, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE) + emails.append(student_user.email) + #sendEmail(student_user.email, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE) except Http404: logger.warning('Utils - send_opening_notifications: user not found : ' + student.id) except Exception as e: logger.warning('Utils - send_opening_notifications: For Loop' + str(e)) - + sendEmail(emails, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE) #handled multiple mailings except: logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info())) return False diff --git a/setup.sh b/setup.sh old mode 100644 new mode 100755 index aaa20b9..1ba33a4 --- a/setup.sh +++ b/setup.sh @@ -3,7 +3,7 @@ echo "Environment setup complete" cd CDC_Backend python3 manage.py flush --no-input -python3 manage.py makemigrations +python3 manage.py makemigrations APIs python3 manage.py migrate echo "Migrations complete" From 5d0f9fba5866d139cd451439cba23f2ad82b92d3 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Tue, 3 Oct 2023 01:55:18 +0530 Subject: [PATCH 02/38] fixed mailer --- CDC_Backend/APIs/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index 53d29a6..a715380 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -198,7 +198,7 @@ def sendEmail(email_to, subject, data, template, attachment_jnf_response=None): else: recipient_list = [str(email_to), ] - msg = EmailMultiAlternatives(subject, text_content, email_from,"uttamthummala@gmail.com",bcc=recipient_list) + msg = EmailMultiAlternatives(subject, text_content, email_from,"irontwist00@gmail.com",bcc=recipient_list) msg.attach_alternative(html_content, "text/html") if attachment_jnf_response: # logger.info(attachment_jnf_response) From ed6f313b68da2ed642eb4f6cfa0d55a560578f5f Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Tue, 3 Oct 2023 02:16:33 +0530 Subject: [PATCH 03/38] fixed notifications --- CDC_Backend/APIs/adminViews.py | 2 +- CDC_Backend/APIs/utils.py | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index a834b01..9da035f 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -158,7 +158,7 @@ def updateOfferAccepted(request, id, email, user_type): opening.changed_by = get_object_or_404(User, id=id) opening.save() if opening.offer_accepted: - send_opening_notifications(opening.id) + send_opening_notifications(opening.id,opening_type) else: raise ValueError("Offer Status already updated") diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index a715380..f6a8dee 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -405,26 +405,29 @@ def internship_eligibility_filters(student, internships): @background_task.background(schedule=2) -def send_opening_notifications(placement_id): +def send_opening_notifications(opening_id, opening_type): try: - placement = get_object_or_404(Placement, id=placement_id) + if opening_type == PLACEMENT: + opening = get_object_or_404(Placement, id=opening_id) + else: + opening = get_object_or_404(Internship, id=opening_id) emails=[] students = Student.objects.all() for student in students.iterator(): - if student.branch in placement.allowed_branch: - if student.degree == 'bTech' or placement.rs_eligible is True: - if PlacementApplicationConditions(student, placement)[0]: + if student.branch in opening.allowed_branch: + if student.degree == 'bTech' or opening.rs_eligible is True: + if (isinstance(opening,Placement) and PlacementApplicationConditions(student, opening)[0]) or (isinstance(opening,Internship) and InternshipApplicationConditions(student, opening)[0]): try: student_user = get_object_or_404(User, id=student.id) subject = NOTIFY_STUDENTS_OPENING_TEMPLATE_SUBJECT.format( - company_name=placement.company_name) - deadline_datetime = placement.deadline_datetime.astimezone(pytz.timezone('Asia/Kolkata')) + company_name=opening.company_name) + deadline_datetime = opening.deadline_datetime.astimezone(pytz.timezone('Asia/Kolkata')) data = { - "company_name": placement.company_name, - "opening_type": 'Placement', - "designation": placement.designation, + "company_name": opening.company_name, + "opening_type": "INTERNSHIP" if isinstance(opening, Internship) else "PLACEMENT", + "designation": opening.designation, "deadline": deadline_datetime.strftime("%A, %-d %B %Y, %-I:%M %p"), - "link": PLACEMENT_OPENING_URL.format(id=placement.designation) + "link": PLACEMENT_OPENING_URL.format(id=opening.designation) } emails.append(student_user.email) #sendEmail(student_user.email, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE) @@ -432,6 +435,7 @@ def send_opening_notifications(placement_id): logger.warning('Utils - send_opening_notifications: user not found : ' + student.id) except Exception as e: logger.warning('Utils - send_opening_notifications: For Loop' + str(e)) + sendEmail(emails, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE) #handled multiple mailings except: logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info())) @@ -442,7 +446,7 @@ def exception_email(opening): opening = opening.dict() data = { "designation": opening["designation"], - "opening_type": PLACEMENT, + "opening_type": "INTERNSHIP" if opening["opening_type"] == "INF" else "PLACEMENT", "company_name": opening["company_name"], } pdfhtml = opening_description_table_html(opening) From 7ccac2a2f2581fc62792d12176df6c640a7549d2 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Tue, 3 Oct 2023 02:35:33 +0530 Subject: [PATCH 04/38] consolidated code --- CDC_Backend/APIs/adminViews.py | 155 +++++++++++---------------------- 1 file changed, 50 insertions(+), 105 deletions(-) diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index 9da035f..b806275 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -307,136 +307,82 @@ def getApplications(request, id, email, user_type): def submitApplication(request, id, email, user_type): try: data = request.data - if OPENING_TYPE in data: + if OPENING_TYPE in data: opening_type= data[OPENING_TYPE] else: opening_type= "Placement" - student = get_object_or_404(Student, pk=data[STUDENT_ID]) if opening_type == "Internship": opening = get_object_or_404(Internship, pk=data[OPENING_ID]) - student_user = get_object_or_404(User, id=student.id) - if data[APPLICATION_ID] == "": - application = InternshipApplication() - application.id = generateRandomString() - application.internship = opening - application.student = student - if data[RESUME_FILE_NAME] in student.resumes: - application.resume = data[RESUME_FILE_NAME] - else: - raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") - additional_info = {} - for i in opening.additional_info: - if i not in data[ADDITIONAL_INFO]: - raise AttributeError(i + " not found in Additional Info") - else: - additional_info[i] = data[ADDITIONAL_INFO][i] - application.additional_info = json.dumps(additional_info) - data = { - "name": student.name, - "company_name": opening.company_name, - "application_type": "Internship", - "additional_info": dict(json.loads(application.additional_info)), - } - subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) - application.changed_by = get_object_or_404(User, id=id) - application.save() - sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE) - return Response({'action': "Add Student Application", 'message': "Application added For Internship"}, - status=status.HTTP_200_OK) - else: - application = get_object_or_404(InternshipApplication, id=data[APPLICATION_ID]) - if application: - if data[RESUME_FILE_NAME] in student.resumes: - application.resume = data[RESUME_FILE_NAME] - else: - raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") - application.resume = data[RESUME_FILE_NAME] - additional_info = {} - for i in opening.additional_info: - if i not in data[ADDITIONAL_INFO]: - raise AttributeError(i + " not found in Additional Info") - else: - additional_info[i] = data[ADDITIONAL_INFO][i] - - application.additional_info = json.dumps(additional_info) - data = { - "name": student.name, - "company_name": opening.company_name, - "application_type": "Internship", - "resume": application.resume[16:], - "additional_info_items": dict(json.loads(application.additional_info)), - } - subject = STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) - application.changed_by = get_object_or_404(User, id=id) - application.save() - sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_UPDATED_TEMPLATE) - return Response({'action': "Add Student Application", 'message': "Application updated For Internship"}, - status=status.HTTP_200_OK) - else: - return Response({'action': "Edit Student Application", 'message': "No Application Found For Internship"}, - status=status.HTTP_400_BAD_REQUEST) else: opening = get_object_or_404(Placement, pk=data[OPENING_ID]) - student_user = get_object_or_404(User, id=student.id) - if data[APPLICATION_ID] == "": - application = PlacementApplication() - application.id = generateRandomString() + student = get_object_or_404(Student, pk=data[STUDENT_ID]) + # opening = get_object_or_404(Placement, pk=data[OPENING_ID]) + student_user = get_object_or_404(User, id=student.id) + if data[APPLICATION_ID] == "": + application = PlacementApplication() if opening_type == "Placement" else InternshipApplication() + application.id = generateRandomString() + if(opening_type == "Placement"): application.placement = opening - application.student = student + else: + application.internship = opening + application.student = student + if data[RESUME_FILE_NAME] in student.resumes: + application.resume = data[RESUME_FILE_NAME] + else: + raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") + additional_info = {} + for i in opening.additional_info: + if i not in data[ADDITIONAL_INFO]: + raise AttributeError(i + " not found in Additional Info") + else: + additional_info[i] = data[ADDITIONAL_INFO][i] + application.additional_info = json.dumps(additional_info) + data = { + "name": student.name, + "company_name": opening.company_name, + "application_type": "Placement" if opening_type == "Placement" else "Internship", + "additional_info": dict(json.loads(application.additional_info)), + } + subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) + application.changed_by = get_object_or_404(User, id=id) + application.save() + sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE) + return Response({'action': "Add Student Application", 'message': "Application added"}, + status=status.HTTP_200_OK) + else: + if opening_type == "Internship": + application = get_object_or_404(InternshipApplication, id=data[APPLICATION_ID]) + else: + application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID]) + if application: if data[RESUME_FILE_NAME] in student.resumes: application.resume = data[RESUME_FILE_NAME] else: raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") + application.resume = data[RESUME_FILE_NAME] additional_info = {} for i in opening.additional_info: if i not in data[ADDITIONAL_INFO]: raise AttributeError(i + " not found in Additional Info") else: additional_info[i] = data[ADDITIONAL_INFO][i] + application.additional_info = json.dumps(additional_info) data = { "name": student.name, "company_name": opening.company_name, - "application_type": "Placement", - "additional_info": dict(json.loads(application.additional_info)), + "application_type": "Placement" if opening_type == "Placement" else "Internship", + "resume": application.resume[16:], + "additional_info_items": dict(json.loads(application.additional_info)), } - subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) + subject = STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) application.changed_by = get_object_or_404(User, id=id) application.save() - sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE) - return Response({'action': "Add Student Application", 'message': "Application added"}, - status=status.HTTP_200_OK) - else: - application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID]) - if application: - if data[RESUME_FILE_NAME] in student.resumes: - application.resume = data[RESUME_FILE_NAME] - else: - raise FileNotFoundError(RESUME_FILE_NAME + " Not Found") - application.resume = data[RESUME_FILE_NAME] - additional_info = {} - for i in opening.additional_info: - if i not in data[ADDITIONAL_INFO]: - raise AttributeError(i + " not found in Additional Info") - else: - additional_info[i] = data[ADDITIONAL_INFO][i] - - application.additional_info = json.dumps(additional_info) - data = { - "name": student.name, - "company_name": opening.company_name, - "application_type": "Placement", - "resume": application.resume[16:], - "additional_info_items": dict(json.loads(application.additional_info)), - } - subject = STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) - application.changed_by = get_object_or_404(User, id=id) - application.save() - sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_UPDATED_TEMPLATE) - return Response({'action': "Add Student Application", 'message': "Application updated"}, + sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_UPDATED_TEMPLATE) + return Response({'action': "Add Student Application", 'message': "Application updated"}, status=status.HTTP_200_OK) - else: - return Response({'action': "Edit Student Application", 'message': "No Application Found"}, + else: + return Response({'action': "Edit Student Application", 'message': "No Application Found"}, status=status.HTTP_400_BAD_REQUEST) except Http404 as e: @@ -453,7 +399,6 @@ def submitApplication(request, id, email, user_type): return Response({'action': "Submit Application", 'message': "Something Went Wrong"}, status=status.HTTP_400_BAD_REQUEST) - @api_view(['POST']) @isAuthorized(allowed_users=[ADMIN]) @precheck(required_data=[OPENING_ID]) From 62033249e9aa494f38928cc929be6a9dbc59c301 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Tue, 3 Oct 2023 10:14:03 +0530 Subject: [PATCH 05/38] fixed mailer --- CDC_Backend/APIs/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index f6a8dee..cc9a773 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -198,7 +198,7 @@ def sendEmail(email_to, subject, data, template, attachment_jnf_response=None): else: recipient_list = [str(email_to), ] - msg = EmailMultiAlternatives(subject, text_content, email_from,"irontwist00@gmail.com",bcc=recipient_list) + msg = EmailMultiAlternatives(subject, text_content, email_from,None,bcc=recipient_list) msg.attach_alternative(html_content, "text/html") if attachment_jnf_response: # logger.info(attachment_jnf_response) @@ -405,8 +405,9 @@ def internship_eligibility_filters(student, internships): @background_task.background(schedule=2) -def send_opening_notifications(opening_id, opening_type): +def send_opening_notifications(opening_id, opening_type=PLACEMENT): try: + # print(opening_id, opening_type) if opening_type == PLACEMENT: opening = get_object_or_404(Placement, id=opening_id) else: From 37615876d61c3f918f3a2ab151c1cc1b656dd8d6 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Tue, 3 Oct 2023 16:33:11 +0530 Subject: [PATCH 06/38] added addIssue endpoint and updated offeraccepted --- CDC_Backend/APIs/adminViews.py | 5 + CDC_Backend/APIs/constants.py | 9 +- CDC_Backend/APIs/models.py | 29 ++++- CDC_Backend/APIs/studentUrls.py | 18 +-- CDC_Backend/APIs/studentViews.py | 48 +++++++ CDC_Backend/APIs/utils.py | 8 +- .../templates/reps_issue_submitted.html | 117 +++++++++++++++++ .../templates/student_issue_submitted.html | 118 ++++++++++++++++++ 8 files changed, 339 insertions(+), 13 deletions(-) create mode 100644 CDC_Backend/templates/reps_issue_submitted.html create mode 100644 CDC_Backend/templates/student_issue_submitted.html diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index b806275..f56d1c5 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -149,12 +149,17 @@ def updateOfferAccepted(request, id, email, user_type): opening_type= data[OPENING_TYPE] else: opening_type= "Placement" + if DEADLINE_DATETIME in data: + deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z') + else: + deadline_datetime = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) + datetime.timedelta(days=2) if opening_type == "Internship": opening = get_object_or_404(Internship, pk=data[OPENING_ID]) else: opening = get_object_or_404(Placement, pk=data[OPENING_ID]) if opening.offer_accepted is None: opening.offer_accepted = offer_accepted == "true" + opening.deadline_datetime = deadline_datetime opening.changed_by = get_object_or_404(User, id=id) opening.save() if opening.offer_accepted: diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index 0c8e21a..8ebfcf1 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -73,6 +73,10 @@ CDC_REPS_EMAILS = [ "suvamay.jana@iitdh.ac.in", "ramesh.nayaka@iitdh.ac.in" ] +CDC_REPS_EMAILS_FOR_ISSUE=[ #add reps emails + "support.cdc@iitdh.ac.in" + "irontwist00@gmail.com" +] # To be Configured Properly CLIENT_ID = os.environ.get('GOOGLE_OAUTH_CLIENT_ID') # Google Login Client ID @@ -207,7 +211,9 @@ APPLICATION_CSV_COL_NAMES = ['Applied At', 'Roll No.', 'Name', 'Email', 'Phone N 'Resume', 'Selected', ] - +ISSUE_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Issue Submitted' +STUDENT_ISSUE_SUBMITTED_TEMPLATE = 'student_issue_submitted.html' +REPS_ISSUE_SUBMITTED_TEMPLATE = 'reps_issue_submitted.html' # Internships INTERNSHIP = 'Internship' INTERNSHIP_ID = 'internship_id' @@ -225,6 +231,7 @@ FACILITIES = 'facilities' OTHER_FACILITIES = 'other_facilities' STIPEND_DETAILS_PDF = 'compensation_details_pdf' STIPEND_DETAILS_PDF_NAMES = 'stipend_description_pdf_names' +INTERNSHIP_OPENING_URL = "https://cdc.iitdh.ac.in/portal/student/dashboard/internships/{id}" # On frontend, this is the URL to be opened SEASONS = ( 'Summer', diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py index f5dbc57..9321cc6 100644 --- a/CDC_Backend/APIs/models.py +++ b/CDC_Backend/APIs/models.py @@ -478,4 +478,31 @@ class Contributor(models.Model): image = models.CharField(max_length=JNF_SMALLTEXT_MAX_CHARACTER_COUNT, blank=False, default="", null=True) def __str__(self): - return self.name \ No newline at end of file + return self.name + + +class Issues(models.Model): + id = models.AutoField(primary_key=True) + title = models.CharField(max_length=JNF_SMALLTEXT_MAX_CHARACTER_COUNT, blank=False, default="") + description = models.CharField(max_length=200, blank=False, default="") + opening=(models.ForeignKey(Placement, on_delete=models.CASCADE, blank=False) or models.ForeignKey(Internship, on_delete=models.CASCADE, blank=False)) + #status = models.CharField(max_length=JNF_SMALLTEXT_MAX_CHARACTER_COUNT, blank=False, default="") + student=models.ForeignKey(Student, on_delete=models.CASCADE, blank=False) + created_at = models.DateTimeField(blank=False, default=None, null=True) + updated_at = models.DateTimeField(blank=False, default=None, null=True) + changed_by = models.ForeignKey(User, on_delete=models.RESTRICT, blank=True, null=True) + history = HistoricalRecords(user_model=User) + + def save(self, *args, **kwargs): + ''' On save, add timestamps ''' + if not self.created_at: + self.created_at = timezone.now() + self.updated_at = timezone.now() + + return super(Issues, self).save(*args, **kwargs) + + def __str__(self): + return self.title + " - " + self.student.name + class Meta: + verbose_name_plural = "Issues" + \ No newline at end of file diff --git a/CDC_Backend/APIs/studentUrls.py b/CDC_Backend/APIs/studentUrls.py index 07c4710..e94ecf5 100644 --- a/CDC_Backend/APIs/studentUrls.py +++ b/CDC_Backend/APIs/studentUrls.py @@ -3,14 +3,14 @@ from django.urls import path from . import studentViews urlpatterns = [ - path('login/', studentViews.login, name="Login"), #done for intern - path('profile/', studentViews.studentProfile, name="Student Profile"), #done for intern - path('getDashboard/', studentViews.getDashboard, name="Dashboard"), # customised dashboard.. check are we checking registedred check allowed branch/batches filter in - path("addResume/", studentViews.addResume, name="Upload Resume"), #done for intern - path("deleteResume/", studentViews.deleteResume, name="Upload Resume"),#done for intern - path("submitApplication/", studentViews.submitApplication, name="Submit Application"), #done for intern - path("deleteApplication/", studentViews.deleteApplication, name="Delete Application"), #done for intern check for opening type data in headers + path('login/', studentViews.login, name="Login"), + path('profile/', studentViews.studentProfile, name="Student Profile"), + path('getDashboard/', studentViews.getDashboard, name="Dashboard"), + path("addResume/", studentViews.addResume, name="Upload Resume"), + path("deleteResume/", studentViews.deleteResume, name="Delete Resume"), + path("submitApplication/", studentViews.submitApplication, name="Submit Application"), + path("deleteApplication/", studentViews.deleteApplication, name="Delete Application"), path("getContributorStats/", studentViews.getContributorStats, name="Get Contributor Stats"), - path("studentAcceptOffer/", studentViews.studentAcceptOffer, name="Student Accept Offer"), #same as above check header + path("studentAcceptOffer/", studentViews.studentAcceptOffer, name="Student Accept Offer"), + path("addIssue/",studentViews.addIssue,name= "Add Issue") ] -#store all files.. \ No newline at end of file diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index a9fb2aa..2f7c7e1 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -346,4 +346,52 @@ def studentAcceptOffer(request, id, email, user_type): logger.warning("Accept Offer: " + str(sys.exc_info())) return Response({'action': "Accept Offer", 'message': "Something Went Wrong"}, + status=status.HTTP_400_BAD_REQUEST) + + +#view for addIssue + +@api_view(['POST']) +@isAuthorized(allowed_users=[STUDENT]) +@precheck(required_data=["Title","Description","opening_id"]) +def addIssue(request, id, email, user_type): + try: + data = request.data + student = get_object_or_404(Student, id=id) + issue = Issues() + issue.student = student + issue.title = data["Title"] + issue.description = data["Description"] + # issue.opening=get_object_or_404(Placement, id=data["opening_id"]) or get_object_or_404(Internship, id=data["opening_id"]) + try: + issue.opening=get_object_or_404(Placement, id=data["opening_id"]) + except: + try: + issue.opening=get_object_or_404(Internship, id=data["opening_id"]) + except: + return Response({'action': "Add Issue", 'message': "Opening Not Found"}, + status=status.HTTP_400_BAD_REQUEST) + issue.save() + subject=ISSUE_SUBMITTED_TEMPLATE_SUBJECT + data={ + "name":student.name, + "application_type":PLACEMENT if isinstance(issue.opening,Placement) else INTERNSHIP, + "company_name":issue.opening.company_name, + "additional_info":{ + "Title":issue.title, + "Description":issue.description + }, + "email":email + } + sendEmail(email, subject, data, STUDENT_ISSUE_SUBMITTED_TEMPLATE) + #send_mail_to reps + sendEmail(CDC_REPS_EMAILS_FOR_ISSUE,"Issue Raised",data,REPS_ISSUE_SUBMITTED_TEMPLATE) + return Response({'action': "Add Issue", 'message': "Issue Added"}, + status=status.HTTP_200_OK) + except Http404: + return Response({'action': "Add Issue", 'message': 'Student Not Found'}, + status=status.HTTP_404_NOT_FOUND) + except: + logger.warning("Add Issue: " + str(sys.exc_info())) + return Response({'action': "Add Issue", 'message': "Something Went Wrong"}, status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index cc9a773..60ea4da 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -428,7 +428,7 @@ def send_opening_notifications(opening_id, opening_type=PLACEMENT): "opening_type": "INTERNSHIP" if isinstance(opening, Internship) else "PLACEMENT", "designation": opening.designation, "deadline": deadline_datetime.strftime("%A, %-d %B %Y, %-I:%M %p"), - "link": PLACEMENT_OPENING_URL.format(id=opening.designation) + "link": PLACEMENT_OPENING_URL.format(id=opening.designation) if opening_type == PLACEMENT else INTERNSHIP_OPENING_URL.format(id=opening.designation), } emails.append(student_user.email) #sendEmail(student_user.email, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE) @@ -451,7 +451,7 @@ def exception_email(opening): "company_name": opening["company_name"], } pdfhtml = opening_description_table_html(opening) - name = opening["company_name"] + '_jnf_response.pdf' + name = opening["company_name"] + '_jnf_response.pdf' if opening[OPENING_TYPE]!="INF" else opening["company_name"] + '_inf_response.pdf' attachment_jnf_respone = { "name": name, "html": pdfhtml, @@ -474,6 +474,10 @@ def store_all_files(request): for file in files.getlist(COMPENSATION_DETAILS_PDF): file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/' saveFile(file, file_location) + #stipend details pdf for internships + for file in files.getlist(STIPEND_DETAILS_PDF): + file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/' + saveFile(file, file_location) # selection procedure details pdf for file in files.getlist(SELECTION_PROCEDURE_DETAILS_PDF): file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/' diff --git a/CDC_Backend/templates/reps_issue_submitted.html b/CDC_Backend/templates/reps_issue_submitted.html new file mode 100644 index 0000000..ac6ca1f --- /dev/null +++ b/CDC_Backend/templates/reps_issue_submitted.html @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ +
+ + + + + + + +
+

Hello, Folks

+

+ We have received a issue regarding a {{ application_type }} opening at + + {{ company_name }} From {{name}}. + {% if additional_info_items %} + We received these additional details +
+

+ + + + {% for i,j in additional_info.items %} + + + + + + {% endfor %} +
{{ i }}:{{ j }}
+ {% endif %} + +

+

+

+ please look into it and take necessary actions. + get in touch with the student at at {{ email }} + +

+
+ + + + +
+ + +
+
+
+ + + + + + + +
+

+ ® CDC,IIT Dharwad,2021
+

+
+
+
+ + \ No newline at end of file diff --git a/CDC_Backend/templates/student_issue_submitted.html b/CDC_Backend/templates/student_issue_submitted.html new file mode 100644 index 0000000..ef96862 --- /dev/null +++ b/CDC_Backend/templates/student_issue_submitted.html @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ +
+ + + + + + + +
+

Hello, {{ name }}

+

+ We have received your issue regarding a {{ application_type }} opening at + + {{ company_name }}. + {% if additional_info_items %} + We received these additional details +
+

+ + + + {% for i,j in additional_info.items %} + + + + + + {% endfor %} +
{{ i }}:{{ j }}
+ {% endif %} + +

+

+

+ We will get back to you if we find it legitimate. If you have any queries, please + feel to + write to + cdc.support@iitdh.ac.in +

+
+ + + + +
+ + +
+
+
+ + + + + + + +
+

+ ® CDC,IIT Dharwad,2021
+

+
+
+
+ + \ No newline at end of file From 59c1a0a59e299f279dd117fe2ebb57756cb59e7b Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Tue, 3 Oct 2023 17:46:31 +0530 Subject: [PATCH 07/38] registered issues --- CDC_Backend/APIs/admin.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CDC_Backend/APIs/admin.py b/CDC_Backend/APIs/admin.py index 7e72dc7..a14a7d9 100644 --- a/CDC_Backend/APIs/admin.py +++ b/CDC_Backend/APIs/admin.py @@ -217,3 +217,12 @@ class Placement(InternAdmin): search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME) ordering = ('updated_at', COMPANY_NAME, CONTACT_PERSON_NAME, 'stipend') +@admin.register(Issues) +class Issues(admin.ModelAdmin): + list_display = ('id', 'title', 'description') + search_fields = ('id', 'title', 'description') + ordering = ('id', 'title', 'description') + # list_filter = ('status',) + + def Student(self, obj): + return model_admin_url(obj.student) From 17299b18618c9676cd0251523926924dee171024 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Tue, 3 Oct 2023 19:14:10 +0530 Subject: [PATCH 08/38] updates issuhandlers and mailer --- CDC_Backend/APIs/models.py | 4 +++- CDC_Backend/APIs/studentViews.py | 21 +++++++++-------- CDC_Backend/APIs/utils.py | 23 +++++++++---------- .../templates/reps_issue_submitted.html | 2 +- .../templates/student_issue_submitted.html | 2 +- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py index 9321cc6..fcbaac0 100644 --- a/CDC_Backend/APIs/models.py +++ b/CDC_Backend/APIs/models.py @@ -485,7 +485,9 @@ class Issues(models.Model): id = models.AutoField(primary_key=True) title = models.CharField(max_length=JNF_SMALLTEXT_MAX_CHARACTER_COUNT, blank=False, default="") description = models.CharField(max_length=200, blank=False, default="") - opening=(models.ForeignKey(Placement, on_delete=models.CASCADE, blank=False) or models.ForeignKey(Internship, on_delete=models.CASCADE, blank=False)) + #opening=(models.ForeignKey(Placement, on_delete=models.CASCADE, blank=False) or models.ForeignKey(Internship, on_delete=models.CASCADE, blank=False)) + opening_id=models.CharField(blank=False, max_length=15, default=None, null=True) + opening_type=models.CharField(choices=[('Placement','Placement'),('Internship','Internship')], blank=False, max_length=15, default=PLACEMENT) #status = models.CharField(max_length=JNF_SMALLTEXT_MAX_CHARACTER_COUNT, blank=False, default="") student=models.ForeignKey(Student, on_delete=models.CASCADE, blank=False) created_at = models.DateTimeField(blank=False, default=None, null=True) diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index 2f7c7e1..0d7e010 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -353,7 +353,7 @@ def studentAcceptOffer(request, id, email, user_type): @api_view(['POST']) @isAuthorized(allowed_users=[STUDENT]) -@precheck(required_data=["Title","Description","opening_id"]) +@precheck(required_data=["Title","Description","opening_id","opening_type"]) def addIssue(request, id, email, user_type): try: data = request.data @@ -362,23 +362,24 @@ def addIssue(request, id, email, user_type): issue.student = student issue.title = data["Title"] issue.description = data["Description"] - # issue.opening=get_object_or_404(Placement, id=data["opening_id"]) or get_object_or_404(Internship, id=data["opening_id"]) + issue.opening_id = data["opening_id"] + issue.opening_type = data["opening_type"] try: - issue.opening=get_object_or_404(Placement, id=data["opening_id"]) + if data["opening_type"]==PLACEMENT: + opening=get_object_or_404(Placement, id=data["opening_id"]) + else: + opening=get_object_or_404(Internship, id=data["opening_id"]) except: - try: - issue.opening=get_object_or_404(Internship, id=data["opening_id"]) - except: - return Response({'action': "Add Issue", 'message': "Opening Not Found"}, + return Response({'action': "Add Issue", 'message': "Opening Not Found"}, status=status.HTTP_400_BAD_REQUEST) issue.save() subject=ISSUE_SUBMITTED_TEMPLATE_SUBJECT data={ "name":student.name, - "application_type":PLACEMENT if isinstance(issue.opening,Placement) else INTERNSHIP, - "company_name":issue.opening.company_name, + "application_type":issue.opening_type, + "company_name":opening.company_name, "additional_info":{ - "Title":issue.title, + "Abstract":issue.title, "Description":issue.description }, "email":email diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index 60ea4da..a31d5d1 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -254,7 +254,7 @@ def InternshipApplicationConditions(student, internship): try: selected_companies = InternshipApplication.objects.filter(student=student, selected=True) if len(selected_companies)>=1: - print("selected companies > 1") + # print("selected companies > 1") return False, "You have already secured a Internship" return True, "Conditions Satisfied" @@ -420,23 +420,22 @@ def send_opening_notifications(opening_id, opening_type=PLACEMENT): if (isinstance(opening,Placement) and PlacementApplicationConditions(student, opening)[0]) or (isinstance(opening,Internship) and InternshipApplicationConditions(student, opening)[0]): try: student_user = get_object_or_404(User, id=student.id) - subject = NOTIFY_STUDENTS_OPENING_TEMPLATE_SUBJECT.format( - company_name=opening.company_name) - deadline_datetime = opening.deadline_datetime.astimezone(pytz.timezone('Asia/Kolkata')) - data = { - "company_name": opening.company_name, - "opening_type": "INTERNSHIP" if isinstance(opening, Internship) else "PLACEMENT", - "designation": opening.designation, - "deadline": deadline_datetime.strftime("%A, %-d %B %Y, %-I:%M %p"), - "link": PLACEMENT_OPENING_URL.format(id=opening.designation) if opening_type == PLACEMENT else INTERNSHIP_OPENING_URL.format(id=opening.designation), - } emails.append(student_user.email) #sendEmail(student_user.email, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE) except Http404: logger.warning('Utils - send_opening_notifications: user not found : ' + student.id) except Exception as e: logger.warning('Utils - send_opening_notifications: For Loop' + str(e)) - + subject = NOTIFY_STUDENTS_OPENING_TEMPLATE_SUBJECT.format( + company_name=opening.company_name) + deadline_datetime = opening.deadline_datetime.astimezone(pytz.timezone('Asia/Kolkata')) + data = { + "company_name": opening.company_name, + "opening_type": "INTERNSHIP" if isinstance(opening, Internship) else "PLACEMENT", + "designation": opening.designation, + "deadline": deadline_datetime.strftime("%A, %-d %B %Y, %-I:%M %p"), + "link": PLACEMENT_OPENING_URL.format(id=opening.designation) if opening_type == PLACEMENT else INTERNSHIP_OPENING_URL.format(id=opening.designation), + } sendEmail(emails, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE) #handled multiple mailings except: logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info())) diff --git a/CDC_Backend/templates/reps_issue_submitted.html b/CDC_Backend/templates/reps_issue_submitted.html index ac6ca1f..48fcc86 100644 --- a/CDC_Backend/templates/reps_issue_submitted.html +++ b/CDC_Backend/templates/reps_issue_submitted.html @@ -48,7 +48,7 @@ We have received a issue regarding a {{ application_type }} opening at {{ company_name }} From {{name}}. - {% if additional_info_items %} + {% if additional_info %} We received these additional details

Date: Tue, 3 Oct 2023 22:17:00 +0530 Subject: [PATCH 09/38] fixed logic in StudentAcceptoffer --- CDC_Backend/APIs/models.py | 1 + CDC_Backend/APIs/studentViews.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py index fcbaac0..bb5b9a0 100644 --- a/CDC_Backend/APIs/models.py +++ b/CDC_Backend/APIs/models.py @@ -435,6 +435,7 @@ class InternshipApplication(models.Model): resume = models.CharField(max_length=JNF_TEXT_MAX_CHARACTER_COUNT, blank=False, null=True, default=None) additional_info = models.JSONField(blank=True, null=True, default=None) selected = models.BooleanField(null=True, default=None, blank=True) + offer_accepted = models.BooleanField(null=True, default=None, blank=True) # True if offer accepted, False if rejected, None if not yet decided stipend = models.IntegerField(blank=True, default=None, null=True) applied_at = models.DateTimeField(blank=False, default=None, null=True) updated_at = models.DateTimeField(blank=False, default=None, null=True) diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index 0d7e010..ad67aec 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -328,17 +328,17 @@ def studentAcceptOffer(request, id, email, user_type): try: company_id = request.data['id'] student_id=request.data['profileInfo']['id'] - offer_status = request.data['offerStatus'] + offer_accepted = request.data['offerStatus'] if OPENING_TYPE in request.data: opening_type = request.data[OPENING_TYPE] else: opening_type = PLACEMENT if opening_type==INTERNSHIP: - application=InternshipApplication.objects.get(internship=company_id,student=student_id) #check syntax + application=InternshipApplication.objects.get(internship=company_id,student=student_id,selected=True) else: - application=PlacementApplication.objects.get(placement=company_id,student=student_id) + application=PlacementApplication.objects.get(placement=company_id,student=student_id,selected=True) - application.offer_accepted=offer_status + application.offer_accepted=offer_accepted application.save() return Response({'action': "Accept Offer", 'message': "Updated Offer Status"}, status=status.HTTP_200_OK) From 195b9e8037c232a96fd6fed5a4973f331daf5abc Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Wed, 4 Oct 2023 00:23:36 +0530 Subject: [PATCH 10/38] removed debug statements --- CDC_Backend/APIs/studentViews.py | 3 +-- CDC_Backend/APIs/utils.py | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index ad67aec..660e444 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -48,7 +48,7 @@ def refresh(request): @isAuthorized(allowed_users=[STUDENT]) def studentProfile(request, id, email, user_type): try: - print(id) + #print(id) studentDetails = get_object_or_404(Student, id=id) data = StudentSerializer(studentDetails).data @@ -117,7 +117,6 @@ def getDashboard(request, id, email, user_type): offer_accepted=True, email_verified=True).order_by('deadline_datetime') filtered_internships = internship_eligibility_filters(studentDetails, internships) - print(len(filtered_internships)) internshipsdata = InternshipSerializerForStudent(filtered_internships, many=True).data internshipApplications = InternshipApplication.objects.filter(student_id=id) diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index a31d5d1..69e97a2 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -395,8 +395,6 @@ def internship_eligibility_filters(student, internships): if InternshipApplicationConditions(student, internship)[0]: filtered_internships.append(internship) - else: - print("Not applicable") return filtered_internships except: From 32de7eebb5cda96ec699042d0508f0611736751c Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Thu, 5 Oct 2023 01:48:37 +0530 Subject: [PATCH 11/38] added studentView Tests --- CDC_Backend/APIs/studentUrls.py | 2 +- CDC_Backend/APIs/studentViews.py | 26 +- CDC_Backend/APIs/test_studentView.py | 389 +++++++++++++++++++++++++++ 3 files changed, 408 insertions(+), 9 deletions(-) create mode 100644 CDC_Backend/APIs/test_studentView.py diff --git a/CDC_Backend/APIs/studentUrls.py b/CDC_Backend/APIs/studentUrls.py index e94ecf5..65482ed 100644 --- a/CDC_Backend/APIs/studentUrls.py +++ b/CDC_Backend/APIs/studentUrls.py @@ -8,7 +8,7 @@ urlpatterns = [ path('getDashboard/', studentViews.getDashboard, name="Dashboard"), path("addResume/", studentViews.addResume, name="Upload Resume"), path("deleteResume/", studentViews.deleteResume, name="Delete Resume"), - path("submitApplication/", studentViews.submitApplication, name="Submit Application"), + path("submitApplication/", studentViews.submitApplication, name="Add Application"), path("deleteApplication/", studentViews.deleteApplication, name="Delete Application"), path("getContributorStats/", studentViews.getContributorStats, name="Get Contributor Stats"), path("studentAcceptOffer/", studentViews.studentAcceptOffer, name="Student Accept Offer"), diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index 660e444..c78f605 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -322,25 +322,35 @@ def getContributorStats(request, id, email, user_type): #view for sudentAcceptOffer @api_view(['POST']) +@precheck(required_data=[OPENING_ID,"offer_accepted"]) @isAuthorized(allowed_users=[STUDENT]) def studentAcceptOffer(request, id, email, user_type): try: - company_id = request.data['id'] - student_id=request.data['profileInfo']['id'] - offer_accepted = request.data['offerStatus'] + company_id = request.data[OPENING_ID] + #student_id=request.data['profileInfo']['id'] + student_id=id + + offer_accepted = request.data['offer_accepted'] if OPENING_TYPE in request.data: opening_type = request.data[OPENING_TYPE] else: opening_type = PLACEMENT if opening_type==INTERNSHIP: - application=InternshipApplication.objects.get(internship=company_id,student=student_id,selected=True) + application=InternshipApplication.objects.filter(internship=company_id,student=student_id,selected=True) else: - application=PlacementApplication.objects.get(placement=company_id,student=student_id,selected=True) + application=PlacementApplication.objects.filter(placement=company_id,student=student_id,selected=True) - application.offer_accepted=offer_accepted - application.save() - return Response({'action': "Accept Offer", 'message': "Updated Offer Status"}, + if len(application): + application[0].offer_accepted=offer_accepted + application[0].save() + return Response({'action': "Accept Offer", 'message': "Updated Offer Status"}, status=status.HTTP_200_OK) + else: + return Response({'action': "Accept Offer", 'message': "Offer Not Found"}, + status=status.HTTP_404_NOT_FOUND) + + + except: logger.warning("Accept Offer: " + str(sys.exc_info())) diff --git a/CDC_Backend/APIs/test_studentView.py b/CDC_Backend/APIs/test_studentView.py new file mode 100644 index 0000000..12d13f5 --- /dev/null +++ b/CDC_Backend/APIs/test_studentView.py @@ -0,0 +1,389 @@ +# Create your tests here. +from .models import * +from .serializers import * +from django.test import TestCase, Client +from rest_framework import status +from rest_framework.test import APITestCase, APIClient +from django.urls import reverse +from .utils import * +import json +from django.utils import timezone + + + +class StudentViewsTestCase(APITestCase): + def setUp(self): + self.client = APIClient() + self.user= User.objects.create( + email=str(os.environ.get("email")), + id=generateRandomString(), + user_type=[STUDENT]) + self.assertEqual(self.user.email, User.objects.get(id=self.user.id).email) + self.student = Student.objects.create( + name="Test Student", + id=self.user.id, + resumes=["8BSLybntULgrPPm_beehyv.pdf"], + #email="test@student.com", + #password="testpassword", + roll_no="200010052", + branch="CSE", + batch="2020", + phone_number="1234567890", + # resume_link="https://testresume.com" + changed_by=self.user, + can_apply=True, + can_apply_internship=True, + degree="bTech", + cpi=7.95, + ) + self.assertEqual(self.student.name, Student.objects.get(id=self.student.id).name) + # self.user=User.objects.filter(email="200010052@iitdh.ac.in").first() + # self.student = Student.objects.filter(id=self.user.id).first() + self.internship = Internship.objects.create( + company_name="Test Company", + id=generateRandomString(), + website="https://testwebsite.com", + address="Test Address", + company_type="Test Company Type", + offer_accepted=True, + season=["Summer"], + allowed_branch=["CSE"], + allowed_batch=["2020"], + contact_person_name="Test Contact Person", + phone_number="1234567890", + email="test@test.com", + email_verified=True, + deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), + # location="Test Location", + stipend=10000, + # apply_link="https://testapplylink.com" + ) + # self.assertEqual(self.internship.company_name, Internship.objects.get(self.internship.id).company_name) + # self.internship1 =Internship.objects.create( + # company_name="Test Company1", + # id=generateRandomString(), + # website="https://testwebsite1.com", + # address="Test Address1", + # company_type="Test Company Type1", + # offer_accepted=True, + # season=["Summer"], + # allowed_branch=["CSE"], + # allowed_batch=["2020"], + # contact_person_name="Test Contact Person1", + # phone_number="1234567890", + # email="test@test1.com", + # email_verified=True, + # deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), + # stipend=10000, + + # ) + self.placement = Placement.objects.create( + company_name="Test Company", + id=generateRandomString(), + website="https://testwebsite.com", + address="Test Address", + company_type="Test Company Type", + offer_accepted=True, + tier="6", + # season="Summer", + allowed_branch=["CSE"], + allowed_batch=["2020"], + contact_person_name="Test Contact Person", + phone_number="1234567890", + email="test@test.com", + email_verified=True, + deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), + ) + # self.placement1 = Placement.objects.create( + # company_name="Test Company1", + # id=generateRandomString(), + # website="https://testwebsite1.com", + # address="Test Address1", + # company_type="Test Company Type1", + # offer_accepted=True, + # tier="7", + # # season="Summer", + # allowed_branch=["CSE"], + # allowed_batch=["2020"], + # contact_person_name="Test Contact Person1", + # phone_number="1234567890", + # email="test@test1.com", + # email_verified=True, + # deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), + # ) + #self.assertEqual(self.placement.tier,"1") + self.assertEqual(self.placement.company_name, Placement.objects.get(id=self.placement.id).company_name) + self.internship_application = InternshipApplication.objects.create( + id=generateRandomString(), + internship=self.internship, + student=self.student, + resume="8BSLybntULgrPPm_beehyv.pdf", + selected=True + # status="Applied" + ) + # self.internship_application1=InternshipApplication.objects.create( + # id=generateRandomString(), + # internship=self.internship1, + # student=self.student, + # resume="8BSLybntULgrPPm_beehyv.pdf" + # ) + self.assertEqual(self.internship_application.internship.company_name, InternshipApplication.objects.get(id=self.internship_application.id).internship.company_name) + self.placement_application = PlacementApplication.objects.create( + id=generateRandomString(), + placement=self.placement, + student=self.student, + resume="8BSLybntULgrPPm_beehyv.pdf", + selected=True + # status="Applied" + ) + # self.placement_application1 = PlacementApplication.objects.create( + # id=generateRandomString(), + # placement=self.placement1, + # student=self.student, + # resume="8BSLybntULgrPPm_beehyv.pdf", + # # selected=True + # # status="Applied" + # ) + self.assertEqual(self.placement_application.placement.company_name, PlacementApplication.objects.get(id=self.placement_application.id).placement.company_name) + self.issue = Issues.objects.create( + student=self.student, + title="Test Issue", + description="Test Issue Description", + opening_id=self.internship.id, + opening_type=INTERNSHIP + ) + #get token from google OAuth API + response=self.client.post(reverse('Refresh Token'), {'refresh_token': os.environ.get("refresh_token")}, format='json') + self.student_token=response.data['id_token'] + # self.student_token = get_access_token_id(os.environ.get("refresh_token")) + + #self.contributor_token = get_token(self.contributor.email, "testpassword", CONTRIBUTOR) + + def test_student_accept_offer_internship(self): + url = reverse('Student Accept Offer') + data={ + 'opening_id':self.internship.id, + 'offer_accepted':True, + 'opening_type':INTERNSHIP + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Updated Offer Status') + self.assertEqual(InternshipApplication.objects.get(id=self.internship_application.id).offer_accepted, True) + self.internship_application.selected=False + self.internship_application.offer_accepted=False + self.internship_application.save() + + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Offer Not Found') + self.assertEqual(InternshipApplication.objects.get(id=self.internship_application.id).offer_accepted, False) + + + def test_delete_application_internship(self): + url = reverse('Delete Application') + data = { + 'application_id': self.internship_application.id, + 'opening_type': INTERNSHIP + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Deleted') + self.assertEqual(InternshipApplication.objects.filter(id=self.internship_application.id).count(), 0) + self.internship.deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + self.internship.save() + self.internship_application=InternshipApplication.objects.create(id=generateRandomString(), + internship=self.internship, + student=self.student, + resume="8BSLybntULgrPPm_beehyv.pdf", + selected=True) + data['application_id']=self.internship_application.id + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], 'Deadline Passed') + self.assertEqual(InternshipApplication.objects.filter(id=self.internship_application.id).count(), 1) + + + def test_add_application_internship(self): + url = reverse('Delete Application') + data = { + 'application_id': self.internship_application.id, + 'opening_type': INTERNSHIP + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Deleted') + self.assertEqual(InternshipApplication.objects.filter(id=self.internship_application.id).count(), 0) + #deleted existing application + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf' + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Submitted') + self.assertEqual(InternshipApplication.objects.filter(student=self.student).count(), 1) + self.internship_application=InternshipApplication.objects.filter(student=self.student) + self.internship.deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + self.internship.save() + + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'],'Application is already Submitted') + self.assertEqual(InternshipApplication.objects.filter(student=self.student).count(), 1) + self.internship_application.delete() + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'],'No Internship matches the given query.') + self.assertEqual(InternshipApplication.objects.filter(student=self.student).count(), 0) + + + def test_student_accept_offer_placement(self): + url=reverse('Student Accept Offer') + data={ + 'opening_id':self.placement.id, + 'offer_accepted':True, + 'opening_type':PLACEMENT + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response=self.client.post(url,data,format='json') + self.assertEqual(response.status_code,status.HTTP_200_OK) + self.assertEqual(response.data['message'],'Updated Offer Status') + self.assertEqual(PlacementApplication.objects.get(id=self.placement_application.id).offer_accepted,True) + self.placement_application.selected=False + self.placement_application.offer_accepted=False + self.placement_application.save() + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Offer Not Found') + self.assertEqual(PlacementApplication.objects.get(id=self.placement_application.id).offer_accepted, False) + + def test_delete_application_placement(self): + url=reverse('Delete Application') + data={ + 'application_id':self.placement_application.id, + 'opening_type':PLACEMENT + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response=self.client.post(url,data,format='json') + self.assertEqual(response.status_code,status.HTTP_200_OK) + self.assertEqual(response.data['message'],'Application Deleted') + self.assertEqual(PlacementApplication.objects.filter(id=self.placement_application.id).count(),0) + self.placement.deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + self.placement.save() + self.placement_application=PlacementApplication.objects.create(id=generateRandomString(), + placement=self.placement, + student=self.student, + resume="8BSLybntULgrPPm_beehyv.pdf", + selected=True) + data['application_id']=self.placement_application.id + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], 'Deadline Passed') + self.assertEqual(PlacementApplication.objects.filter(id=self.placement_application.id).count(), 1) + def test_add_application_placement(self): + url=reverse('Delete Application') + data={ + 'application_id':self.placement_application.id, + 'opening_type':PLACEMENT + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response=self.client.post(url,data,format='json') + self.assertEqual(response.status_code,status.HTTP_200_OK) + self.assertEqual(response.data['message'],'Application Deleted') + self.assertEqual(PlacementApplication.objects.filter(id=self.placement_application.id).count(),0) + #deleted existing application + url=reverse('Add Application') + data={ + OPENING_ID:self.placement.id, + OPENING_TYPE:PLACEMENT, + RESUME_FILE_NAME:'8BSLybntULgrPPm_beehyv.pdf' + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response=self.client.post(url,data,format='json') + self.assertEqual(response.status_code,status.HTTP_200_OK) + self.assertEqual(response.data['message'],'Application Submitted') + self.assertEqual(PlacementApplication.objects.filter(student=self.student).count(),1) + self.placement.deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + self.placement.save() + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], 'Application is already Submitted') + self.assertEqual(PlacementApplication.objects.filter(student=self.student).count(), 1) + self.placement_application=PlacementApplication.objects.filter(student=self.student) + self.placement_application.delete() + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'No Placement matches the given query.') + self.assertEqual(PlacementApplication.objects.filter(student=self.student).count(), 0) + + + + def test_dashboard(self): + url=reverse('Dashboard') + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response=self.client.get(url,format='json') + self.assertEqual(response.status_code,status.HTTP_200_OK) + self.assertEqual(response.data['message'],'Data Found') + internships=Internship.objects.filter(allowed_batch__contains=[self.student.batch], + allowed_branch__contains=[self.student.branch], + deadline_datetime__gte=datetime.datetime.now(), + offer_accepted=True, email_verified=True) + placements=Placement.objects.filter(allowed_batch__contains=[self.student.batch], + allowed_branch__contains=[self.student.branch], + deadline_datetime__gte=datetime.datetime.now(), + offer_accepted=True, email_verified=True) + # self.assertEqual(len(response.data['internships']),len(internships)) + # self.assertEqual(PlacementApplicationConditions(self.student,self.placement)[1],"hai") + # self.assertEqual(len(response.data['placements']),len(placements)) + filtered_internships=internship_eligibility_filters(self.student,internships) + filtered_placements=placement_eligibility_filters(self.student,placements) + self.assertEqual(len(response.data['internships']),len(filtered_internships)) + self.assertEqual(len(response.data['placements']),len(filtered_placements)) + self.assertEqual(len(response.data['placementApplication']),1) + self.assertEqual(len(response.data['internshipApplication']),1) + self.assertEqual(response.data['placementApplication'][0]['placement']['company_name'],self.placement.company_name) + self.assertEqual(response.data['internshipApplication'][0]['internship']['company_name'],self.internship.company_name) + + + + + + + + + + # def test_get_contributor_stats(self): + # url = reverse('get_contributor_stats', kwargs={'id': self.student.id}) + # self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.contributor_token) + # response = self.client.get(url, format='json') + # self.assertEqual(response.status_code, status.HTTP_200_OK) + # self.assertEqual(response.data['message'], 'Contributor Stats Fetched') + # self.assertEqual(len(response.data['data']), 1) + # self.assertEqual(response.data['data'][0]['name'], self.contributor.name) + # self.assertEqual(response.data['data'][0]['email'], self.contributor.email) + # self.assertEqual(response.data['data'][0]['contribution_count'], self.contributor.contribution_count) + + + def test_add_issue(self): + url = reverse('Add Issue') + data = { + 'Title': 'Test Issue 2', + 'Description': 'Test Issue Description 2', + 'opening_id': self.placement.id, + 'opening_type': PLACEMENT + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Issue Added') + self.assertEqual(Issues.objects.filter(student=self.student).count(), 2) + self.assertEqual(Issues.objects.filter(opening_id=self.placement.id).count(), 1) + self.assertEqual(Issues.objects.filter(opening_type=PLACEMENT).count(), 1) + \ No newline at end of file From 814ed005f1cef57c3e9d63231dc1c26e7bb50a83 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Fri, 6 Oct 2023 03:19:25 +0530 Subject: [PATCH 12/38] testcases --- CDC_Backend/APIs/adminViews.py | 6 +- CDC_Backend/APIs/tests/__init__.py | 0 CDC_Backend/APIs/tests/test_adminView.py | 796 +++++++++++++++++++++ CDC_Backend/APIs/tests/test_studentView.py | 431 +++++++++++ 4 files changed, 1230 insertions(+), 3 deletions(-) create mode 100644 CDC_Backend/APIs/tests/__init__.py create mode 100644 CDC_Backend/APIs/tests/test_adminView.py create mode 100644 CDC_Backend/APIs/tests/test_studentView.py diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index f56d1c5..9c6ce31 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -23,7 +23,7 @@ def markStatus(request, id, email, user_type): # Getting all application from db for this opening # applications = PlacementApplication.objects.filter(placement_id=data[OPENING_ID]) for i in data[STUDENT_LIST]: - # print(i[STUDENT_ID]) issue is using student id instead of roll no both may not be same + # print(i[STUDENT_ID]) issue is using student id instead of roll no both may not be same #remember this application = applications.filter(student__roll_no=i[STUDENT_ID]) # Filtering student's application if len(application) > 0: application = application[0] @@ -60,7 +60,7 @@ def markStatus(request, id, email, user_type): application.chaged_by = get_object_or_404(User, id=id) application.save() else: - raise ValueError("Student - " + i[STUDENT_ID] + " didn't apply for this opening") + raise ValueError("Student - " + str(i[STUDENT_ID]) + " didn't apply for this opening") return Response({'action': "Mark Status", 'message': "Marked Status"}, status=status.HTTP_200_OK) @@ -152,7 +152,7 @@ def updateOfferAccepted(request, id, email, user_type): if DEADLINE_DATETIME in data: deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z') else: - deadline_datetime = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) + datetime.timedelta(days=2) + deadline_datetime = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + datetime.timedelta(days=2) if opening_type == "Internship": opening = get_object_or_404(Internship, pk=data[OPENING_ID]) else: diff --git a/CDC_Backend/APIs/tests/__init__.py b/CDC_Backend/APIs/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/CDC_Backend/APIs/tests/test_adminView.py b/CDC_Backend/APIs/tests/test_adminView.py new file mode 100644 index 0000000..a3bcb0f --- /dev/null +++ b/CDC_Backend/APIs/tests/test_adminView.py @@ -0,0 +1,796 @@ +from django.test import TestCase, Client +from rest_framework import status +from django.urls import reverse +from ..models import * +from ..serializers import * +from ..utils import * +import json +import os +from rest_framework.test import APITestCase, APIClient + + +class AdminView(APITestCase): + + def setUp(self): + self.client = APIClient() + self.admin = User.objects.create(email=str(os.environ.get( + "email")), id=generateRandomString(), user_type=[ADMIN]) + self.s_admin = User.objects.create(email=str(os.environ.get( + "s_email")), id=generateRandomString(), user_type=["s_admin"]) + self.user1 = User.objects.create( + email="200010030@iitdh.ac.in", id=200010030, user_type=[STUDENT]) + self.user2 = User.objects.create( + email="200010038@iitdh.ac.in", id=200010038, user_type=[STUDENT]) + self.user3 = User.objects.create( + email="200010054@iitdh.ac.in", id=200010054, user_type=[STUDENT]) + self.user4 = User.objects.create( + email="200030058@iitdh.ac.in", id=200030058, user_type=[STUDENT]) + self.student1 = Student.objects.create( + name='John Doe', roll_no='200010030', batch='2020', branch='CSE', cpi=9.5, id=200010030, can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) + self.student2 = Student.objects.create( + name='Jane Doe', roll_no='200010038', batch='2020', branch='EE', cpi=9.0, id=200010038, can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) + self.student3 = Student.objects.create( + name='Bob Smith', roll_no='200010054', batch='2020', branch='CSE', cpi=8.5, id=200010054, can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) + self.student4 = Student.objects.create( + name='Bob Marley', roll_no='200030058', batch='2020', branch='CSE', cpi=8.5, id=200030058, can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) + + self.placement1 = Placement.objects.create( + company_name='ABC Corp', compensation_CTC=1000000, tier='1', id=generateRandomString(), allowed_branch=["CSE", "EE"], allowed_batch=["2020"], contact_person_name="test", phone_number="1234567890", email="test1@test.com", email_verified=True, offer_accepted=True) + self.placement2 = Placement.objects.create( + company_name='XYZ Corp', compensation_CTC=800000, tier='2', id=generateRandomString(), allowed_branch=["CSE", "EE"], allowed_batch=["2020"], contact_person_name="test1", phone_number="1234567890", email="test2@test.com", email_verified=True, offer_accepted=True) + self.placement3 = Placement.objects.create( + company_name='X Corp', compensation_CTC=800000, tier='2', id=generateRandomString(), allowed_branch=["CSE", "EE"], allowed_batch=["2020"], contact_person_name="test2", phone_number="1234567890", email="test3@test.com", email_verified=True) + self.internship1 = Internship.objects.create( + company_name='ABC Corp', stipend=100000, id=generateRandomString(), allowed_branch=["CSE", "EE"], allowed_batch=["2020"], contact_person_name="test", phone_number="1234567890", email="test@gmail.com", email_verified=True, offer_accepted=True) + self.internship2 = Internship.objects.create( + company_name='XYZ Corp', stipend=80000, id=generateRandomString(), allowed_branch=["CSE", "EE"], allowed_batch=["2020"], contact_person_name="test1", phone_number="1234567890", email="test1@gmail.com", email_verified=True, offer_accepted=True) + self.internship3 = Internship.objects.create( + company_name='X Corp', stipend=80000, id=generateRandomString(), allowed_branch=["CSE", "EE"], allowed_batch=["2020"], contact_person_name="test", phone_number="1234567890", email="test3@gmail.com", email_verified=True) + self.ppo1 = PrePlacementOffer.objects.create( + company='DEF Corp', compensation=900000, tier='1', student=self.student1, designation="SDE") + self.ppo2 = PrePlacementOffer.objects.create( + company='GHI Corp', compensation=700000, tier='2', student=self.student3, designation="SDE") + + self.pa1 = PlacementApplication.objects.create( + id=generateRandomString(), student=self.student1, placement=self.placement1, resume="8BSLybntULgrPPm_beehyv.pdf") + self.pa2 = PlacementApplication.objects.create( + id=generateRandomString(), student=self.student2, placement=self.placement2, resume="8BSLybntULgrPPm_beehyv.pdf") + self.pa3 = PlacementApplication.objects.create( + id=generateRandomString(), student=self.student3, placement=self.placement1, resume="8BSLybntULgrPPm_beehyv.pdf") + + self.pa4 = PlacementApplication.objects.create( + id=generateRandomString(), student=self.student1, placement=self.placement2) + self.pa5 = PlacementApplication.objects.create( + id=generateRandomString(), student=self.student2, placement=self.placement1) + self.pa6 = PlacementApplication.objects.create( + id=generateRandomString(), student=self.student3, placement=self.placement2) + + self.ia1 = InternshipApplication.objects.create( + id=generateRandomString(), student=self.student1, internship=self.internship1, resume="8BSLybntULgrPPm_beehyv.pdf") + self.ia2 = InternshipApplication.objects.create( + id=generateRandomString(), student=self.student2, internship=self.internship2, resume="8BSLybntULgrPPm_beehyv.pdf") + self.ia3 = InternshipApplication.objects.create( + id=generateRandomString(), student=self.student3, internship=self.internship1, resume="8BSLybntULgrPPm_beehyv.pdf") + self.ia4 = InternshipApplication.objects.create( + id=generateRandomString(), student=self.student1, internship=self.internship2, resume="8BSLybntULgrPPm_beehyv.pdf") + self.ia5 = InternshipApplication.objects.create( + id=generateRandomString(), student=self.student2, internship=self.internship1, resume="8BSLybntULgrPPm_beehyv.pdf") + self.ia6 = InternshipApplication.objects.create( + id=generateRandomString(), student=self.student3, internship=self.internship2, resume="8BSLybntULgrPPm_beehyv.pdf") + + response = self.client.post(reverse('Refresh Token'), { + 'refresh_token': os.environ.get("refresh_token")}, format='json') + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + self.token = response.data['id_token'] + # response = self.client.post(reverse('Refresh Token'), { + # 'refresh_token': os.environ.get("s_refresh_token")}, format='json') + # self.assertEqual(response.status_code, status.HTTP_200_OK) + # self.s_token = response.data['id_token'] + + def test_get_stats(self): + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.get(reverse('Get Stats')) + stats = response.data['stats'] + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(len(stats), 3) + + # Check if the stats are correct for student1 + student1_stats = next( + (item for item in stats if item["id"] == self.student1.id), None) + self.assertEqual(student1_stats['name'], self.student1.name) + self.assertEqual(student1_stats['roll_no'], self.student1.roll_no) + self.assertEqual(student1_stats['batch'], self.student1.batch) + self.assertEqual(student1_stats['branch'], self.student1.branch) + self.assertEqual(student1_stats['cpi'], self.student1.cpi) + self.assertEqual( + student1_stats['first_offer'], self.placement1.company_name) + self.assertEqual( + student1_stats['first_offer_tier'], self.placement1.tier) + self.assertEqual( + student1_stats['first_offer_compensation'], self.placement1.compensation_CTC) + self.assertEqual( + student1_stats['second_offer'], self.placement2.company_name) + self.assertEqual( + student1_stats['second_offer_tier'], self.placement2.tier) + self.assertEqual( + student1_stats['second_offer_compensation'], self.placement2.compensation_CTC) + + # Check if the stats are correct for student2 + student2_stats = next( + (item for item in stats if item["id"] == self.student2.id), None) + self.assertEqual(student2_stats['name'], self.student2.name) + self.assertEqual(student2_stats['roll_no'], self.student2.roll_no) + self.assertEqual(student2_stats['batch'], self.student2.batch) + self.assertEqual(student2_stats['branch'], self.student2.branch) + self.assertEqual(student2_stats['cpi'], self.student2.cpi) + self.assertEqual( + student2_stats['first_offer'], self.placement2.company_name) + self.assertEqual( + student2_stats['first_offer_tier'], self.placement2.tier) + self.assertEqual( + student2_stats['first_offer_compensation'], self.placement2.compensation_CTC) + self.assertEqual( + student2_stats['second_offer'], self.placement1.company_name) + self.assertEqual( + student2_stats['second_offer_tier'], self.placement1.tier) + self.assertEqual( + student2_stats['second_offer_compensation'], self.placement1.compensation_CTC) + + # Check if the stats are correct for student3 + student3_stats = next( + (item for item in stats if item["id"] == self.student3.id), None) + self.assertEqual(student3_stats['name'], self.student3.name) + self.assertEqual(student3_stats['roll_no'], self.student3.roll_no) + self.assertEqual(student3_stats['batch'], self.student3.batch) + self.assertEqual(student3_stats['branch'], self.student3.branch) + self.assertEqual(student3_stats['cpi'], self.student3.cpi) + self.assertEqual(student3_stats['first_offer'], self.ppo2.company) + self.assertEqual(student3_stats['first_offer_tier'], self.ppo2.tier) + self.assertEqual( + student3_stats['first_offer_compensation'], self.ppo2.compensation) + self.assertEqual( + student3_stats['second_offer'], self.placement2.company_name) + self.assertEqual( + student3_stats['second_offer_tier'], self.placement2.tier) + self.assertEqual( + student3_stats['second_offer_compensation'], self.placement2.compensation_CTC) + + def test_get_stats_error(self): + # Test if an error is returned when an exception is raised + # by the view function + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.get(reverse('Get Stats')) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['message'], 'Something Went Wrong') + + def test_addPPO(self): + url = reverse("Add PPO") + data = { + "student_id": self.student2.id, + "company_name": "ABC Corp", + "compensation_gross": 1000000, + "tier": "1", + "designation": "SDE", + "offer_accepted": "" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'PPO Added') + self.assertEqual(PrePlacementOffer.objects.get( + student=self.student1).company, data['company']) + self.assertEqual(PrePlacementOffer.objects.get( + student=self.student1).compensation, data['compensation']) + self.assertEqual(PrePlacementOffer.objects.get( + student=self.student1).tier, data['tier']) + self.assertEqual(PrePlacementOffer.objects.get( + student=self.student1).designation, data['designation']) + + def test_getStudentApplication(self): + url = reverse("Get student application") + data = { + "student_id": self.student1.id, + "opening_id": self.placement1.id, + "opening_type": "Placement" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['application_info']["id"], self.pa1.id) + self.assertEqual( + response.data['application_info']["resume"], self.pa1.resume) + self.assertEqual( + response.data['application_info']["additional_info"], self.pa1.additional_info) + data["student_id"] = self.student4.id + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['application_found'], 'false') + self.assertEqual( + response.data["student_details"]["name"], self.student4.name) + data['student_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data["message"], 'Student not found') + # ---------------------------------------------- + # -------------------------------------------------checking for internships------------------- + # data[OPENING_TYPE]=INTERNSHIP + # response = self.client.post(url, data=json.dumps( + # data), content_type='application/json') + # self.assertEqual(response.status_code, status.HTTP_200_OK) + # self.assertEqual(len(response.data['application_info']), 2) + + def test_generateCSV(self): + url = reverse("Generate CSV") # not done + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_submitApplication(self): + url = reverse("Submit Application") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_list": [{ + "student_id": self.student1.id, + "student_selected": True + }, { + "student_id": self.student2.id, + "student_selected": False + }] + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Submitted') + self.assertEqual(PlacementApplication.objects.get( + student=self.student1).selected, True) + self.assertEqual(PlacementApplication.objects.get( # note done yet + student=self.student2).selected, False) + + def test_getApplications(self): #has issues check it once + url = reverse("Get Applications") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.get(url, data) + # self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Data Found') + self.assertEqual(len(response.data['applications']), 3) + applications_students = [] + applications_students.append( + response.data['applications'][0]['student_details']["id"]) + applications_students.append( + response.data['applications'][1]['student_details']["id"]) + self.assertIn(self.student1.id, applications_students) + self.assertIn(self.student2.id, applications_students) + data['opening_id'] = generateRandomString() + response = self.client.get(url, data) + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + +#-done + def test_addAdditionalInfo(self): + url = reverse("Add Additional Info") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "field": "Test Field" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Additional Info Added') + self.assertIn(data['field'], Placement.objects.get( + id=self.placement1.id).additional_info) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['message'], + 'Additional Info already found') + self.assertIn(data['field'], Placement.objects.get( + id=self.placement1.id).additional_info) + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_deleteAdditionalInfo(self): + self.placement1.additional_info = ["Test Field"] + self.placement1.save() + url = reverse("Delete Additional Info") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "field": "Test Field" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Additional Info Deleted') + self.assertNotIn(data['field'], Placement.objects.get( + id=self.placement1.id).additional_info) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Additional Info not found') + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_updateEmailVerified(self): #done + url = reverse("Update Email Verified") + self.placement1.email_verified = False + self.placement1.save() + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "email_verified": "true" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Email Verified Updated') + self.assertEqual(Placement.objects.get( + id=self.placement1.id).email_verified, True) + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_updateofferAccepted(self): #done + url = reverse("Update Offer Accepted") + self.placement1.offer_accepted = None + self.placement1.save() + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "offer_accepted": "true" + } + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Offer Accepted Updated') + self.assertEqual(Placement.objects.get( + id=self.placement1.id).offer_accepted, True) + self.assertEqual(Placement.objects.get( + id=self.placement1.id).deadline_datetime, timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=2)) + data['opening_id'] = self.placement3.id + data[DEADLINE_DATETIME]=(timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(Placement.objects.get( + id=self.placement3.id).deadline_datetime, timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)) + self.assertEqual(response.data['message'], 'Offer Accepted Updated') + self.placement1.offer_accepted = False + self.placement1.save() + data["opening_id"] = self.placement1.id + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], 'Offer Status already updated') + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_updateDeadline(self): #done + url = reverse("Update Deadline") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "deadline_datetime": (timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.placement1.refresh_from_db() + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Deadline Updated') + self.assertEqual(Placement.objects.get( + id=self.placement1.id).deadline_datetime.strftime('%Y-%m-%d %H:%M:%S %z'), data['deadline_datetime']) + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.placement1.refresh_from_db() + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_markStatus(self): #done + url = reverse("Mark Status") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_list": [{ + "student_id": self.student1.id, + "student_selected": True + }, { + "student_id": self.student2.id, + "student_selected": False + } + ] + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Marked Status') + i = 0 + for student in data['student_list']: + self.assertEqual(PlacementApplication.objects.get( + student=student['student_id'], placement=self.placement1).selected, data['student_list'][i]['student_selected']) + i += 1 + data['student_list'] = [{ + "student_id": self.student4.id, + "student_selected": True + }] + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], "Student - " + str(self.student4.id) + " didn't apply for this opening") + data['student_list'] = [{ + "student_id": self.student1.id, + "student_selected": True + }] + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], "Student already selected") + + def test_get_dashboard(self): #working + url = reverse("Get Dashboard") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + self.internship2.deadline_datetime = timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0) + self.internship2.save() + self.placement2.deadline_datetime = timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0) + self.placement2.save() + response = self.client.get(url) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Data Found') + self.assertEqual(len(response.data['ongoing']), 1) + self.assertEqual(response.data['ongoing'][0]['id'], self.placement1.id) + self.assertEqual(len(response.data['previous']), 1) + self.assertEqual(response.data['previous'] + [0]['id'], self.placement2.id) + self.assertEqual(len(response.data['new']), 1) + self.assertEqual(response.data['new'][0]['id'], self.placement3.id) + self.assertEqual(len(response.data['ongoing_internships']), 1) + self.assertEqual( + response.data['ongoing_internships'][0]['id'], self.internship1.id) + self.assertEqual(len(response.data['previous_internships']), 1) + self.assertEqual( + response.data['previous_internships'][0]['id'], self.internship2.id) + self.assertEqual(len(response.data['new_internships']), 1) + self.assertEqual( + response.data['new_internships'][0]['id'], self.internship3.id) + + # -------------------------------------------------checking for internships------------------- + + def test_getStudentApplication_internship(self): #not done + url = reverse("Get student application") + data = { + "student_id": self.student1.id, + "opening_id": self.internship1.id, + "opening_type": "Placement" + } + self.assertEqual(Student.objects.filter(id=self.student1.id).count(), 1) + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data, content_type='application/json') + # self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Data Found') + self.assertEqual(response.data['application_info']["id"], self.ia1.id) + self.assertEqual( + response.data['application_info']["resume"], self.ia1.resume) + self.assertEqual( + response.data['application_info']["additional_info"], self.ia1.additional_info) + data["student_id"] = self.student4.id + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['application_found'], 'false') + self.assertEqual( + response.data["student_details"]["name"], self.student4.name) + data['student_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data["message"], 'Student not found') + + def test_generateCSV_internship(self): # done + url = reverse("Generate CSV") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_submitApplication_internship(self): + url = reverse("Submit Application") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_list": [{ + "student_id": self.student1.id, + "student_selected": True + }, { + "student_id": self.student2.id, + "student_selected": False + }] + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Submitted') + self.assertEqual(InternshipApplication.objects.get( + student=self.student1).selected, True) + self.assertEqual(InternshipApplication.objects.get( # note done yet + student=self.student2).selected, False) + + def test_getApplications_internship(self): #done + url = reverse("Get Applications") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.get(url, data) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Data Found') + self.assertEqual(len(response.data['applications']), 3) + applications_students = [] + applications_students.append( + response.data['applications'][0]['student_details']["id"]) + applications_students.append( + response.data['applications'][1]['student_details']["id"]) + applications_students.append( + response.data['applications'][2]['student_details']["id"]) + self.assertIn(str(self.student1.id), applications_students) + self.assertIn(str(self.student2.id), applications_students) + self.assertIn(str(self.student3.id), applications_students) + + data['opening_id'] = generateRandomString() + response = self.client.get(url, data) + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + +#-working + def test_addAdditionalInfo_internship(self): + url = reverse("Add Additional Info") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "field": "Test Field", + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Additional Info Added') + self.assertIn(data['field'], Internship.objects.get( + id=self.internship1.id).additional_info) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['message'], + 'Additional Info already found') + self.assertIn(data['field'], Internship.objects.get( + id=self.internship1.id).additional_info) + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_deleteAdditionalInfo_internship(self): + self.internship1.additional_info = ["Test Field"] + self.internship1.save() + url = reverse("Delete Additional Info") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "field": "Test Field" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Additional Info Deleted') + self.assertNotIn(data['field'], Internship.objects.get( + id=self.internship1.id).additional_info) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Additional Info not found') + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_updateEmailVerified_internship(self): #done + url = reverse("Update Email Verified") + self.internship1.email_verified = False + self.internship1.save() + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "email_verified": "true" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Email Verified Updated') + self.assertEqual(Internship.objects.get( + id=self.internship1.id).email_verified, True) + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_updateDeadline_internship(self): #done + url = reverse("Update Deadline") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "deadline_datetime": (timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.internship1.refresh_from_db() + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Deadline Updated') + self.assertEqual(Internship.objects.get( + id=self.internship1.id).deadline_datetime.strftime('%Y-%m-%d %H:%M:%S %z'), data['deadline_datetime']) + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.internship1.refresh_from_db() + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_updateofferAccepted_internship(self): #done + url = reverse("Update Offer Accepted") + self.internship1.offer_accepted = None + self.internship1.save() + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "offer_accepted": "true" + } + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Offer Accepted Updated') + self.assertEqual(Internship.objects.get( + id=self.internship1.id).offer_accepted, True) + self.internship1.refresh_from_db() + self.assertEqual(self.internship1.deadline_datetime, timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=2)) + data['opening_id'] = self.internship3.id + data[DEADLINE_DATETIME] = (timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(Internship.objects.get( + id=self.internship3.id).offer_accepted, True) + self.assertEqual(Internship.objects.get( + id=self.internship3.id).deadline_datetime, timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)) + self.assertEqual(response.data['message'], 'Offer Accepted Updated') + self.internship1.offer_accepted = False + self.internship1.save() + data["opening_id"] = self.internship1.id + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], 'Offer Status already updated') + data["opening_id"] = self.internship2.id + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], 'Offer Status already updated') + data['opening_id'] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_markStatus_internship(self): #done + url = reverse("Mark Status") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_list": [{ + "student_id": self.student1.id, + "student_selected": True + }, { + "student_id": self.student2.id, + "student_selected": False + } + ] + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Marked Status') + i = 0 + for student in data['student_list']: + self.assertEqual(InternshipApplication.objects.get( + student=student['student_id'], internship=self.internship1).selected, data['student_list'][i]['student_selected']) + i += 1 + data['student_list'] = [{ + "student_id": self.student4.id, + "student_selected": True + }] + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], "Student - " + str(self.student4.id) + " didn't apply for this opening") + data['student_list'] = [{ + "student_id": self.student1.id, + "student_selected": True + }] + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], "Student already selected") + + +# --------------------------------------------------------------------------- diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py new file mode 100644 index 0000000..6643991 --- /dev/null +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -0,0 +1,431 @@ +# Create your tests here. +from ..models import * +from ..serializers import * +from django.test import TestCase, Client +from rest_framework import status +from rest_framework.test import APITestCase, APIClient +from django.urls import reverse +from ..utils import * +import json +from django.utils import timezone + + +class StudentViewsTestCase(APITestCase): + def setUp(self): + self.client = APIClient() + self.user = User.objects.create( + email=str(os.environ.get("email")), + id=generateRandomString(), + user_type=[STUDENT]) + self.assertEqual( + self.user.email, User.objects.get(id=self.user.id).email) + self.student = Student.objects.create( + name="Test Student", + id=self.user.id, + resumes=["8BSLybntULgrPPm_beehyv.pdf"], + # email="test@student.com", + # password="testpassword", + roll_no="200010052", + branch="CSE", + batch="2020", + phone_number="1234567890", + # resume_link="https://testresume.com" + changed_by=self.user, + can_apply=True, + can_apply_internship=True, + degree="bTech", + cpi=7.95, + ) + self.assertEqual(self.student.name, + Student.objects.get(id=self.student.id).name) + # self.user=User.objects.filter(email="200010052@iitdh.ac.in").first() + # self.student = Student.objects.filter(id=self.user.id).first() + self.internship = Internship.objects.create( + company_name="Test Company", + id=generateRandomString(), + website="https://testwebsite.com", + address="Test Address", + company_type="Test Company Type", + offer_accepted=True, + season=["Summer"], + allowed_branch=["CSE"], + allowed_batch=["2020"], + contact_person_name="Test Contact Person", + phone_number="1234567890", + email="test@test.com", + email_verified=True, + deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, + microsecond=0) + timezone.timedelta(days=1), + # location="Test Location", + stipend=10000, + # apply_link="https://testapplylink.com" + ) + # self.assertEqual(self.internship.company_name, Internship.objects.get(self.internship.id).company_name) + # self.internship1 =Internship.objects.create( + # company_name="Test Company1", + # id=generateRandomString(), + # website="https://testwebsite1.com", + # address="Test Address1", + # company_type="Test Company Type1", + # offer_accepted=True, + # season=["Summer"], + # allowed_branch=["CSE"], + # allowed_batch=["2020"], + # contact_person_name="Test Contact Person1", + # phone_number="1234567890", + # email="test@test1.com", + # email_verified=True, + # deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), + # stipend=10000, + + # ) + self.placement = Placement.objects.create( + company_name="Test Company", + id=generateRandomString(), + website="https://testwebsite.com", + address="Test Address", + company_type="Test Company Type", + offer_accepted=True, + tier="6", + # season="Summer", + allowed_branch=["CSE"], + allowed_batch=["2020"], + contact_person_name="Test Contact Person", + phone_number="1234567890", + email="test@test.com", + email_verified=True, + deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, + microsecond=0) + timezone.timedelta(days=1), + ) + # self.placement1 = Placement.objects.create( + # company_name="Test Company1", + # id=generateRandomString(), + # website="https://testwebsite1.com", + # address="Test Address1", + # company_type="Test Company Type1", + # offer_accepted=True, + # tier="7", + # # season="Summer", + # allowed_branch=["CSE"], + # allowed_batch=["2020"], + # contact_person_name="Test Contact Person1", + # phone_number="1234567890", + # email="test@test1.com", + # email_verified=True, + # deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), + # ) + # self.assertEqual(self.placement.tier,"1") + self.assertEqual(self.placement.company_name, Placement.objects.get( + id=self.placement.id).company_name) + self.internship_application = InternshipApplication.objects.create( + id=generateRandomString(), + internship=self.internship, + student=self.student, + resume="8BSLybntULgrPPm_beehyv.pdf", + selected=True + # status="Applied" + ) + # self.internship_application1=InternshipApplication.objects.create( + # id=generateRandomString(), + # internship=self.internship1, + # student=self.student, + # resume="8BSLybntULgrPPm_beehyv.pdf" + # ) + self.assertEqual(self.internship_application.internship.company_name, InternshipApplication.objects.get( + id=self.internship_application.id).internship.company_name) + self.placement_application = PlacementApplication.objects.create( + id=generateRandomString(), + placement=self.placement, + student=self.student, + resume="8BSLybntULgrPPm_beehyv.pdf", + selected=True + # status="Applied" + ) + # self.placement_application1 = PlacementApplication.objects.create( + # id=generateRandomString(), + # placement=self.placement1, + # student=self.student, + # resume="8BSLybntULgrPPm_beehyv.pdf", + # # selected=True + # # status="Applied" + # ) + self.assertEqual(self.placement_application.placement.company_name, PlacementApplication.objects.get( + id=self.placement_application.id).placement.company_name) + self.issue = Issues.objects.create( + student=self.student, + title="Test Issue", + description="Test Issue Description", + opening_id=self.internship.id, + opening_type=INTERNSHIP + ) + # get token from google OAuth API + response = self.client.post(reverse('Refresh Token'), { + 'refresh_token': os.environ.get("refresh_token")}, format='json') + self.student_token = response.data['id_token'] + # self.student_token = get_access_token_id(os.environ.get("refresh_token")) + + # self.contributor_token = get_token(self.contributor.email, "testpassword", CONTRIBUTOR) + + def test_student_accept_offer_internship(self): + url = reverse('Student Accept Offer') + data = { + 'opening_id': self.internship.id, + 'offer_accepted': True, + 'opening_type': INTERNSHIP + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Updated Offer Status') + self.assertEqual(InternshipApplication.objects.get( + id=self.internship_application.id).offer_accepted, True) + self.internship_application.selected = False + self.internship_application.offer_accepted = False + self.internship_application.save() + + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Offer Not Found') + self.assertEqual(InternshipApplication.objects.get( + id=self.internship_application.id).offer_accepted, False) + + def test_delete_application_internship(self): + url = reverse('Delete Application') + data = { + 'application_id': self.internship_application.id, + 'opening_type': INTERNSHIP + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Deleted') + self.assertEqual(InternshipApplication.objects.filter( + id=self.internship_application.id).count(), 0) + self.internship.deadline_datetime = timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0) + self.internship.save() + self.internship_application = InternshipApplication.objects.create(id=generateRandomString(), + internship=self.internship, + student=self.student, + resume="8BSLybntULgrPPm_beehyv.pdf", + selected=True) + data['application_id'] = self.internship_application.id + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], 'Deadline Passed') + self.assertEqual(InternshipApplication.objects.filter( + id=self.internship_application.id).count(), 1) + + def test_add_application_internship(self): + url = reverse('Delete Application') + data = { + 'application_id': self.internship_application.id, + 'opening_type': INTERNSHIP + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Deleted') + self.assertEqual(InternshipApplication.objects.filter( + id=self.internship_application.id).count(), 0) + # deleted existing application + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf' + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Submitted') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student).count(), 1) + self.internship_application = InternshipApplication.objects.filter( + student=self.student) + self.internship.deadline_datetime = timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0) + self.internship.save() + + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], + 'Application is already Submitted') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student).count(), 1) + self.internship_application.delete() + data[OPENING_ID] = generateRandomString() + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], + 'No Internship matches the given query.') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student).count(), 0) + + def test_student_accept_offer_placement(self): + url = reverse('Student Accept Offer') + data = { + 'opening_id': self.placement.id, + 'offer_accepted': True, + 'opening_type': PLACEMENT + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Updated Offer Status') + self.assertEqual(PlacementApplication.objects.get( + id=self.placement_application.id).offer_accepted, True) + self.placement_application.selected = False + self.placement_application.offer_accepted = False + self.placement_application.save() + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Offer Not Found') + self.assertEqual(PlacementApplication.objects.get( + id=self.placement_application.id).offer_accepted, False) + + def test_delete_application_placement(self): + url = reverse('Delete Application') + data = { + 'application_id': self.placement_application.id, + 'opening_type': PLACEMENT + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Deleted') + self.assertEqual(PlacementApplication.objects.filter( + id=self.placement_application.id).count(), 0) + self.placement.deadline_datetime = timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0) + self.placement.save() + self.placement_application = PlacementApplication.objects.create(id=generateRandomString(), + placement=self.placement, + student=self.student, + resume="8BSLybntULgrPPm_beehyv.pdf", + selected=True) + data['application_id'] = self.placement_application.id + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], 'Deadline Passed') + self.assertEqual(PlacementApplication.objects.filter( + id=self.placement_application.id).count(), 1) + + def test_add_application_placement(self): + url = reverse('Delete Application') + data = { + 'application_id': self.placement_application.id, + 'opening_type': PLACEMENT + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Deleted') + self.assertEqual(PlacementApplication.objects.filter( + id=self.placement_application.id).count(), 0) + # deleted existing application + url = reverse('Add Application') + data = { + OPENING_ID: self.placement.id, + OPENING_TYPE: PLACEMENT, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf' + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Submitted') + self.assertEqual(PlacementApplication.objects.filter( + student=self.student).count(), 1) + self.placement.deadline_datetime = timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0) + self.placement.save() + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], + 'Application is already Submitted') + self.assertEqual(PlacementApplication.objects.filter( + student=self.student).count(), 1) + self.placement_application = PlacementApplication.objects.filter( + student=self.student) + self.placement_application.delete() + data[OPENING_ID] = generateRandomString() + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], + 'No Placement matches the given query.') + self.assertEqual(PlacementApplication.objects.filter( + student=self.student).count(), 0) + + def test_dashboard(self): + url = reverse('Dashboard') + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.get(url, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Data Found') + internships = Internship.objects.filter(allowed_batch__contains=[self.student.batch], + allowed_branch__contains=[ + self.student.branch], + deadline_datetime__gte=datetime.datetime.now(), + offer_accepted=True, email_verified=True) + placements = Placement.objects.filter(allowed_batch__contains=[self.student.batch], + allowed_branch__contains=[ + self.student.branch], + deadline_datetime__gte=datetime.datetime.now(), + offer_accepted=True, email_verified=True) + # self.assertEqual(len(response.data['internships']),len(internships)) + # self.assertEqual(PlacementApplicationConditions(self.student,self.placement)[1],"hai") + # self.assertEqual(len(response.data['placements']),len(placements)) + filtered_internships = internship_eligibility_filters( + self.student, internships) + filtered_placements = placement_eligibility_filters( + self.student, placements) + self.assertEqual( + len(response.data['internships']), len(filtered_internships)) + self.assertEqual( + len(response.data['placements']), len(filtered_placements)) + self.assertEqual(len(response.data['placementApplication']), 1) + self.assertEqual(len(response.data['internshipApplication']), 1) + self.assertEqual(response.data['placementApplication'][0] + ['placement']['company_name'], self.placement.company_name) + self.assertEqual(response.data['internshipApplication'][0] + ['internship']['company_name'], self.internship.company_name) + + # def test_get_contributor_stats(self): + # url = reverse('get_contributor_stats', kwargs={'id': self.student.id}) + # self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.contributor_token) + # response = self.client.get(url, format='json') + # self.assertEqual(response.status_code, status.HTTP_200_OK) + # self.assertEqual(response.data['message'], 'Contributor Stats Fetched') + # self.assertEqual(len(response.data['data']), 1) + # self.assertEqual(response.data['data'][0]['name'], self.contributor.name) + # self.assertEqual(response.data['data'][0]['email'], self.contributor.email) + # self.assertEqual(response.data['data'][0]['contribution_count'], self.contributor.contribution_count) + + def test_add_issue(self): + url = reverse('Add Issue') + data = { + 'Title': 'Test Issue 2', + 'Description': 'Test Issue Description 2', + 'opening_id': self.placement.id, + 'opening_type': PLACEMENT + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Issue Added') + self.assertEqual(Issues.objects.filter( + student=self.student).count(), 2) + self.assertEqual(Issues.objects.filter( + opening_id=self.placement.id).count(), 1) + self.assertEqual(Issues.objects.filter( + opening_type=PLACEMENT).count(), 1) From a9177417f761e9bdfb183fccd081641d714bb14a Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Fri, 6 Oct 2023 03:20:10 +0530 Subject: [PATCH 13/38] edited PPo test --- CDC_Backend/APIs/tests/test_adminView.py | 39 +++++++++++++----------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/CDC_Backend/APIs/tests/test_adminView.py b/CDC_Backend/APIs/tests/test_adminView.py index a3bcb0f..4cf6929 100644 --- a/CDC_Backend/APIs/tests/test_adminView.py +++ b/CDC_Backend/APIs/tests/test_adminView.py @@ -179,7 +179,7 @@ class AdminView(APITestCase): response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'PPO Added') + self.assertEqual(response.data['message'], 'PPO added') self.assertEqual(PrePlacementOffer.objects.get( student=self.student1).company, data['company']) self.assertEqual(PrePlacementOffer.objects.get( @@ -259,7 +259,7 @@ class AdminView(APITestCase): self.assertEqual(PlacementApplication.objects.get( # note done yet student=self.student2).selected, False) - def test_getApplications(self): #has issues check it once + def test_getApplications(self): # has issues check it once url = reverse("Get Applications") data = { "opening_type": "Placement", @@ -282,7 +282,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') -#-done +# -done def test_addAdditionalInfo(self): url = reverse("Add Additional Info") data = { @@ -336,7 +336,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') - def test_updateEmailVerified(self): #done + def test_updateEmailVerified(self): # done url = reverse("Update Email Verified") self.placement1.email_verified = False self.placement1.save() @@ -358,7 +358,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') - def test_updateofferAccepted(self): #done + def test_updateofferAccepted(self): # done url = reverse("Update Offer Accepted") self.placement1.offer_accepted = None self.placement1.save() @@ -379,7 +379,8 @@ class AdminView(APITestCase): self.assertEqual(Placement.objects.get( id=self.placement1.id).deadline_datetime, timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=2)) data['opening_id'] = self.placement3.id - data[DEADLINE_DATETIME]=(timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + data[DEADLINE_DATETIME] = (timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -400,7 +401,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') - def test_updateDeadline(self): #done + def test_updateDeadline(self): # done url = reverse("Update Deadline") data = { "opening_type": "Placement", @@ -422,7 +423,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') - def test_markStatus(self): #done + def test_markStatus(self): # done url = reverse("Mark Status") data = { "opening_type": "Placement", @@ -465,7 +466,7 @@ class AdminView(APITestCase): self.assertEqual( response.data['message'], "Student already selected") - def test_get_dashboard(self): #working + def test_get_dashboard(self): # working url = reverse("Get Dashboard") self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) self.internship2.deadline_datetime = timezone.now().replace( @@ -496,14 +497,15 @@ class AdminView(APITestCase): # -------------------------------------------------checking for internships------------------- - def test_getStudentApplication_internship(self): #not done + def test_getStudentApplication_internship(self): # not done url = reverse("Get student application") data = { "student_id": self.student1.id, "opening_id": self.internship1.id, "opening_type": "Placement" } - self.assertEqual(Student.objects.filter(id=self.student1.id).count(), 1) + self.assertEqual(Student.objects.filter( + id=self.student1.id).count(), 1) self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data, content_type='application/json') # self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -561,7 +563,7 @@ class AdminView(APITestCase): self.assertEqual(InternshipApplication.objects.get( # note done yet student=self.student2).selected, False) - def test_getApplications_internship(self): #done + def test_getApplications_internship(self): # done url = reverse("Get Applications") data = { "opening_type": "Internship", @@ -590,7 +592,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') -#-working +# -working def test_addAdditionalInfo_internship(self): url = reverse("Add Additional Info") data = { @@ -650,7 +652,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') - def test_updateEmailVerified_internship(self): #done + def test_updateEmailVerified_internship(self): # done url = reverse("Update Email Verified") self.internship1.email_verified = False self.internship1.save() @@ -674,7 +676,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') - def test_updateDeadline_internship(self): #done + def test_updateDeadline_internship(self): # done url = reverse("Update Deadline") data = { "opening_type": "Internship", @@ -698,7 +700,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') - def test_updateofferAccepted_internship(self): #done + def test_updateofferAccepted_internship(self): # done url = reverse("Update Offer Accepted") self.internship1.offer_accepted = None self.internship1.save() @@ -720,7 +722,8 @@ class AdminView(APITestCase): self.assertEqual(self.internship1.deadline_datetime, timezone.now().replace( hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=2)) data['opening_id'] = self.internship3.id - data[DEADLINE_DATETIME] = (timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + data[DEADLINE_DATETIME] = (timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -749,7 +752,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') - def test_markStatus_internship(self): #done + def test_markStatus_internship(self): # done url = reverse("Mark Status") data = { "opening_type": "Internship", From 8c6f6dc17dffa6146cf0ab6411b7edcf56aba3c6 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Sat, 7 Oct 2023 02:43:42 +0530 Subject: [PATCH 14/38] added tests --- CDC_Backend/APIs/adminViews.py | 5 +- CDC_Backend/APIs/studentViews.py | 6 +- CDC_Backend/APIs/test_studentView.py | 389 ------ CDC_Backend/APIs/tests.py | 1 - CDC_Backend/APIs/tests/test_adminView.py | 1273 ++++++++++++++++---- CDC_Backend/APIs/tests/test_studentView.py | 683 ++++++++--- 6 files changed, 1546 insertions(+), 811 deletions(-) delete mode 100644 CDC_Backend/APIs/test_studentView.py delete mode 100644 CDC_Backend/APIs/tests.py diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index 9c6ce31..c93cdc0 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -399,6 +399,9 @@ def submitApplication(request, id, email, user_type): except FileNotFoundError as e: return Response({'action': "Submit Application", 'message': str(e)}, status=status.HTTP_404_NOT_FOUND) + except AttributeError as e: + return Response({'action': "Submit Application", 'message': str(e)}, + status=status.HTTP_400_BAD_REQUEST) except: logger.warning("Submit Application: " + str(sys.exc_info())) return Response({'action': "Submit Application", 'message': "Something Went Wrong"}, @@ -441,7 +444,7 @@ def generateCSV(request, id, email, user_type): row_details.append(apl.student.branch) row_details.append(apl.student.batch) row_details.append(apl.student.cpi) - link = LINK_TO_STORAGE_RESUME + urllib.parse.quote(apl.student.id) + "/" + urllib.parse.quote(apl.resume) + link = LINK_TO_STORAGE_RESUME + urllib.parse.quote(str(apl.student.id)) + "/" + urllib.parse.quote(str(apl.resume)) row_details.append(link) row_details.append(apl.selected) diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index c78f605..a2e6584 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -170,7 +170,7 @@ def deleteResume(request, id, email, user_type): @api_view(['POST']) @isAuthorized(allowed_users=[STUDENT]) -@precheck(required_data=[OPENING_TYPE, OPENING_ID, RESUME_FILE_NAME, +@precheck(required_data=[OPENING_TYPE, OPENING_ID, RESUME_FILE_NAME,ADDITIONAL_INFO ]) def submitApplication(request, id, email, user_type): try: @@ -201,7 +201,7 @@ def submitApplication(request, id, email, user_type): raise PermissionError("Application is already Submitted") elif data[OPENING_TYPE] == INTERNSHIP: if not student.can_apply_internship: - return Response({'action': "Submit Application", 'message': "Student Can't Apply Internship"}, + return Response({'action': "Submit Application", 'message': "Student Can't Apply"}, status=status.HTTP_400_BAD_REQUEST) if not len(InternshipApplication.objects.filter( student_id=id, internship_id=data[OPENING_ID])): @@ -327,7 +327,7 @@ def getContributorStats(request, id, email, user_type): def studentAcceptOffer(request, id, email, user_type): try: company_id = request.data[OPENING_ID] - #student_id=request.data['profileInfo']['id'] + #student_id=request.data['profileInfo']['id'] //check this once student_id=id offer_accepted = request.data['offer_accepted'] diff --git a/CDC_Backend/APIs/test_studentView.py b/CDC_Backend/APIs/test_studentView.py deleted file mode 100644 index 12d13f5..0000000 --- a/CDC_Backend/APIs/test_studentView.py +++ /dev/null @@ -1,389 +0,0 @@ -# Create your tests here. -from .models import * -from .serializers import * -from django.test import TestCase, Client -from rest_framework import status -from rest_framework.test import APITestCase, APIClient -from django.urls import reverse -from .utils import * -import json -from django.utils import timezone - - - -class StudentViewsTestCase(APITestCase): - def setUp(self): - self.client = APIClient() - self.user= User.objects.create( - email=str(os.environ.get("email")), - id=generateRandomString(), - user_type=[STUDENT]) - self.assertEqual(self.user.email, User.objects.get(id=self.user.id).email) - self.student = Student.objects.create( - name="Test Student", - id=self.user.id, - resumes=["8BSLybntULgrPPm_beehyv.pdf"], - #email="test@student.com", - #password="testpassword", - roll_no="200010052", - branch="CSE", - batch="2020", - phone_number="1234567890", - # resume_link="https://testresume.com" - changed_by=self.user, - can_apply=True, - can_apply_internship=True, - degree="bTech", - cpi=7.95, - ) - self.assertEqual(self.student.name, Student.objects.get(id=self.student.id).name) - # self.user=User.objects.filter(email="200010052@iitdh.ac.in").first() - # self.student = Student.objects.filter(id=self.user.id).first() - self.internship = Internship.objects.create( - company_name="Test Company", - id=generateRandomString(), - website="https://testwebsite.com", - address="Test Address", - company_type="Test Company Type", - offer_accepted=True, - season=["Summer"], - allowed_branch=["CSE"], - allowed_batch=["2020"], - contact_person_name="Test Contact Person", - phone_number="1234567890", - email="test@test.com", - email_verified=True, - deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), - # location="Test Location", - stipend=10000, - # apply_link="https://testapplylink.com" - ) - # self.assertEqual(self.internship.company_name, Internship.objects.get(self.internship.id).company_name) - # self.internship1 =Internship.objects.create( - # company_name="Test Company1", - # id=generateRandomString(), - # website="https://testwebsite1.com", - # address="Test Address1", - # company_type="Test Company Type1", - # offer_accepted=True, - # season=["Summer"], - # allowed_branch=["CSE"], - # allowed_batch=["2020"], - # contact_person_name="Test Contact Person1", - # phone_number="1234567890", - # email="test@test1.com", - # email_verified=True, - # deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), - # stipend=10000, - - # ) - self.placement = Placement.objects.create( - company_name="Test Company", - id=generateRandomString(), - website="https://testwebsite.com", - address="Test Address", - company_type="Test Company Type", - offer_accepted=True, - tier="6", - # season="Summer", - allowed_branch=["CSE"], - allowed_batch=["2020"], - contact_person_name="Test Contact Person", - phone_number="1234567890", - email="test@test.com", - email_verified=True, - deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), - ) - # self.placement1 = Placement.objects.create( - # company_name="Test Company1", - # id=generateRandomString(), - # website="https://testwebsite1.com", - # address="Test Address1", - # company_type="Test Company Type1", - # offer_accepted=True, - # tier="7", - # # season="Summer", - # allowed_branch=["CSE"], - # allowed_batch=["2020"], - # contact_person_name="Test Contact Person1", - # phone_number="1234567890", - # email="test@test1.com", - # email_verified=True, - # deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), - # ) - #self.assertEqual(self.placement.tier,"1") - self.assertEqual(self.placement.company_name, Placement.objects.get(id=self.placement.id).company_name) - self.internship_application = InternshipApplication.objects.create( - id=generateRandomString(), - internship=self.internship, - student=self.student, - resume="8BSLybntULgrPPm_beehyv.pdf", - selected=True - # status="Applied" - ) - # self.internship_application1=InternshipApplication.objects.create( - # id=generateRandomString(), - # internship=self.internship1, - # student=self.student, - # resume="8BSLybntULgrPPm_beehyv.pdf" - # ) - self.assertEqual(self.internship_application.internship.company_name, InternshipApplication.objects.get(id=self.internship_application.id).internship.company_name) - self.placement_application = PlacementApplication.objects.create( - id=generateRandomString(), - placement=self.placement, - student=self.student, - resume="8BSLybntULgrPPm_beehyv.pdf", - selected=True - # status="Applied" - ) - # self.placement_application1 = PlacementApplication.objects.create( - # id=generateRandomString(), - # placement=self.placement1, - # student=self.student, - # resume="8BSLybntULgrPPm_beehyv.pdf", - # # selected=True - # # status="Applied" - # ) - self.assertEqual(self.placement_application.placement.company_name, PlacementApplication.objects.get(id=self.placement_application.id).placement.company_name) - self.issue = Issues.objects.create( - student=self.student, - title="Test Issue", - description="Test Issue Description", - opening_id=self.internship.id, - opening_type=INTERNSHIP - ) - #get token from google OAuth API - response=self.client.post(reverse('Refresh Token'), {'refresh_token': os.environ.get("refresh_token")}, format='json') - self.student_token=response.data['id_token'] - # self.student_token = get_access_token_id(os.environ.get("refresh_token")) - - #self.contributor_token = get_token(self.contributor.email, "testpassword", CONTRIBUTOR) - - def test_student_accept_offer_internship(self): - url = reverse('Student Accept Offer') - data={ - 'opening_id':self.internship.id, - 'offer_accepted':True, - 'opening_type':INTERNSHIP - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Updated Offer Status') - self.assertEqual(InternshipApplication.objects.get(id=self.internship_application.id).offer_accepted, True) - self.internship_application.selected=False - self.internship_application.offer_accepted=False - self.internship_application.save() - - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['message'], 'Offer Not Found') - self.assertEqual(InternshipApplication.objects.get(id=self.internship_application.id).offer_accepted, False) - - - def test_delete_application_internship(self): - url = reverse('Delete Application') - data = { - 'application_id': self.internship_application.id, - 'opening_type': INTERNSHIP - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Application Deleted') - self.assertEqual(InternshipApplication.objects.filter(id=self.internship_application.id).count(), 0) - self.internship.deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) - self.internship.save() - self.internship_application=InternshipApplication.objects.create(id=generateRandomString(), - internship=self.internship, - student=self.student, - resume="8BSLybntULgrPPm_beehyv.pdf", - selected=True) - data['application_id']=self.internship_application.id - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - self.assertEqual(response.data['message'], 'Deadline Passed') - self.assertEqual(InternshipApplication.objects.filter(id=self.internship_application.id).count(), 1) - - - def test_add_application_internship(self): - url = reverse('Delete Application') - data = { - 'application_id': self.internship_application.id, - 'opening_type': INTERNSHIP - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Application Deleted') - self.assertEqual(InternshipApplication.objects.filter(id=self.internship_application.id).count(), 0) - #deleted existing application - url = reverse('Add Application') - data = { - OPENING_ID: self.internship.id, - OPENING_TYPE: INTERNSHIP, - RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf' - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Application Submitted') - self.assertEqual(InternshipApplication.objects.filter(student=self.student).count(), 1) - self.internship_application=InternshipApplication.objects.filter(student=self.student) - self.internship.deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) - self.internship.save() - - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - self.assertEqual(response.data['message'],'Application is already Submitted') - self.assertEqual(InternshipApplication.objects.filter(student=self.student).count(), 1) - self.internship_application.delete() - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['message'],'No Internship matches the given query.') - self.assertEqual(InternshipApplication.objects.filter(student=self.student).count(), 0) - - - def test_student_accept_offer_placement(self): - url=reverse('Student Accept Offer') - data={ - 'opening_id':self.placement.id, - 'offer_accepted':True, - 'opening_type':PLACEMENT - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response=self.client.post(url,data,format='json') - self.assertEqual(response.status_code,status.HTTP_200_OK) - self.assertEqual(response.data['message'],'Updated Offer Status') - self.assertEqual(PlacementApplication.objects.get(id=self.placement_application.id).offer_accepted,True) - self.placement_application.selected=False - self.placement_application.offer_accepted=False - self.placement_application.save() - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['message'], 'Offer Not Found') - self.assertEqual(PlacementApplication.objects.get(id=self.placement_application.id).offer_accepted, False) - - def test_delete_application_placement(self): - url=reverse('Delete Application') - data={ - 'application_id':self.placement_application.id, - 'opening_type':PLACEMENT - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response=self.client.post(url,data,format='json') - self.assertEqual(response.status_code,status.HTTP_200_OK) - self.assertEqual(response.data['message'],'Application Deleted') - self.assertEqual(PlacementApplication.objects.filter(id=self.placement_application.id).count(),0) - self.placement.deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) - self.placement.save() - self.placement_application=PlacementApplication.objects.create(id=generateRandomString(), - placement=self.placement, - student=self.student, - resume="8BSLybntULgrPPm_beehyv.pdf", - selected=True) - data['application_id']=self.placement_application.id - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - self.assertEqual(response.data['message'], 'Deadline Passed') - self.assertEqual(PlacementApplication.objects.filter(id=self.placement_application.id).count(), 1) - def test_add_application_placement(self): - url=reverse('Delete Application') - data={ - 'application_id':self.placement_application.id, - 'opening_type':PLACEMENT - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response=self.client.post(url,data,format='json') - self.assertEqual(response.status_code,status.HTTP_200_OK) - self.assertEqual(response.data['message'],'Application Deleted') - self.assertEqual(PlacementApplication.objects.filter(id=self.placement_application.id).count(),0) - #deleted existing application - url=reverse('Add Application') - data={ - OPENING_ID:self.placement.id, - OPENING_TYPE:PLACEMENT, - RESUME_FILE_NAME:'8BSLybntULgrPPm_beehyv.pdf' - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response=self.client.post(url,data,format='json') - self.assertEqual(response.status_code,status.HTTP_200_OK) - self.assertEqual(response.data['message'],'Application Submitted') - self.assertEqual(PlacementApplication.objects.filter(student=self.student).count(),1) - self.placement.deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) - self.placement.save() - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - self.assertEqual(response.data['message'], 'Application is already Submitted') - self.assertEqual(PlacementApplication.objects.filter(student=self.student).count(), 1) - self.placement_application=PlacementApplication.objects.filter(student=self.student) - self.placement_application.delete() - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['message'], 'No Placement matches the given query.') - self.assertEqual(PlacementApplication.objects.filter(student=self.student).count(), 0) - - - - def test_dashboard(self): - url=reverse('Dashboard') - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response=self.client.get(url,format='json') - self.assertEqual(response.status_code,status.HTTP_200_OK) - self.assertEqual(response.data['message'],'Data Found') - internships=Internship.objects.filter(allowed_batch__contains=[self.student.batch], - allowed_branch__contains=[self.student.branch], - deadline_datetime__gte=datetime.datetime.now(), - offer_accepted=True, email_verified=True) - placements=Placement.objects.filter(allowed_batch__contains=[self.student.batch], - allowed_branch__contains=[self.student.branch], - deadline_datetime__gte=datetime.datetime.now(), - offer_accepted=True, email_verified=True) - # self.assertEqual(len(response.data['internships']),len(internships)) - # self.assertEqual(PlacementApplicationConditions(self.student,self.placement)[1],"hai") - # self.assertEqual(len(response.data['placements']),len(placements)) - filtered_internships=internship_eligibility_filters(self.student,internships) - filtered_placements=placement_eligibility_filters(self.student,placements) - self.assertEqual(len(response.data['internships']),len(filtered_internships)) - self.assertEqual(len(response.data['placements']),len(filtered_placements)) - self.assertEqual(len(response.data['placementApplication']),1) - self.assertEqual(len(response.data['internshipApplication']),1) - self.assertEqual(response.data['placementApplication'][0]['placement']['company_name'],self.placement.company_name) - self.assertEqual(response.data['internshipApplication'][0]['internship']['company_name'],self.internship.company_name) - - - - - - - - - - # def test_get_contributor_stats(self): - # url = reverse('get_contributor_stats', kwargs={'id': self.student.id}) - # self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.contributor_token) - # response = self.client.get(url, format='json') - # self.assertEqual(response.status_code, status.HTTP_200_OK) - # self.assertEqual(response.data['message'], 'Contributor Stats Fetched') - # self.assertEqual(len(response.data['data']), 1) - # self.assertEqual(response.data['data'][0]['name'], self.contributor.name) - # self.assertEqual(response.data['data'][0]['email'], self.contributor.email) - # self.assertEqual(response.data['data'][0]['contribution_count'], self.contributor.contribution_count) - - - def test_add_issue(self): - url = reverse('Add Issue') - data = { - 'Title': 'Test Issue 2', - 'Description': 'Test Issue Description 2', - 'opening_id': self.placement.id, - 'opening_type': PLACEMENT - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Issue Added') - self.assertEqual(Issues.objects.filter(student=self.student).count(), 2) - self.assertEqual(Issues.objects.filter(opening_id=self.placement.id).count(), 1) - self.assertEqual(Issues.objects.filter(opening_type=PLACEMENT).count(), 1) - \ No newline at end of file diff --git a/CDC_Backend/APIs/tests.py b/CDC_Backend/APIs/tests.py deleted file mode 100644 index a39b155..0000000 --- a/CDC_Backend/APIs/tests.py +++ /dev/null @@ -1 +0,0 @@ -# Create your tests here. diff --git a/CDC_Backend/APIs/tests/test_adminView.py b/CDC_Backend/APIs/tests/test_adminView.py index 4cf6929..9e63a3b 100644 --- a/CDC_Backend/APIs/tests/test_adminView.py +++ b/CDC_Backend/APIs/tests/test_adminView.py @@ -18,21 +18,21 @@ class AdminView(APITestCase): self.s_admin = User.objects.create(email=str(os.environ.get( "s_email")), id=generateRandomString(), user_type=["s_admin"]) self.user1 = User.objects.create( - email="200010030@iitdh.ac.in", id=200010030, user_type=[STUDENT]) + email="200010030@iitdh.ac.in", id="200010030", user_type=[STUDENT]) self.user2 = User.objects.create( - email="200010038@iitdh.ac.in", id=200010038, user_type=[STUDENT]) + email="200010038@iitdh.ac.in", id="200010038", user_type=[STUDENT]) self.user3 = User.objects.create( - email="200010054@iitdh.ac.in", id=200010054, user_type=[STUDENT]) + email="200010054@iitdh.ac.in", id="200010054", user_type=[STUDENT]) self.user4 = User.objects.create( - email="200030058@iitdh.ac.in", id=200030058, user_type=[STUDENT]) + email="200030058@iitdh.ac.in", id="200030058", user_type=[STUDENT]) self.student1 = Student.objects.create( - name='John Doe', roll_no='200010030', batch='2020', branch='CSE', cpi=9.5, id=200010030, can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) + name='John Doe', roll_no='200010030', batch='2020', branch='CSE', cpi=9.5, id="200010030", can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf", "8BSLybntULgrPPm_kalera.pdf"], can_apply_internship=True) self.student2 = Student.objects.create( - name='Jane Doe', roll_no='200010038', batch='2020', branch='EE', cpi=9.0, id=200010038, can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) + name='Jane Doe', roll_no='200010038', batch='2020', branch='EE', cpi=9.0, id="200010038", can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) self.student3 = Student.objects.create( - name='Bob Smith', roll_no='200010054', batch='2020', branch='CSE', cpi=8.5, id=200010054, can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) + name='Bob Smith', roll_no='200010054', batch='2020', branch='CSE', cpi=8.5, id="200010054", can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) self.student4 = Student.objects.create( - name='Bob Marley', roll_no='200030058', batch='2020', branch='CSE', cpi=8.5, id=200030058, can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) + name='Bob Marley', roll_no='200030058', batch='2020', branch='CSE', cpi=8.5, id="200030058", can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) self.placement1 = Placement.objects.create( company_name='ABC Corp', compensation_CTC=1000000, tier='1', id=generateRandomString(), allowed_branch=["CSE", "EE"], allowed_batch=["2020"], contact_person_name="test", phone_number="1234567890", email="test1@test.com", email_verified=True, offer_accepted=True) @@ -59,11 +59,11 @@ class AdminView(APITestCase): id=generateRandomString(), student=self.student3, placement=self.placement1, resume="8BSLybntULgrPPm_beehyv.pdf") self.pa4 = PlacementApplication.objects.create( - id=generateRandomString(), student=self.student1, placement=self.placement2) + id=generateRandomString(), student=self.student1, placement=self.placement2, resume="8BSLybntULgrPPm_beehyv.pdf") self.pa5 = PlacementApplication.objects.create( - id=generateRandomString(), student=self.student2, placement=self.placement1) + id=generateRandomString(), student=self.student2, placement=self.placement1, resume="8BSLybntULgrPPm_beehyv.pdf") self.pa6 = PlacementApplication.objects.create( - id=generateRandomString(), student=self.student3, placement=self.placement2) + id=generateRandomString(), student=self.student3, placement=self.placement2, resume="8BSLybntULgrPPm_beehyv.pdf") self.ia1 = InternshipApplication.objects.create( id=generateRandomString(), student=self.student1, internship=self.internship1, resume="8BSLybntULgrPPm_beehyv.pdf") @@ -89,83 +89,116 @@ class AdminView(APITestCase): # self.assertEqual(response.status_code, status.HTTP_200_OK) # self.s_token = response.data['id_token'] - def test_get_stats(self): - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) - response = self.client.get(reverse('Get Stats')) - stats = response.data['stats'] - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(len(stats), 3) + # def test_get_stats(self): + # self.pa1.selected = True + # self.pa1.save() + # self.pa2.selected = True + # self.pa2.save() + # self.pa3.selected = True + # self.pa3.save() + # self.pa4.selected = True + # self.pa4.save() + # self.pa5.selected = True + # self.pa5.save() + # self.pa6.selected = True + # self.pa6.save() - # Check if the stats are correct for student1 - student1_stats = next( - (item for item in stats if item["id"] == self.student1.id), None) - self.assertEqual(student1_stats['name'], self.student1.name) - self.assertEqual(student1_stats['roll_no'], self.student1.roll_no) - self.assertEqual(student1_stats['batch'], self.student1.batch) - self.assertEqual(student1_stats['branch'], self.student1.branch) - self.assertEqual(student1_stats['cpi'], self.student1.cpi) - self.assertEqual( - student1_stats['first_offer'], self.placement1.company_name) - self.assertEqual( - student1_stats['first_offer_tier'], self.placement1.tier) - self.assertEqual( - student1_stats['first_offer_compensation'], self.placement1.compensation_CTC) - self.assertEqual( - student1_stats['second_offer'], self.placement2.company_name) - self.assertEqual( - student1_stats['second_offer_tier'], self.placement2.tier) - self.assertEqual( - student1_stats['second_offer_compensation'], self.placement2.compensation_CTC) + # self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + # response = self.client.get(reverse('Get Stats')) + # stats = response.data['stats'] + # self.assertEqual(response.status_code, status.HTTP_200_OK) + # self.assertEqual(len(stats), 4) - # Check if the stats are correct for student2 - student2_stats = next( - (item for item in stats if item["id"] == self.student2.id), None) - self.assertEqual(student2_stats['name'], self.student2.name) - self.assertEqual(student2_stats['roll_no'], self.student2.roll_no) - self.assertEqual(student2_stats['batch'], self.student2.batch) - self.assertEqual(student2_stats['branch'], self.student2.branch) - self.assertEqual(student2_stats['cpi'], self.student2.cpi) - self.assertEqual( - student2_stats['first_offer'], self.placement2.company_name) - self.assertEqual( - student2_stats['first_offer_tier'], self.placement2.tier) - self.assertEqual( - student2_stats['first_offer_compensation'], self.placement2.compensation_CTC) - self.assertEqual( - student2_stats['second_offer'], self.placement1.company_name) - self.assertEqual( - student2_stats['second_offer_tier'], self.placement1.tier) - self.assertEqual( - student2_stats['second_offer_compensation'], self.placement1.compensation_CTC) + # # Check if the stats are correct for student1 - # Check if the stats are correct for student3 - student3_stats = next( - (item for item in stats if item["id"] == self.student3.id), None) - self.assertEqual(student3_stats['name'], self.student3.name) - self.assertEqual(student3_stats['roll_no'], self.student3.roll_no) - self.assertEqual(student3_stats['batch'], self.student3.batch) - self.assertEqual(student3_stats['branch'], self.student3.branch) - self.assertEqual(student3_stats['cpi'], self.student3.cpi) - self.assertEqual(student3_stats['first_offer'], self.ppo2.company) - self.assertEqual(student3_stats['first_offer_tier'], self.ppo2.tier) - self.assertEqual( - student3_stats['first_offer_compensation'], self.ppo2.compensation) - self.assertEqual( - student3_stats['second_offer'], self.placement2.company_name) - self.assertEqual( - student3_stats['second_offer_tier'], self.placement2.tier) - self.assertEqual( - student3_stats['second_offer_compensation'], self.placement2.compensation_CTC) + # student1_stats = next( + # (item for item in stats if item["id"] == self.student1.id), None) + # self.assertEqual(student1_stats['name'], self.student1.name) + # self.assertEqual(student1_stats['roll_no'], self.student1.roll_no) + # self.assertEqual(student1_stats['batch'], self.student1.batch) + # self.assertEqual(student1_stats['branch'], self.student1.branch) + # self.assertEqual(student1_stats['cpi'], self.student1.cpi) + # self.assertEqual( + # student1_stats['first_offer'], self.placement1.company_name) + # self.assertEqual( + # student1_stats['first_offer_tier'], self.placement1.tier) + # self.assertEqual( + # student1_stats['first_offer_compensation'], self.placement1.compensation_CTC) + # self.assertEqual( + # student1_stats['second_offer'], self.placement2.company_name) + # self.assertEqual( + # student1_stats['second_offer_tier'], self.placement2.tier) + # self.assertEqual( + # student1_stats['second_offer_compensation'], self.placement2.compensation_CTC) - def test_get_stats_error(self): - # Test if an error is returned when an exception is raised - # by the view function - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) - response = self.client.get(reverse('Get Stats')) - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - self.assertEqual(response.data['message'], 'Something Went Wrong') + # # Check if the stats are correct for student2 + # student2_stats = next( + # (item for item in stats if item["id"] == self.student2.id), None) + # self.assertEqual(student2_stats['name'], self.student2.name) + # self.assertEqual(student2_stats['roll_no'], self.student2.roll_no) + # self.assertEqual(student2_stats['batch'], self.student2.batch) + # self.assertEqual(student2_stats['branch'], self.student2.branch) + # self.assertEqual(student2_stats['cpi'], self.student2.cpi) + # self.assertEqual( + # student2_stats['first_offer'], self.placement2.company_name) + # self.assertEqual( + # student2_stats['first_offer_tier'], self.placement2.tier) + # self.assertEqual( + # student2_stats['first_offer_compensation'], self.placement2.compensation_CTC) + # self.assertEqual( + # student2_stats['second_offer'], self.placement1.company_name) + # self.assertEqual( + # student2_stats['second_offer_tier'], self.placement1.tier) + # self.assertEqual( + # student2_stats['second_offer_compensation'], self.placement1.compensation_CTC) - def test_addPPO(self): + # # Check if the stats are correct for student3 + # student3_stats = next( + # (item for item in stats if item["id"] == self.student3.id), None) + # self.assertEqual(student3_stats['name'], self.student3.name) + # self.assertEqual(student3_stats['roll_no'], self.student3.roll_no) + # self.assertEqual(student3_stats['batch'], self.student3.batch) + # self.assertEqual(student3_stats['branch'], self.student3.branch) + # self.assertEqual(student3_stats['cpi'], self.student3.cpi) + # self.assertEqual(student3_stats['first_offer'], self.placement1.company_name) + # self.assertEqual(student3_stats['first_offer_tier'], self.placement1.tier) + # self.assertEqual( + # student3_stats['first_offer_compensation'], self.placement1.compensation_CTC) + # self.assertEqual( + # student3_stats['second_offer'], self.placement2.company_name) + # self.assertEqual( + # student3_stats['second_offer_tier'], self.placement2.tier) + # self.assertEqual( + # student3_stats['second_offer_compensation'], self.placement2.compensation_CTC) + + # # check if the stats are correct for student4 + # student4_stats = next( + # (item for item in stats if item["id"] == self.student4.id), None) + # self.assertEqual(student4_stats['name'], self.student4.name) + # self.assertEqual(student4_stats['roll_no'], self.student4.roll_no) + # self.assertEqual(student4_stats['batch'], self.student4.batch) + # self.assertEqual(student4_stats['branch'], self.student4.branch) + # self.assertEqual(student4_stats['cpi'], self.student4.cpi) + # self.assertEqual(student4_stats['first_offer'], None) + # self.assertEqual(student4_stats['first_offer_tier'], None) + # self.assertEqual( + # student4_stats['first_offer_compensation'], None) + # self.assertEqual( + # student4_stats['second_offer'], None) + # self.assertEqual( + # student4_stats['second_offer_tier'], None) + # self.assertEqual( + # student4_stats['second_offer_compensation'], None) + + # def test_get_stats_error(self): + # # Test if an error is returned when an exception is raised + # # by the view function + # self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + # response = self.client.get(reverse('Get Stats')) + # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + # self.assertEqual(response.data['message'], 'Something Went Wrong') + + def test_addPPO(self): # done url = reverse("Add PPO") data = { "student_id": self.student2.id, @@ -181,15 +214,15 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['message'], 'PPO added') self.assertEqual(PrePlacementOffer.objects.get( - student=self.student1).company, data['company']) + student=self.student2).company, data['company_name']) self.assertEqual(PrePlacementOffer.objects.get( - student=self.student1).compensation, data['compensation']) + student=self.student2).compensation, data['compensation_gross']) self.assertEqual(PrePlacementOffer.objects.get( - student=self.student1).tier, data['tier']) + student=self.student2).tier, data['tier']) self.assertEqual(PrePlacementOffer.objects.get( - student=self.student1).designation, data['designation']) + student=self.student2).designation, data['designation']) - def test_getStudentApplication(self): + def test_getStudentApplication(self): # done url = reverse("Get student application") data = { "student_id": self.student1.id, @@ -202,31 +235,41 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['application_info']["id"], self.pa1.id) self.assertEqual( - response.data['application_info']["resume"], self.pa1.resume) + response.data['application_info']["resume"]['link'][-26:], self.pa1.resume) self.assertEqual( response.data['application_info']["additional_info"], self.pa1.additional_info) - data["student_id"] = self.student4.id + self.assertEqual(response.data['application_found'], 'true') + + def test_getStudentApplication_notfound(self): + url = reverse("Get student application") + data = { + "student_id": self.student4.id, + "opening_id": self.placement1.id, + "opening_type": "Placement" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['application_found'], 'false') self.assertEqual( response.data["student_details"]["name"], self.student4.name) - data['student_id'] = generateRandomString() + + def test_getStudentApplication_wrongStudent(self): + url = reverse("Get student application") + data = { + "student_id": generateRandomString(), + "opening_id": self.placement1.id, + "opening_type": "Placement" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data["message"], 'Student not found') - # ---------------------------------------------- - # -------------------------------------------------checking for internships------------------- - # data[OPENING_TYPE]=INTERNSHIP - # response = self.client.post(url, data=json.dumps( - # data), content_type='application/json') - # self.assertEqual(response.status_code, status.HTTP_200_OK) - # self.assertEqual(len(response.data['application_info']), 2) + self.assertEqual(response.data["message"], 'Student not found.') def test_generateCSV(self): - url = reverse("Generate CSV") # not done + url = reverse("Generate CSV") # done data = { "opening_type": "Placement", "opening_id": self.placement1.id @@ -234,32 +277,275 @@ class AdminView(APITestCase): self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_200_OK) + # self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'CSV created') def test_submitApplication(self): url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + data = { "opening_type": "Placement", "opening_id": self.placement1.id, - "student_list": [{ - "student_id": self.student1.id, - "student_selected": True - }, { - "student_id": self.student2.id, - "student_selected": False - }] + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "additional_info": [], + "application_id": "" } + # data["opening_id"] = generateRandomString() + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application added') + self.assertEqual(PlacementApplication.objects.filter( + student=self.student4).count(), 1) + + # handle double creation of application + + def test_submitApplication_without_adinfo(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + self.placement1.additional_info = ["test"] + self.placement1.save() + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "additional_info": [], + "application_id": "" + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], 'test not found in Additional Info') + + def test_submitApplication_with_adinfo(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + self.placement1.additional_info = ["test"] + self.placement1.save() + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "additional_info": {"test": "test"}, + "application_id": "" + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application added') + self.assertEqual(PlacementApplication.objects.filter( + student=self.student4).count(), 1) + self.assertEqual(PlacementApplication.objects.get( + student=self.student4, placement=self.placement1).additional_info, json.dumps(data['additional_info'])) + + def test_submitApplication_with_wrong_resume(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv1.pdf", + "application_id": "", + "additional_info": [] + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'resume_file_name Not Found') + + def test_submitApplication_with_wrongOpening(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + data = { + "opening_type": "Placement", + "opening_id": generateRandomString(), + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "application_id": "", + "additional_info": [] + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No Placement matches the given query.') + + def test_submitApplication_with_wrongStudent(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": generateRandomString(), + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "application_id": "", + "additional_info": [] + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No Student matches the given query.') + + def test_submitApplicatioin_with_application(self): + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "additional_info": [], + "application_id": self.pa1.id + } + url = reverse("Submit Application") self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Application Submitted') + self.assertEqual(response.data['message'], 'Application updated') self.assertEqual(PlacementApplication.objects.get( - student=self.student1).selected, True) - self.assertEqual(PlacementApplication.objects.get( # note done yet - student=self.student2).selected, False) + student=self.student1, placement=self.placement1).resume, data['resume_file_name']) - def test_getApplications(self): # has issues check it once + def test_submitApplication_with_application_without_adinfo(self): + self.placement1.additional_info = ["test"] + self.placement1.save() + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "additional_info": [], + "application_id": self.pa1.id + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], 'test not found in Additional Info') + + def test_submitApplication_with_application_with_adinfo(self): + self.placement1.additional_info = ["test"] + self.placement1.save() + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "additional_info": {"test": "test"}, + "application_id": self.pa1.id + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + # self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application updated') + self.assertEqual(PlacementApplication.objects.get( + student=self.student1, placement=self.placement1).resume, data['resume_file_name']) + self.assertEqual(PlacementApplication.objects.get( + student=self.student1, placement=self.placement1).additional_info, json.dumps(data['additional_info'])) + + def test_submitApplication_with_application_with_wrong_resume(self): + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera1.pdf", + "application_id": self.pa1.id, + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'resume_file_name Not Found') + + def test_submitApplication_with_application_with_wrongapplication(self): + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "application_id": generateRandomString(), + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No PlacementApplication matches the given query.') + + def test_submitApplication_with_application_with_wrongOpening(self): + data = { + "opening_type": "Placement", + "opening_id": generateRandomString(), + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "application_id": self.pa1.id, + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No Placement matches the given query.') + + def test_submitApplication_with_application_with_wrongStudent(self): + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": generateRandomString(), + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "application_id": self.pa1.id, + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No Student matches the given query.') + + def test_submitApplication_with_application_without_corresponding_student(self): + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "application_id": self.pa1.id, + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'resume_file_name Not Found') # this is a malfunctioning test case + + +# -----------------------------done submit application placement + + + def test_getApplications(self): # done url = reverse("Get Applications") data = { "opening_type": "Placement", @@ -267,7 +553,7 @@ class AdminView(APITestCase): } self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.get(url, data) - # self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['message'], 'Data Found') self.assertEqual(len(response.data['applications']), 3) applications_students = [] @@ -275,14 +561,26 @@ class AdminView(APITestCase): response.data['applications'][0]['student_details']["id"]) applications_students.append( response.data['applications'][1]['student_details']["id"]) + applications_students.append( + response.data['applications'][2]['student_details']["id"]) self.assertIn(self.student1.id, applications_students) self.assertIn(self.student2.id, applications_students) - data['opening_id'] = generateRandomString() + self.assertIn(self.student3.id, applications_students) + + def test_getApplications_error(self): + url = reverse("Get Applications") + data = { + "opening_type": "Placement", + "opening_id": generateRandomString() + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.get(url, data) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') -# -done +# done getApplications......... + +# # -done def test_addAdditionalInfo(self): url = reverse("Add Additional Info") data = { @@ -297,19 +595,42 @@ class AdminView(APITestCase): self.assertEqual(response.data['message'], 'Additional Info Added') self.assertIn(data['field'], Placement.objects.get( id=self.placement1.id).additional_info) + + def test_addAdditional_info_with_wrongOpening(self): + url = reverse("Add Additional Info") + data = { + "opening_type": "Placement", + "opening_id": generateRandomString(), + "field": "Test Field" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_addAdditional_info_existing(self): + url = reverse("Add Additional Info") + self.placement1.additional_info = ["Test Field"] + self.placement1.save() + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "field": "Test Field" + } + + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data['message'], 'Additional Info already found') self.assertIn(data['field'], Placement.objects.get( id=self.placement1.id).additional_info) - data['opening_id'] = generateRandomString() - response = self.client.post(url, data=json.dumps( - data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['message'], 'Opening Not Found') +# done add additional info def test_deleteAdditionalInfo(self): self.placement1.additional_info = ["Test Field"] self.placement1.save() @@ -328,14 +649,38 @@ class AdminView(APITestCase): id=self.placement1.id).additional_info) response = self.client.post(url, data=json.dumps( data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['message'], 'Additional Info not found') - data['opening_id'] = generateRandomString() + + def test_deletetAdditional_info_with_wrongOpening(self): + url = reverse("Delete Additional Info") + data = { + "opening_type": "Placement", + "opening_id": generateRandomString(), + "field": "Test Field" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') + def test_deletetAdditional_info_with_wrongField(self): + url = reverse("Delete Additional Info") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "field": "Test Field" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Additional Info not found') + + +# done delete + def test_updateEmailVerified(self): # done url = reverse("Update Email Verified") self.placement1.email_verified = False @@ -352,12 +697,23 @@ class AdminView(APITestCase): self.assertEqual(response.data['message'], 'Email Verified Updated') self.assertEqual(Placement.objects.get( id=self.placement1.id).email_verified, True) - data['opening_id'] = generateRandomString() + + def test_updateEmailVerified_WrongOpening(self): + url = reverse("Update Email Verified") + data = { + "opening_type": "Placement", + "opening_id": generateRandomString(), + "email_verified": "true" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') +# done update email verified + def test_updateofferAccepted(self): # done url = reverse("Update Offer Accepted") self.placement1.offer_accepted = None @@ -378,28 +734,78 @@ class AdminView(APITestCase): id=self.placement1.id).offer_accepted, True) self.assertEqual(Placement.objects.get( id=self.placement1.id).deadline_datetime, timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=2)) - data['opening_id'] = self.placement3.id - data[DEADLINE_DATETIME] = (timezone.now().replace( - hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + + def test_offerAccepted_withDeadline(self): + url = reverse("Update Offer Accepted") + data = { + "opening_type": "Placement", + "opening_id": self.placement3.id, + "offer_accepted": "true", + "deadline_datetime": (timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + } + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(Placement.objects.get( id=self.placement3.id).deadline_datetime, timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)) self.assertEqual(response.data['message'], 'Offer Accepted Updated') + + def test_offerAccepted_wrongOpening(self): + url = reverse("Update Offer Accepted") + data = { + "opening_type": "Placement", + "opening_id": generateRandomString(), + "offer_accepted": "true", + "deadline_datetime": (timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + } + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Opening Not Found') + + def test_offerAccepted_rejectedOpening(self): + url = reverse("Update Offer Accepted") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "offer_accepted": "true" + } self.placement1.offer_accepted = False self.placement1.save() - data["opening_id"] = self.placement1.id + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data['message'], 'Offer Status already updated') - data['opening_id'] = generateRandomString() + + def test_offerAccepted_acceptedOpening(self): + url = reverse("Update Offer Accepted") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "offer_accepted": "true" + } + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['message'], 'Opening Not Found') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], 'Offer Status already updated') +# updated offerAccepted def test_updateDeadline(self): # done url = reverse("Update Deadline") @@ -416,13 +822,23 @@ class AdminView(APITestCase): self.assertEqual(response.data['message'], 'Deadline Updated') self.assertEqual(Placement.objects.get( id=self.placement1.id).deadline_datetime.strftime('%Y-%m-%d %H:%M:%S %z'), data['deadline_datetime']) - data['opening_id'] = generateRandomString() + + def test_updateDeadline_with_wrongOpening(self): + url = reverse("Update Deadline") + data = { + "opening_type": "Placement", + "opening_id": generateRandomString(), + "deadline_datetime": (timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') - self.placement1.refresh_from_db() + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') +# updated update deadline + def test_markStatus(self): # done url = reverse("Mark Status") data = { @@ -447,25 +863,47 @@ class AdminView(APITestCase): self.assertEqual(PlacementApplication.objects.get( student=student['student_id'], placement=self.placement1).selected, data['student_list'][i]['student_selected']) i += 1 - data['student_list'] = [{ - "student_id": self.student4.id, - "student_selected": True - }] - response = self.client.post(url, data=json.dumps( - data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - self.assertEqual( - response.data['message'], "Student - " + str(self.student4.id) + " didn't apply for this opening") - data['student_list'] = [{ - "student_id": self.student1.id, - "student_selected": True - }] + + def test_markStatus_Alreadyselected(self): + url = reverse("Mark Status") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_list": [{ + "student_id": self.student1.id, + "student_selected": True + }] + + } + self.pa1.selected = True + self.pa1.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data['message'], "Student already selected") + def test_markstatus_notApplied(self): + url = reverse("Mark Status") + data = { + "opening_type": "Placement", + "opening_id": self.placement1.id, + "student_list": [{ + "student_id": self.student4.id, + "student_selected": True + }] + + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], "Student - " + str(self.student4.id) + " didn't apply for this opening") + + # done markStatus + def test_get_dashboard(self): # working url = reverse("Get Dashboard") self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) @@ -495,38 +933,57 @@ class AdminView(APITestCase): self.assertEqual( response.data['new_internships'][0]['id'], self.internship3.id) - # -------------------------------------------------checking for internships------------------- +# # -------------------------------------------------checking for internships------------------- - def test_getStudentApplication_internship(self): # not done + def test_getStudentApplication_internship(self): # done url = reverse("Get student application") data = { "student_id": self.student1.id, "opening_id": self.internship1.id, - "opening_type": "Placement" + "opening_type": "Internship" } - self.assertEqual(Student.objects.filter( - id=self.student1.id).count(), 1) + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) - response = self.client.post(url, data, content_type='application/json') - # self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Data Found') + response = self.client.post(url, json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['application_found'], 'true') self.assertEqual(response.data['application_info']["id"], self.ia1.id) self.assertEqual( - response.data['application_info']["resume"], self.ia1.resume) + response.data['application_info']["resume"]['link'][-26:], self.ia1.resume) self.assertEqual( response.data['application_info']["additional_info"], self.ia1.additional_info) - data["student_id"] = self.student4.id - response = self.client.post(url, data=json.dumps( + + def test_getStudentApplication_internship_notfound(self): + url = reverse("Get student application") + data = { + "student_id": self.student4.id, + "opening_id": self.internship1.id, + "opening_type": "Internship" + } + + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['application_found'], 'false') self.assertEqual( response.data["student_details"]["name"], self.student4.name) - data['student_id'] = generateRandomString() - response = self.client.post(url, data=json.dumps( + + def test_getStudentApplication_internship_wrongstudent(self): + url = reverse("Get student application") + data = { + "student_id": generateRandomString(), + "opening_id": self.internship1.id, + "opening_type": "Internship" + } + + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data["message"], 'Student not found') + # self.assertEqual(response.data['application_found'], 'false') + self.assertEqual(response.data["message"], 'Student not found.') def test_generateCSV_internship(self): # done url = reverse("Generate CSV") @@ -539,30 +996,6 @@ class AdminView(APITestCase): data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_200_OK) - def test_submitApplication_internship(self): - url = reverse("Submit Application") - data = { - "opening_type": "Internship", - "opening_id": self.internship1.id, - "student_list": [{ - "student_id": self.student1.id, - "student_selected": True - }, { - "student_id": self.student2.id, - "student_selected": False - }] - } - self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) - response = self.client.post(url, data=json.dumps( - data), content_type='application/json') - - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Application Submitted') - self.assertEqual(InternshipApplication.objects.get( - student=self.student1).selected, True) - self.assertEqual(InternshipApplication.objects.get( # note done yet - student=self.student2).selected, False) - def test_getApplications_internship(self): # done url = reverse("Get Applications") data = { @@ -586,13 +1019,19 @@ class AdminView(APITestCase): self.assertIn(str(self.student2.id), applications_students) self.assertIn(str(self.student3.id), applications_students) - data['opening_id'] = generateRandomString() + def test_getApplications_internship_error(self): + url = reverse("Get Applications") + data = { + "opening_type": "Internship", + "opening_id": generateRandomString() + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.get(url, data) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') -# -working +# # -working def test_addAdditionalInfo_internship(self): url = reverse("Add Additional Info") data = { @@ -608,18 +1047,37 @@ class AdminView(APITestCase): self.assertEqual(response.data['message'], 'Additional Info Added') self.assertIn(data['field'], Internship.objects.get( id=self.internship1.id).additional_info) + + def test_addAdditionalInfo_internship_existing(self): + url = reverse("Add Additional Info") + self.internship1.additional_info = ["Test Field"] + self.internship1.save() + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "field": "Test Field" + } + + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data['message'], 'Additional Info already found') self.assertIn(data['field'], Internship.objects.get( id=self.internship1.id).additional_info) - data['opening_id'] = generateRandomString() + + def test_addAdditionalInfo_internship_wrongOpening(self): + url = reverse("Add Additional Info") + data = { + "opening_type": "Internship", + "opening_id": generateRandomString(), + "field": "Test Field" + } + + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') @@ -640,18 +1098,37 @@ class AdminView(APITestCase): self.assertEqual(response.data['message'], 'Additional Info Deleted') self.assertNotIn(data['field'], Internship.objects.get( id=self.internship1.id).additional_info) - response = self.client.post(url, data=json.dumps( - data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['message'], 'Additional Info not found') - data['opening_id'] = generateRandomString() + def test_deleteAdditionalInfo_internship_With_wrongOpening(self): + url = reverse("Delete Additional Info") + data = { + "opening_type": "Internship", + "opening_id": generateRandomString(), + "field": "Test Field" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') + def test_deleteAdditionalInfo_internship_with_wrong_field(self): + self.internship1.additional_info = ["Test Field"] + self.internship1.save() + url = reverse("Delete Additional Info") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "field": "Test Field1" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'Additional Info not found') + def test_updateEmailVerified_internship(self): # done url = reverse("Update Email Verified") self.internship1.email_verified = False @@ -669,7 +1146,15 @@ class AdminView(APITestCase): self.assertEqual(response.data['message'], 'Email Verified Updated') self.assertEqual(Internship.objects.get( id=self.internship1.id).email_verified, True) - data['opening_id'] = generateRandomString() + + def test_updateEmailVerified_internship_wrongOpening(self): + url = reverse("Update Email Verified") + data = { + "opening_type": "Internship", + "opening_id": generateRandomString(), + "email_verified": "true" + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') @@ -692,11 +1177,18 @@ class AdminView(APITestCase): self.assertEqual(response.data['message'], 'Deadline Updated') self.assertEqual(Internship.objects.get( id=self.internship1.id).deadline_datetime.strftime('%Y-%m-%d %H:%M:%S %z'), data['deadline_datetime']) - data['opening_id'] = generateRandomString() + + def test_updateDeadline_with_wrongOpening(self): + url = reverse("Update Deadline") + data = { + "opening_type": "Internship", + "opening_id": generateRandomString(), + "deadline_datetime": (timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') - self.internship1.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') @@ -721,37 +1213,82 @@ class AdminView(APITestCase): self.internship1.refresh_from_db() self.assertEqual(self.internship1.deadline_datetime, timezone.now().replace( hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=2)) - data['opening_id'] = self.internship3.id - data[DEADLINE_DATETIME] = (timezone.now().replace( - hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + + def test_updateofferAccepted_withDeadline_internship(self): + url = reverse("Update Offer Accepted") + data = { + "opening_type": "Internship", + "opening_id": self.internship3.id, + "offer_accepted": "true", + "deadline_datetime": (timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + } + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') + self.internship3.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(Internship.objects.get( - id=self.internship3.id).offer_accepted, True) self.assertEqual(Internship.objects.get( id=self.internship3.id).deadline_datetime, timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)) self.assertEqual(response.data['message'], 'Offer Accepted Updated') - self.internship1.offer_accepted = False - self.internship1.save() - data["opening_id"] = self.internship1.id - response = self.client.post(url, data=json.dumps( - data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - self.assertEqual( - response.data['message'], 'Offer Status already updated') - data["opening_id"] = self.internship2.id - response = self.client.post(url, data=json.dumps( - data), content_type='application/json') - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - self.assertEqual( - response.data['message'], 'Offer Status already updated') - data['opening_id'] = generateRandomString() + + def test_updateofferAccepted_wrongOpening_internship(self): + url = reverse("Update Offer Accepted") + data = { + "opening_type": "Internship", + "opening_id": generateRandomString(), + "offer_accepted": "true", + "deadline_datetime": (timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') + } + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Opening Not Found') + def test_updateofferAccepted_rejectedOpening_internship(self): + url = reverse("Update Offer Accepted") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "offer_accepted": "true" + } + self.internship1.offer_accepted = False + self.internship1.save() + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.internship1.refresh_from_db() + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], 'Offer Status already updated') + + def test_updateofferAccepted_acceptedOpening_internship(self): + url = reverse("Update Offer Accepted") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "offer_accepted": "true" + } + + self.admin.user_type = ["s_admin"] + self.admin.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.internship1.refresh_from_db() + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], 'Offer Status already updated') + def test_markStatus_internship(self): # done url = reverse("Mark Status") data = { @@ -776,24 +1313,304 @@ class AdminView(APITestCase): self.assertEqual(InternshipApplication.objects.get( student=student['student_id'], internship=self.internship1).selected, data['student_list'][i]['student_selected']) i += 1 - data['student_list'] = [{ - "student_id": self.student4.id, - "student_selected": True - }] + + def test_markStatus_Internship_alreadySelected(self): + url = reverse("Mark Status") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_list": [{ + "student_id": self.student1.id, + "student_selected": True + }] + } + self.ia1.selected = True + self.ia1.save() + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], "Student already selected") + + def test_mark_status_Internship_notApplied(self): + url = reverse("Mark Status") + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_list": [{ + "student_id": self.student4.id, + "student_selected": True + }] + } + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data['message'], "Student - " + str(self.student4.id) + " didn't apply for this opening") - data['student_list'] = [{ - "student_id": self.student1.id, - "student_selected": True - }] + + +# # --------------------------------------------------------------------------- + + + def test_submitApplication_internship(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "additional_info": [], + "application_id": "" + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application added') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student4).count(), 1) + + # handle double creation of application + + def test_submitApplication_without_adinfo_internship(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + self.internship1.additional_info = ["test"] + self.internship1.save() + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "additional_info": [], + "application_id": "" + } response = self.client.post(url, data=json.dumps( data), content_type='application/json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( - response.data['message'], "Student already selected") + response.data['message'], 'test not found in Additional Info') + def test_submitApplication_with_adinfo_internship(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + self.internship1.additional_info = ["test"] + self.internship1.save() + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "additional_info": {"test": "test"}, + "application_id": "" + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application added') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student4).count(), 1) + self.assertEqual(InternshipApplication.objects.get( + student=self.student4, internship=self.internship1).additional_info, json.dumps(data['additional_info'])) -# --------------------------------------------------------------------------- + def test_submitApplication_with_wrong_resume_internship(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv1.pdf", + "application_id": "", + "additional_info": [] + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'resume_file_name Not Found') + + def test_submitApplication_with_wrongOpening_internship(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + data = { + "opening_type": "Internship", + "opening_id": generateRandomString(), + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "application_id": "", + "additional_info": [] + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No Internship matches the given query.') + + def test_submitApplication_with_wrongStudent_internship(self): + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": generateRandomString(), + "resume_file_name": "8BSLybntULgrPPm_beehyv.pdf", + "application_id": "", + "additional_info": [] + } + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No Student matches the given query.') + + def test_submitApplicatioin_with_application_internship(self): + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "additional_info": [], + "application_id": self.ia1.id + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application updated') + self.assertEqual(InternshipApplication.objects.get( + student=self.student1, internship=self.internship1).resume, data['resume_file_name']) + + def test_submitApplication_with_application_without_adinfo_internship(self): + self.internship1.additional_info = ["test"] + self.internship1.save() + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "additional_info": [], + "application_id": self.ia1.id + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual( + response.data['message'], 'test not found in Additional Info') + + def test_submitApplication_with_application_with_adinfo_internship(self): + self.internship1.additional_info = ["test"] + self.internship1.save() + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "additional_info": {"test": "test"}, + "application_id": self.ia1.id + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + # self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application updated') + self.assertEqual(InternshipApplication.objects.get( + student=self.student1, internship=self.internship1).resume, data['resume_file_name']) + self.assertEqual(InternshipApplication.objects.get( + student=self.student1, internship=self.internship1).additional_info, json.dumps(data['additional_info'])) + + def test_submitApplication_with_application_with_wrong_resume_internship(self): + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera1.pdf", + "application_id": self.ia1.id, + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'resume_file_name Not Found') + + def test_submitApplication_with_application_with_wrongapplication_internship(self): + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "application_id": generateRandomString(), + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No InternshipApplication matches the given query.') + + def test_submitApplication_with_application_with_wrongOpening_internship(self): + data = { + "opening_type": "Internship", + "opening_id": generateRandomString(), + "student_id": self.student1.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "application_id": self.ia1.id, + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No Internship matches the given query.') + + def test_submitApplication_with_application_with_wrongStudent_internship(self): + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": generateRandomString(), + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "application_id": self.ia1.id, + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No Student matches the given query.') + + def test_submitApplication_with_application_without_corresponding_student_internship(self): + data = { + "opening_type": "Internship", + "opening_id": self.internship1.id, + "student_id": self.student4.id, + "resume_file_name": "8BSLybntULgrPPm_kalera.pdf", + "application_id": self.ia1.id, + "additional_info": [] + } + url = reverse("Submit Application") + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) + response = self.client.post(url, data=json.dumps( + data), content_type='application/json') + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'resume_file_name Not Found') # this is a malfunctioning test case diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py index 6643991..a799bf0 100644 --- a/CDC_Backend/APIs/tests/test_studentView.py +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -20,151 +20,48 @@ class StudentViewsTestCase(APITestCase): self.assertEqual( self.user.email, User.objects.get(id=self.user.id).email) self.student = Student.objects.create( - name="Test Student", - id=self.user.id, - resumes=["8BSLybntULgrPPm_beehyv.pdf"], - # email="test@student.com", - # password="testpassword", - roll_no="200010052", - branch="CSE", - batch="2020", - phone_number="1234567890", - # resume_link="https://testresume.com" - changed_by=self.user, - can_apply=True, - can_apply_internship=True, - degree="bTech", - cpi=7.95, + name="Test Student", id=self.user.id, resumes=["8BSLybntULgrPPm_beehyv.pdf"], roll_no=str(os.environ.get("roll_no")), branch="CSE", batch="2020", phone_number="1234567890", changed_by=self.user, can_apply=True, + can_apply_internship=True, degree="bTech", cpi=7.95, ) self.assertEqual(self.student.name, Student.objects.get(id=self.student.id).name) - # self.user=User.objects.filter(email="200010052@iitdh.ac.in").first() - # self.student = Student.objects.filter(id=self.user.id).first() self.internship = Internship.objects.create( - company_name="Test Company", - id=generateRandomString(), - website="https://testwebsite.com", - address="Test Address", - company_type="Test Company Type", - offer_accepted=True, - season=["Summer"], - allowed_branch=["CSE"], - allowed_batch=["2020"], - contact_person_name="Test Contact Person", - phone_number="1234567890", - email="test@test.com", - email_verified=True, - deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, - microsecond=0) + timezone.timedelta(days=1), - # location="Test Location", - stipend=10000, - # apply_link="https://testapplylink.com" + company_name="Test Company", id=generateRandomString(), website="https://testwebsite.com", address="Test Address", company_type="Test Company Type", offer_accepted=True, season=["Summer"], allowed_branch=["CSE"], + allowed_batch=["2020"], contact_person_name="Test Contact Person", phone_number="1234567890", email="test@test.com", email_verified=True, stipend=10000, ) - # self.assertEqual(self.internship.company_name, Internship.objects.get(self.internship.id).company_name) - # self.internship1 =Internship.objects.create( - # company_name="Test Company1", - # id=generateRandomString(), - # website="https://testwebsite1.com", - # address="Test Address1", - # company_type="Test Company Type1", - # offer_accepted=True, - # season=["Summer"], - # allowed_branch=["CSE"], - # allowed_batch=["2020"], - # contact_person_name="Test Contact Person1", - # phone_number="1234567890", - # email="test@test1.com", - # email_verified=True, - # deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), - # stipend=10000, - # ) self.placement = Placement.objects.create( - company_name="Test Company", - id=generateRandomString(), - website="https://testwebsite.com", - address="Test Address", - company_type="Test Company Type", - offer_accepted=True, - tier="6", - # season="Summer", - allowed_branch=["CSE"], - allowed_batch=["2020"], - contact_person_name="Test Contact Person", - phone_number="1234567890", - email="test@test.com", - email_verified=True, - deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, - microsecond=0) + timezone.timedelta(days=1), + company_name="Test Company", id=generateRandomString(), website="https://testwebsite.com", address="Test Address", company_type="Test Company Type", offer_accepted=True, tier="6", allowed_branch=["CSE"], allowed_batch=["2020"], + contact_person_name="Test Contact Person", phone_number="1234567890", email="test@test.com", email_verified=True, + ) - # self.placement1 = Placement.objects.create( - # company_name="Test Company1", - # id=generateRandomString(), - # website="https://testwebsite1.com", - # address="Test Address1", - # company_type="Test Company Type1", - # offer_accepted=True, - # tier="7", - # # season="Summer", - # allowed_branch=["CSE"], - # allowed_batch=["2020"], - # contact_person_name="Test Contact Person1", - # phone_number="1234567890", - # email="test@test1.com", - # email_verified=True, - # deadline_datetime=timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=1), - # ) - # self.assertEqual(self.placement.tier,"1") + self.assertEqual(self.placement.company_name, Placement.objects.get( id=self.placement.id).company_name) + self.internship_application = InternshipApplication.objects.create( - id=generateRandomString(), - internship=self.internship, - student=self.student, - resume="8BSLybntULgrPPm_beehyv.pdf", - selected=True - # status="Applied" + id=generateRandomString(), internship=self.internship, student=self.student, resume="8BSLybntULgrPPm_beehyv.pdf", selected=True + ) - # self.internship_application1=InternshipApplication.objects.create( - # id=generateRandomString(), - # internship=self.internship1, - # student=self.student, - # resume="8BSLybntULgrPPm_beehyv.pdf" - # ) + self.assertEqual(self.internship_application.internship.company_name, InternshipApplication.objects.get( id=self.internship_application.id).internship.company_name) self.placement_application = PlacementApplication.objects.create( - id=generateRandomString(), - placement=self.placement, - student=self.student, - resume="8BSLybntULgrPPm_beehyv.pdf", - selected=True - # status="Applied" + id=generateRandomString(), placement=self.placement, student=self.student, resume="8BSLybntULgrPPm_beehyv.pdf", selected=True + ) - # self.placement_application1 = PlacementApplication.objects.create( - # id=generateRandomString(), - # placement=self.placement1, - # student=self.student, - # resume="8BSLybntULgrPPm_beehyv.pdf", - # # selected=True - # # status="Applied" - # ) + self.assertEqual(self.placement_application.placement.company_name, PlacementApplication.objects.get( id=self.placement_application.id).placement.company_name) self.issue = Issues.objects.create( - student=self.student, - title="Test Issue", - description="Test Issue Description", - opening_id=self.internship.id, + student=self.student, title="Test Issue", description="Test Issue Description", opening_id=self.internship.id, opening_type=INTERNSHIP ) + # get token from google OAuth API response = self.client.post(reverse('Refresh Token'), { 'refresh_token': os.environ.get("refresh_token")}, format='json') self.student_token = response.data['id_token'] - # self.student_token = get_access_token_id(os.environ.get("refresh_token")) - - # self.contributor_token = get_token(self.contributor.email, "testpassword", CONTRIBUTOR) def test_student_accept_offer_internship(self): url = reverse('Student Accept Offer') @@ -180,10 +77,19 @@ class StudentViewsTestCase(APITestCase): self.assertEqual(response.data['message'], 'Updated Offer Status') self.assertEqual(InternshipApplication.objects.get( id=self.internship_application.id).offer_accepted, True) + + def test_student_accept_offer_internship_notFound(self): + url = reverse('Student Accept Offer') + data = { + 'opening_id': self.internship.id, + 'offer_accepted': True, + 'opening_type': INTERNSHIP + } self.internship_application.selected = False self.internship_application.offer_accepted = False self.internship_application.save() - + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Offer Not Found') @@ -203,68 +109,89 @@ class StudentViewsTestCase(APITestCase): self.assertEqual(response.data['message'], 'Application Deleted') self.assertEqual(InternshipApplication.objects.filter( id=self.internship_application.id).count(), 0) + + def test_delete_application_internship_deadlinePassed(self): + url = reverse('Delete Application') + data = { + 'application_id': self.internship_application.id, + 'opening_type': INTERNSHIP + } self.internship.deadline_datetime = timezone.now().replace( hour=0, minute=0, second=0, microsecond=0) self.internship.save() - self.internship_application = InternshipApplication.objects.create(id=generateRandomString(), - internship=self.internship, - student=self.student, - resume="8BSLybntULgrPPm_beehyv.pdf", - selected=True) - data['application_id'] = self.internship_application.id + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.data['message'], 'Deadline Passed') self.assertEqual(InternshipApplication.objects.filter( id=self.internship_application.id).count(), 1) - def test_add_application_internship(self): + def test_delete_application_internship_notFound(self): url = reverse('Delete Application') data = { 'application_id': self.internship_application.id, 'opening_type': INTERNSHIP } + self.internship_application.delete() self.client.credentials( HTTP_AUTHORIZATION='Bearer ' + self.student_token) response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Application Deleted') + self.assertEqual(response.status_code, + status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No InternshipApplication matches the given query.') self.assertEqual(InternshipApplication.objects.filter( id=self.internship_application.id).count(), 0) - # deleted existing application - url = reverse('Add Application') - data = { - OPENING_ID: self.internship.id, - OPENING_TYPE: INTERNSHIP, - RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf' - } - self.client.credentials( - HTTP_AUTHORIZATION='Bearer ' + self.student_token) - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Application Submitted') - self.assertEqual(InternshipApplication.objects.filter( - student=self.student).count(), 1) - self.internship_application = InternshipApplication.objects.filter( - student=self.student) - self.internship.deadline_datetime = timezone.now().replace( - hour=0, minute=0, second=0, microsecond=0) - self.internship.save() - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - self.assertEqual(response.data['message'], - 'Application is already Submitted') - self.assertEqual(InternshipApplication.objects.filter( - student=self.student).count(), 1) - self.internship_application.delete() - data[OPENING_ID] = generateRandomString() - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) - self.assertEqual(response.data['message'], - 'No Internship matches the given query.') - self.assertEqual(InternshipApplication.objects.filter( - student=self.student).count(), 0) + # def test_add_application_internship(self): + # url = reverse('Delete Application') + # data = { + # 'application_id': self.internship_application.id, + # 'opening_type': INTERNSHIP + # } + # self.client.credentials( + # HTTP_AUTHORIZATION='Bearer ' + self.student_token) + # response = self.client.post(url, data, format='json') + # self.assertEqual(response.status_code, status.HTTP_200_OK) + # self.assertEqual(response.data['message'], 'Application Deleted') + # self.assertEqual(InternshipApplication.objects.filter( + # id=self.internship_application.id).count(), 0) + # # deleted existing application + # url = reverse('Add Application') + # data = { + # OPENING_ID: self.internship.id, + # OPENING_TYPE: INTERNSHIP, + # RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + # ADDITIONAL_INFO: [] + # } + # self.client.credentials( + # HTTP_AUTHORIZATION='Bearer ' + self.student_token) + # response = self.client.post(url, data, format='json') + # self.assertEqual(response.status_code, status.HTTP_200_OK) + # self.assertEqual(response.data['message'], 'Application Submitted') + # self.assertEqual(InternshipApplication.objects.filter( + # student=self.student).count(), 1) + # self.internship_application = InternshipApplication.objects.filter( + # student=self.student) + # # self.internship.deadline_datetime = timezone.now().replace( + # # hour=0, minute=0, second=0, microsecond=0) + # # self.internship.save() + + # response = self.client.post(url, data, format='json') + # self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + # self.assertEqual(response.data['message'], + # 'Application is already Submitted') + # self.assertEqual(InternshipApplication.objects.filter( + # student=self.student).count(), 1) + # self.internship_application.delete() + # data[OPENING_ID] = generateRandomString() + # response = self.client.post(url, data, format='json') + # self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + # self.assertEqual(response.data['message'], + # 'No Internship matches the given query.') + # self.assertEqual(InternshipApplication.objects.filter( + # student=self.student).count(), 0) def test_student_accept_offer_placement(self): url = reverse('Student Accept Offer') @@ -280,12 +207,26 @@ class StudentViewsTestCase(APITestCase): self.assertEqual(response.data['message'], 'Updated Offer Status') self.assertEqual(PlacementApplication.objects.get( id=self.placement_application.id).offer_accepted, True) + + def test_student_accept_offer_placement_offerNotFound(self): + url = reverse('Student Accept Offer') + data = { + 'opening_id': self.placement.id, + 'offer_accepted': True, + 'opening_type': PLACEMENT + } self.placement_application.selected = False self.placement_application.offer_accepted = False self.placement_application.save() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + + self.assertEqual(response.status_code, + status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], 'Offer Not Found') + self.assertEqual(PlacementApplication.objects.filter( + id=self.placement_application.id, selected=True).count(), 0) self.assertEqual(PlacementApplication.objects.get( id=self.placement_application.id).offer_accepted, False) @@ -302,40 +243,54 @@ class StudentViewsTestCase(APITestCase): self.assertEqual(response.data['message'], 'Application Deleted') self.assertEqual(PlacementApplication.objects.filter( id=self.placement_application.id).count(), 0) - self.placement.deadline_datetime = timezone.now().replace( - hour=0, minute=0, second=0, microsecond=0) - self.placement.save() - self.placement_application = PlacementApplication.objects.create(id=generateRandomString(), - placement=self.placement, - student=self.student, - resume="8BSLybntULgrPPm_beehyv.pdf", - selected=True) - data['application_id'] = self.placement_application.id - response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - self.assertEqual(response.data['message'], 'Deadline Passed') - self.assertEqual(PlacementApplication.objects.filter( - id=self.placement_application.id).count(), 1) - def test_add_application_placement(self): + def test_delete_application_placement_notFound(self): url = reverse('Delete Application') data = { 'application_id': self.placement_application.id, 'opening_type': PLACEMENT } + self.placement_application.delete() self.client.credentials( HTTP_AUTHORIZATION='Bearer ' + self.student_token) response = self.client.post(url, data, format='json') - self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(response.data['message'], 'Application Deleted') + + self.assertEqual(response.status_code, + status.HTTP_404_NOT_FOUND) + self.assertEqual( + response.data['message'], 'No PlacementApplication matches the given query.') self.assertEqual(PlacementApplication.objects.filter( id=self.placement_application.id).count(), 0) + + def test_delete_application_placement_deadlinePassed(self): + url = reverse('Delete Application') + data = { + 'application_id': self.placement_application.id, + 'opening_type': PLACEMENT + } + self.placement.deadline_datetime = timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0) + self.placement.save() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + + self.assertEqual(response.status_code, + status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], 'Deadline Passed') + self.assertEqual(PlacementApplication.objects.filter( + id=self.placement_application.id).count(), 1) + + def test_add_application_placement(self): + self.placement.additional_info = ["Test"] + self.placement_application.delete() # deleted existing application url = reverse('Add Application') data = { OPENING_ID: self.placement.id, OPENING_TYPE: PLACEMENT, - RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf' + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [{"Test": "Test"}] } self.client.credentials( HTTP_AUTHORIZATION='Bearer ' + self.student_token) @@ -344,19 +299,59 @@ class StudentViewsTestCase(APITestCase): self.assertEqual(response.data['message'], 'Application Submitted') self.assertEqual(PlacementApplication.objects.filter( student=self.student).count(), 1) + + def test_add_application_placement_deadlinePassed(self): self.placement.deadline_datetime = timezone.now().replace( hour=0, minute=0, second=0, microsecond=0) self.placement.save() + # deleted existing application + self.placement_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.placement.id, + OPENING_TYPE: PLACEMENT, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], + 'No Placement matches the given query.') + self.assertEqual(PlacementApplication.objects.filter( + student=self.student, placement=self.placement).count(), 0) + + def test_add_application_placement_alreadyApplied(self): + url = reverse('Add Application') + data = { + OPENING_ID: self.placement.id, + OPENING_TYPE: PLACEMENT, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.data['message'], 'Application is already Submitted') self.assertEqual(PlacementApplication.objects.filter( - student=self.student).count(), 1) - self.placement_application = PlacementApplication.objects.filter( - student=self.student) + student=self.student, placement=self.placement).count(), 1) + + def test_add_application_placement_notFound(self): self.placement_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.placement.id, + OPENING_TYPE: PLACEMENT, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + data[OPENING_ID] = generateRandomString() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data['message'], @@ -364,7 +359,124 @@ class StudentViewsTestCase(APITestCase): self.assertEqual(PlacementApplication.objects.filter( student=self.student).count(), 0) - def test_dashboard(self): + def test_add_application_placement_notApproved(self): + self.placement_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.placement.id, + OPENING_TYPE: PLACEMENT, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.placement.offer_accepted = False + self.placement.save() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], + 'Placement Not Approved') + self.assertEqual(PlacementApplication.objects.filter( + student=self.student, placement=self.placement).count(), 0) + + def test_add_application_placement_notEmailVerified(self): + self.placement_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.placement.id, + OPENING_TYPE: PLACEMENT, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.placement.email_verified = False + self.placement.save() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], + 'Placement Not Approved') + self.assertEqual(PlacementApplication.objects.filter( + student=self.student, placement=self.placement).count(), 0) + + def test_add_application_placement_notRegistered(self): + self.placement_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.placement.id, + OPENING_TYPE: PLACEMENT, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.student.can_apply = False + self.student.save() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['message'], + "Student Can't Apply") + self.assertEqual(PlacementApplication.objects.filter( + student=self.student, placement=self.placement).count(), 0) + + def test_add_application_placement_InvalidOpeningtype(self): + self.placement_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.placement.id, + OPENING_TYPE: "Invalid", + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['message'], + "Something Went Wrong") + self.assertEqual(PlacementApplication.objects.filter( + student=self.student, placement=self.placement).count(), 0) + + def test_add_application_placement_InvalidResume(self): + self.placement_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.placement.id, + OPENING_TYPE: PLACEMENT, + RESUME_FILE_NAME: 'Invalid', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], + "resume_file_name Not Found") + self.assertEqual(PlacementApplication.objects.filter( + student=self.student, placement=self.placement).count(), 0) + + def test_add_application_placement_MissingAdditionalInfo(self): + self.placement_application.delete() + url = reverse('Add Application') + self.placement.additional_info = ["Test"] + self.placement.save() + data = { + + OPENING_ID: self.placement.id, + OPENING_TYPE: PLACEMENT, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['message'], + "Something Went Wrong") + self.assertEqual(PlacementApplication.objects.filter( + student=self.student, placement=self.placement).count(), 0) + + def test_getdashboard(self): url = reverse('Dashboard') self.client.credentials( HTTP_AUTHORIZATION='Bearer ' + self.student_token) @@ -381,9 +493,7 @@ class StudentViewsTestCase(APITestCase): self.student.branch], deadline_datetime__gte=datetime.datetime.now(), offer_accepted=True, email_verified=True) - # self.assertEqual(len(response.data['internships']),len(internships)) - # self.assertEqual(PlacementApplicationConditions(self.student,self.placement)[1],"hai") - # self.assertEqual(len(response.data['placements']),len(placements)) + filtered_internships = internship_eligibility_filters( self.student, internships) filtered_placements = placement_eligibility_filters( @@ -429,3 +539,198 @@ class StudentViewsTestCase(APITestCase): opening_id=self.placement.id).count(), 1) self.assertEqual(Issues.objects.filter( opening_type=PLACEMENT).count(), 1) + + def test_add_application_internship(self): + self.internship.additional_info = ["Test"] + self.internship_application.delete() + # deleted existing application + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [{"Test": "Test"}] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Application Submitted') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student).count(), 1) + + def test_add_application_internship_deadlinePassed(self): + self.internship.deadline_datetime = timezone.now().replace( + hour=0, minute=0, second=0, microsecond=0) + self.internship.save() + # deleted existing application + self.internship_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], + 'No Internship matches the given query.') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student, internship=self.internship).count(), 0) + + def test_add_application_internship_alreadyApplied(self): + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], + 'Application is already Submitted') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student, internship=self.internship).count(), 1) + + def test_add_application_internship_notFound(self): + self.internship_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + + data[OPENING_ID] = generateRandomString() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], + 'No Internship matches the given query.') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student).count(), 0) + + def test_add_application_internship_notApproved(self): + self.internship_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.internship.offer_accepted = False + self.internship.save() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], + 'Internship Not Approved') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student, internship=self.internship).count(), 0) + + def test_add_application_internship_notEmailVerified(self): + self.internship_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.internship.email_verified = False + self.internship.save() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + self.assertEqual(response.data['message'], + 'Internship Not Approved') + self.assertEqual(InternshipApplication.objects.filter( + student=self.student, internship=self.internship).count(), 0) + + def test_add_application_internship_notRegistered(self): + self.internship_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.student.can_apply_internship = False + self.student.save() + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['message'], + "Student Can't Apply") + self.assertEqual(InternshipApplication.objects.filter( + student=self.student, internship=self.internship).count(), 0) + + def test_add_application_internship_InvalidOpeningtype(self): + self.internship_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: "Invalid", + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['message'], + "Something Went Wrong") + self.assertEqual(InternshipApplication.objects.filter( + student=self.student, internship=self.internship).count(), 0) + + def test_add_application_internship_InvalidResume(self): + self.internship_application.delete() + url = reverse('Add Application') + data = { + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: 'Invalid', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], + "resume_file_name Not Found") + self.assertEqual(InternshipApplication.objects.filter( + student=self.student, internship=self.internship).count(), 0) + + def test_add_application_internship_MissingAdditionalInfo(self): + self.internship_application.delete() + url = reverse('Add Application') + self.internship.additional_info = ["Test"] + self.internship.save() + data = { + + OPENING_ID: self.internship.id, + OPENING_TYPE: INTERNSHIP, + RESUME_FILE_NAME: '8BSLybntULgrPPm_beehyv.pdf', + ADDITIONAL_INFO: [] + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['message'], + "Something Went Wrong") + self.assertEqual(InternshipApplication.objects.filter( + student=self.student, internship=self.internship).count(), 0) From 3363aa7d7940edde9ecd1b4d44401aef4e2c9900 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Sun, 8 Oct 2023 01:56:12 +0530 Subject: [PATCH 15/38] added students test ,updated companyurls --- CDC_Backend/APIs/companyUrls.py | 1 + CDC_Backend/APIs/tests/test_studentView.py | 104 ++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/CDC_Backend/APIs/companyUrls.py b/CDC_Backend/APIs/companyUrls.py index 3dcaa27..35379e7 100644 --- a/CDC_Backend/APIs/companyUrls.py +++ b/CDC_Backend/APIs/companyUrls.py @@ -7,4 +7,5 @@ urlpatterns = [ path('verifyEmail/', companyViews.verifyEmail, name="Verify Email"), path('getAutoFillJnf/', companyViews.autoFillJnf, name="Auto FIll JNF"), path('addInternship/',companyViews.addInternship,name="Add Internship"), + path('getAutoFillInf/', companyViews.autoFillInf, name="Auto FIll INF"), ] diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py index a799bf0..e33b8ea 100644 --- a/CDC_Backend/APIs/tests/test_studentView.py +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -8,6 +8,7 @@ from django.urls import reverse from ..utils import * import json from django.utils import timezone +from django.core.files.uploadedfile import SimpleUploadedFile class StudentViewsTestCase(APITestCase): @@ -15,12 +16,12 @@ class StudentViewsTestCase(APITestCase): self.client = APIClient() self.user = User.objects.create( email=str(os.environ.get("email")), - id=generateRandomString(), + id="200010052", user_type=[STUDENT]) self.assertEqual( self.user.email, User.objects.get(id=self.user.id).email) self.student = Student.objects.create( - name="Test Student", id=self.user.id, resumes=["8BSLybntULgrPPm_beehyv.pdf"], roll_no=str(os.environ.get("roll_no")), branch="CSE", batch="2020", phone_number="1234567890", changed_by=self.user, can_apply=True, + name="Test Student", id=self.user.id, resumes=["8BSLybntULgrPPm_beehyv.pdf"], roll_no=str(os.environ.get("roll_no")), branch="CSE", batch="2020", phone_number=1234567890, changed_by=self.user, can_apply=True, can_apply_internship=True, degree="bTech", cpi=7.95, ) self.assertEqual(self.student.name, @@ -734,3 +735,102 @@ class StudentViewsTestCase(APITestCase): "Something Went Wrong") self.assertEqual(InternshipApplication.objects.filter( student=self.student, internship=self.internship).count(), 0) + + def test_getStudentProfile(self): + url = reverse('Student Profile') + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.get(url, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Details Found') + self.assertEqual(response.data['details']['id'], self.student.id) + self.assertEqual(response.data['details']['roll_no'], + self.student.roll_no) + self.assertEqual(response.data['details']['name'], self.student.name) + self.assertEqual(response.data['details']['batch'], self.student.batch) + self.assertEqual(response.data['details']['branch'], + self.student.branch) + self.assertEqual(response.data['details']['phone_number'], + self.student.phone_number) + self.assertEqual(response.data['details'] + ['cpi'], str(self.student.cpi)) + for i in range(len(response.data['details']['resume_list'])): + self.assertIn( + response.data['details']['resume_list'][i]['name'], self.student.resumes) + for i in range(len(response.data['details']['offers'])): + self.assertIn(response.data['details']['offers'][i] + ['application_id'], self.placement_application.id) + + def test_addResume_success(self): + pdf = SimpleUploadedFile( + 'kalera.pdf', b'content', content_type='application/pdf') + url = reverse('Upload Resume') + files = {'file': pdf} + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, files, format='multipart') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Resume Added') + + def test_add_resume_max_limit_reached(self): + pdf = SimpleUploadedFile( + 'kalera.pdf', b'content', content_type='application/pdf') + url = reverse('Upload Resume') + files = {'file': pdf} + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + self.student.resumes = ['resume1.pdf', 'resume2.pdf', 'resume3.pdf'] + self.student.save() + response = self.client.post(url, files, format='multipart') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data, { + 'action': 'Upload Resume', 'message': 'Max Number of Resumes limit reached'}) + self.student.refresh_from_db() + self.assertEqual(len(self.student.resumes), 3) + + def test_deleteResume_success(self): + destination_path = STORAGE_DESTINATION_RESUMES + \ + self.student.id+'/'+"8BSLybntULgrPPm_beehyv.pdf" + # check it whats this above without this test giving error + with open(destination_path, 'w') as f: + f.write('test') + f.close() + # create a file here + + url = reverse('Delete Resume') + data = { + 'resume_file_name': '8BSLybntULgrPPm_beehyv.pdf' + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['message'], 'Resume Deleted') + self.student.refresh_from_db() + self.assertEqual(self.student.resumes, []) + remove(destination_path) + + def test_deleteResume_invalidResume(self): + url = reverse('Delete Resume') + data = { + 'resume_file_name': 'Invalid' + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], + 'Resume Not Found') + self.student.refresh_from_db() + self.assertEqual(self.student.resumes, ['8BSLybntULgrPPm_beehyv.pdf']) + + def test_deleteResume_missingResumeinStorage(self): + url = reverse('Delete Resume') + data = { + 'resume_file_name': '8BSLybntULgrPPm_beehyv.pdf' + } + self.client.credentials( + HTTP_AUTHORIZATION='Bearer ' + self.student_token) + response = self.client.post(url, data, format='json') + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data['message'], 'File Not Found') From 95e6b0c2f3641220bfbd84c8e27ba2690f54fa16 Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Mon, 9 Oct 2023 01:25:25 +0530 Subject: [PATCH 16/38] added tests --- CDC_Backend/APIs/companyViews.py | 2 +- CDC_Backend/APIs/tests/test_adminView.py | 23 +-- CDC_Backend/APIs/tests/test_companyViews.py | 195 ++++++++++++++++++++ 3 files changed, 204 insertions(+), 16 deletions(-) create mode 100644 CDC_Backend/APIs/tests/test_companyViews.py diff --git a/CDC_Backend/APIs/companyViews.py b/CDC_Backend/APIs/companyViews.py index 67fad0b..cd73ce6 100644 --- a/CDC_Backend/APIs/companyViews.py +++ b/CDC_Backend/APIs/companyViews.py @@ -322,7 +322,7 @@ def autoFillJnf(request): status=status.HTTP_400_BAD_REQUEST) @api_view(['GET']) -@precheck([PLACEMENT_ID]) +@precheck([INTERNSHIP_ID]) def autoFillInf(request): try: data = request.GET diff --git a/CDC_Backend/APIs/tests/test_adminView.py b/CDC_Backend/APIs/tests/test_adminView.py index 9e63a3b..7ccce2f 100644 --- a/CDC_Backend/APIs/tests/test_adminView.py +++ b/CDC_Backend/APIs/tests/test_adminView.py @@ -84,10 +84,7 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) self.token = response.data['id_token'] - # response = self.client.post(reverse('Refresh Token'), { - # 'refresh_token': os.environ.get("s_refresh_token")}, format='json') - # self.assertEqual(response.status_code, status.HTTP_200_OK) - # self.s_token = response.data['id_token'] + # def test_get_stats(self): # self.pa1.selected = True @@ -190,13 +187,7 @@ class AdminView(APITestCase): # self.assertEqual( # student4_stats['second_offer_compensation'], None) - # def test_get_stats_error(self): - # # Test if an error is returned when an exception is raised - # # by the view function - # self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) - # response = self.client.get(reverse('Get Stats')) - # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - # self.assertEqual(response.data['message'], 'Something Went Wrong') + # logic Issue Fix The Above Function def test_addPPO(self): # done url = reverse("Add PPO") @@ -300,9 +291,9 @@ class AdminView(APITestCase): self.assertEqual(response.data['message'], 'Application added') self.assertEqual(PlacementApplication.objects.filter( student=self.student4).count(), 1) - - # handle double creation of application - + ############################################## + ### handle double creation of application ### + ############################################## def test_submitApplication_without_adinfo(self): url = reverse("Submit Application") self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token) @@ -1375,7 +1366,9 @@ class AdminView(APITestCase): self.assertEqual(InternshipApplication.objects.filter( student=self.student4).count(), 1) - # handle double creation of application + ############################################## + ### handle double creation of application ### + ############################################## def test_submitApplication_without_adinfo_internship(self): url = reverse("Submit Application") diff --git a/CDC_Backend/APIs/tests/test_companyViews.py b/CDC_Backend/APIs/tests/test_companyViews.py new file mode 100644 index 0000000..e9b7cc1 --- /dev/null +++ b/CDC_Backend/APIs/tests/test_companyViews.py @@ -0,0 +1,195 @@ +from django.test import TestCase, Client +from rest_framework import status +from rest_framework.test import APITestCase, APIClient +from django.urls import reverse +from ..models import * +import json +from ..utils import generateRandomString +import jwt + +# initialize the APIClient app +client = APIClient() + + + +class AddNewPlacementTest(APITestCase): + """ Test module for adding a new placement """ + + def setUp(self): + self.valid_payload = { + 'company_name': 'Test Company 3', 'address': 'Test Address 3', 'company_type': 'Test Company Type 3', + 'nature_of_business': 'Test Nature of Business 3', 'type_of_organisation': 'Test Type of Organisation 3', + 'website': 'Test Website 3', 'company_details': 'Test Company Details 3', 'is_company_details_pdf': True, + 'contact_person_name': 'Test Contact Person Name 3', 'phone_number': 1234567890, 'email': 'test3@test.com', + 'city': 'Test City 3', 'state': 'Test State 3', 'country': 'Test Country 3', 'pin_code': 123456, + 'designation': 'Test Designation 3', 'description': 'Test Description 3', 'job_location': 'Test Job Location 3', + 'is_description_pdf': True, 'compensation_CTC': 300000, 'compensation_gross': 240000, + 'compensation_take_home': 180000, 'compensation_bonus': 60000, 'is_compensation_details_pdf': True, + 'allowed_branch': 'Test Allowed Branch 3', 'rs_eligible': True, + 'selection_procedure_rounds': 'Test Selection Procedure Rounds 3', + 'selection_procedure_details': 'Test Selection Procedure Details 3', + 'is_selection_procedure_details_pdf': True, 'tentative_date_of_joining': '2022-03-01', + 'tentative_no_of_offers': 30, 'other_requirements': 'Test Other Requirements 3' + } + self.invalid_payload = { + 'company_name': '', 'address': 'Test Address 4', 'company_type': 'Test Company Type 4', + 'nature_of_business': 'Test Nature of Business 4', 'type_of_organisation': 'Test Type of Organisation 4', + 'website': 'Test Website 4', 'company_details': 'Test Company Details 4', 'is_company_details_pdf': True, + 'contact_person_name': 'Test Contact Person Name 4', 'phone_number': 1234567890, 'email': 'test4@test.com', + 'city': 'Test City 4', 'state': 'Test State 4', 'country': 'Test Country 4', 'pin_code': 123456, + 'designation': 'Test Designation 4', 'description': 'Test Description 4', 'job_location': 'Test Job Location 4', + 'is_description_pdf': True, 'compensation_CTC': 400000, 'compensation_gross': 320000, + 'compensation_take_home': 240000, 'compensation_bonus': 80000, 'is_compensation_details_pdf': True, + 'allowed_branch': 'Test Allowed Branch 4', 'rs_eligible': True, + 'selection_procedure_rounds': 'Test Selection Procedure Rounds 4', + 'selection_procedure_details': 'Test Selection Procedure Details 4', + 'is_selection_procedure_details_pdf': True, 'tentative_date_of_joining': '2022-04-01', + 'tentative_no_of_offers': 40, 'other_requirements': 'Test Other Requirements 4' + } + self.placement1 = Placement.objects.create( + company_name='ABC Corp', compensation_CTC=1000000, tier='1', id=generateRandomString(), allowed_branch=["CSE", "EE"], allowed_batch=["2020"], contact_person_name="test", phone_number=1234567890, email="test1@test.com", offer_accepted=True) + self.internship1 = Internship.objects.create( + company_name='ABC Corp', stipend=100000, id=generateRandomString(), allowed_branch=["CSE", "EE"], allowed_batch=["2020"], contact_person_name="test", phone_number=1234567890, email="test@gmail.com", offer_accepted=True) + self.token_placement1=jwt.encode({'opening_id': self.placement1.id,'opening_type':PLACEMENT,'email':"test1@test.com"}, os.environ.get("EMAIL_VERIFICATION_SECRET_KEY"), algorithm='HS256') + + # def test_create_valid_placement(self): + # response = client.post( + # reverse('addPlacement'), + # data=json.dumps(self.valid_payload), + # content_type='application/json' + # ) + # self.assertEqual(response.status_code, status.HTTP_201_CREATED) + + # def test_create_invalid_placement(self): + # response = client.post( + # reverse('addPlacement'), + # data=json.dumps(self.invalid_payload), + # content_type='application/json' + # ) + # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + def test_autofill_jnf_success(self): + response = client.get( + reverse('Auto FIll JNF'),{"placement_id": self.placement1.id} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["message"], "Data Found") + self.assertEqual(response.data["placement_data"]["company_name"], "ABC Corp") + self.assertEqual(response.data["placement_data"]["compensation_CTC"], 1000000) + self.assertEqual(response.data["placement_data"]["tier"], "1") + self.assertEqual(response.data["placement_data"]["allowed_branch"], ["CSE", "EE"]) + self.assertEqual(response.data["placement_data"]["allowed_batch"], ["2020"]) + self.assertEqual(response.data["placement_data"]["contact_person_name"], "test") + self.assertEqual(response.data["placement_data"]["phone_number"], 1234567890) + self.assertEqual(response.data["placement_data"]["email"], "test1@test.com") + + def test_autofill_jnf_WithInvalidId(self): + response = client.get( + reverse('Auto FIll JNF'),{"placement_id": generateRandomString()} + ) + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data["message"], "Placement Not Found") + + def test_autofill_inf_success(self): + response = client.get( + reverse('Auto FIll INF'),{"internship_id": self.internship1.id} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["message"], "Data Found") + self.assertEqual(response.data["internship_data"]["company_name"], "ABC Corp") + self.assertEqual(response.data["internship_data"]["stipend"], 100000) + self.assertEqual(response.data["internship_data"]["allowed_branch"], ["CSE", "EE"]) + self.assertEqual(response.data["internship_data"]["allowed_batch"], ["2020"]) + self.assertEqual(response.data["internship_data"]["contact_person_name"], "test") + self.assertEqual(response.data["internship_data"]["phone_number"], 1234567890) + self.assertEqual(response.data["internship_data"]["email"], "test@gmail.com") + + def test_autofill_inf_WithInvalidId(self): + response = client.get( + reverse('Auto FIll INF'),{"internship_id": generateRandomString()} + ) + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data["message"], "Internship Not Found") + + def test_verify_email_success_placement(self): + response = client.post( + reverse('Verify Email'),{"token": self.token_placement1} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["message"], "Email Verified Successfully") + + + + def test_verify_email_WithInvalidEmail_placement(self): + token_placement1=jwt.encode({'opening_id': self.placement1.id,'opening_type':PLACEMENT,'email':"hai@hai.com"}, os.environ.get("EMAIL_VERIFICATION_SECRET_KEY"), algorithm='HS256') + response = client.post( + reverse('Verify Email'),{"token": token_placement1} + ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data["message"], "Invalid Email") + + + + def test_verify_email_WithInvalidOpeningId_Placement(self): + token_placement1=jwt.encode({'opening_id': generateRandomString(),'opening_type':PLACEMENT,'email':"hai@hai.com"}, os.environ.get("EMAIL_VERIFICATION_SECRET_KEY"), algorithm='HS256') + response = client.post( + reverse('Verify Email'),{"token": token_placement1} + ) + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data["message"], "Opening Not Found") + + def test_verify_email_WithInvalidOpeningType(self): + token_placement1=jwt.encode({'opening_id': self.placement1.id,'opening_type':"hai",'email':"hai@hai.com"}, os.environ.get("EMAIL_VERIFICATION_SECRET_KEY"), algorithm='HS256') + response = client.post( + reverse('Verify Email'),{"token": token_placement1} + ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data["message"], "Invalid opening type") + def test_verify_email_WithInvalidToken(self): + response = client.post( + reverse('Verify Email'),{"token": generateRandomString()} + ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data["message"], "Something went wrong") + def test_verify_email_success_Internship(self): + token_placement1=jwt.encode({'opening_id': self.internship1.id,'opening_type':INTERNSHIP,'email':"test@gmail.com"}, os.environ.get("EMAIL_VERIFICATION_SECRET_KEY"), algorithm='HS256') + response = client.post( + reverse('Verify Email'),{"token": token_placement1} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["message"], "Email Verified Successfully") + + def test_verify_email_WithInvalidEmail_Internship(self): + token_placement1=jwt.encode({'opening_id': self.internship1.id,'opening_type':INTERNSHIP,'email':"hai@hai.com"}, os.environ.get("EMAIL_VERIFICATION_SECRET_KEY"), algorithm='HS256') + response = client.post( + reverse('Verify Email'),{"token": token_placement1} + ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data["message"], "Invalid Email") + + def test_verify_email_WithInvalidOpeningId_Internship(self): + token_placement1=jwt.encode({'opening_id': generateRandomString(),'opening_type':INTERNSHIP,'email':"hai@hai.com"}, os.environ.get("EMAIL_VERIFICATION_SECRET_KEY"), algorithm='HS256') + response = client.post( + reverse('Verify Email'),{"token": token_placement1} + ) + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data["message"], "Opening Not Found") + + + +################################################################ +# 1.Write Tests For AddPlacement Functions All cases # +# # +# 2.Write Tests For AddInternship Function All cases # +# # +################################################################ + def test_addPlacement_sucess(self): + self.assertTrue(True) + + def test_addPlacement_failure(self): + self.assertTrue(True) + + + + + From 186bab832c711fbc6b8fde79d6b23aa36ed0e4bd Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Tue, 10 Oct 2023 00:36:01 +0530 Subject: [PATCH 17/38] deleted internapis folder --- CDC_Backend/internAPIs/__init__.py | 0 CDC_Backend/internAPIs/admin.py | 10 -- CDC_Backend/internAPIs/apps.py | 6 - CDC_Backend/internAPIs/companyUrls.py | 7 - CDC_Backend/internAPIs/companyViews.py | 4 - CDC_Backend/internAPIs/constants.py | 189 ------------------------- CDC_Backend/internAPIs/models.py | 187 ------------------------ CDC_Backend/internAPIs/tests.py | 3 - CDC_Backend/internAPIs/urls.py | 7 - CDC_Backend/internAPIs/views.py | 3 - 10 files changed, 416 deletions(-) delete mode 100644 CDC_Backend/internAPIs/__init__.py delete mode 100644 CDC_Backend/internAPIs/admin.py delete mode 100644 CDC_Backend/internAPIs/apps.py delete mode 100644 CDC_Backend/internAPIs/companyUrls.py delete mode 100644 CDC_Backend/internAPIs/companyViews.py delete mode 100644 CDC_Backend/internAPIs/constants.py delete mode 100644 CDC_Backend/internAPIs/models.py delete mode 100644 CDC_Backend/internAPIs/tests.py delete mode 100644 CDC_Backend/internAPIs/urls.py delete mode 100644 CDC_Backend/internAPIs/views.py diff --git a/CDC_Backend/internAPIs/__init__.py b/CDC_Backend/internAPIs/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/CDC_Backend/internAPIs/admin.py b/CDC_Backend/internAPIs/admin.py deleted file mode 100644 index e0f38d1..0000000 --- a/CDC_Backend/internAPIs/admin.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.contrib import admin - -# Register your models here. -from .models import * - -admin.site.register(Internship) - -admin.site.register(Season) - -admin.site.register(InternshipApplication) \ No newline at end of file diff --git a/CDC_Backend/internAPIs/apps.py b/CDC_Backend/internAPIs/apps.py deleted file mode 100644 index d8cd54d..0000000 --- a/CDC_Backend/internAPIs/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class InternapisConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'internAPIs' diff --git a/CDC_Backend/internAPIs/companyUrls.py b/CDC_Backend/internAPIs/companyUrls.py deleted file mode 100644 index 7fd2773..0000000 --- a/CDC_Backend/internAPIs/companyUrls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.urls import path - -from . import companyViews - -urlpatterns = [ - path('addInternship/', companyViews.addInternship, name="Add Internship"), -] diff --git a/CDC_Backend/internAPIs/companyViews.py b/CDC_Backend/internAPIs/companyViews.py deleted file mode 100644 index 1d55cf1..0000000 --- a/CDC_Backend/internAPIs/companyViews.py +++ /dev/null @@ -1,4 +0,0 @@ - - -def addInternship(request): - pass diff --git a/CDC_Backend/internAPIs/constants.py b/CDC_Backend/internAPIs/constants.py deleted file mode 100644 index 9230fa5..0000000 --- a/CDC_Backend/internAPIs/constants.py +++ /dev/null @@ -1,189 +0,0 @@ -import os - -BRANCH_CHOICES = [ - ["CSE", "CSE"], - ["EE", "EE"], - ["ME", "ME"], - ['MMAE', 'MMAE'], - ['EP', 'EP'], -] -BRANCHES = [ - "CSE", - "EE", - "MMAE", - "EP" -] -BATCH_CHOICES = [ - ["2021", "2021"], - ["2020", "2020"], - ["2019", "2019"], - ["2018", "2018"], - ["2017", "2017"], -] - -OFFER_CITY_TYPE = [ - ['Domestic', 'Domestic'], - ['International', 'International'] -] - -FACILITIES_PROVIDED = [ - ['Accommodation', 'Accommodation'], - ['Food', 'Food'], - ['Transport', 'Transport'], - ['Medical', 'Medical'], -] - -TOTAL_FACILITIES = 4 - -TIERS = [ - ['psu', 'PSU'], - ['1', 'Tier 1'], - ['2', 'Tier 2'], - ['3', 'Tier 3'], - ['4', 'Tier 4'], - ['5', 'Tier 5'], - ['6', 'Tier 6'], - ['7', 'Tier 7'], -] - -SEASON_CHOICES = ( - ['summer', 'Summer'], - ['winter', 'Winter'], - ['autumn', 'Autumn'], - ['spring', 'Spring'], - ) - -DEGREE_CHOICES = [ - ['bTech', 'B.Tech'], - ['ms/phd', 'MS/ PhD'], -] - -TOTAL_BRANCHES = 4 # Total No of Branches -TOTAL_BATCHES = 5 # Total No of Batches - -CDC_MAIl_ADDRESS = '2000' - -# To be Configured Properly -CLIENT_ID = os.environ.get('GOOGLE_OAUTH_CLIENT_ID') # Google Login Client ID - -# To be Configured Properly -PLACEMENT_OPENING_URL = "https://cdc.iitdh.ac.in/portal/student/dashboard/placements/{id}" # On frontend, this is the URL to be opened -LINK_TO_STORAGE_COMPANY_ATTACHMENT = "https://cdc.iitdh.ac.in/storage/Company_Attachments/" -LINK_TO_STORAGE_RESUME = "https://cdc.iitdh.ac.in/storage/Resumes/" -LINK_TO_APPLICATIONS_CSV = "https://cdc.iitdh.ac.in/storage/Application_CSV/" -LINK_TO_EMAIl_VERIFICATION_API = "https://cdc.iitdh.ac.in/portal/company/verifyEmail?token={token}" -PDF_FILES_SERVING_ENDPOINT = 'https://cdc.iitdh.ac.in/storage/Company_Attachments/' # TODO: Change this to actual URL - -EMAIL = "email" - -STUDENT = 'student' -ADMIN = 'admin' -SUPER_ADMIN = 's_admin' -COMPANY = 'company' -TIER = 'tier' -# To be Configured Properly -FOURTH_YEAR = '2020' -MAX_OFFERS_PER_STUDENT = 2 -MAX_RESUMES_PER_STUDENT = 3 -EMAIL_VERIFICATION_TOKEN_TTL = 48 # in hours -INF_TEXT_MAX_CHARACTER_COUNT = 100 -INF_TEXTMEDIUM_MAX_CHARACTER_COUNT = 200 -INF_TEXTAREA_MAX_CHARACTER_COUNT = 1000 -INF_SMALLTEXT_MAX_CHARACTER_COUNT = 50 - -STORAGE_DESTINATION_RESUMES = "./Storage/Resumes/" -STORAGE_DESTINATION_COMPANY_ATTACHMENTS = './Storage/Company_Attachments/' -STORAGE_DESTINATION_APPLICATION_CSV = './Storage/Application_CSV/' - -TOKEN = 'token' -RESUME_FILE_NAME = 'resume_file_name' - -APPLICATION_ID = "application_id" -OPENING_ID = "opening_id" -ADDITIONAL_INFO = "additional_info" -FIELD = "field" - -STATUS_ACCEPTING_APPLICATIONS = "Accepting Applications" - -PLACEMENT = "Placement" - -COMPANY_NAME = "company_name" -ADDRESS = "address" -COMPANY_TYPE = "company_type" -NATURE_OF_BUSINESS = "nature_of_business" -TYPE_OF_ORGANISATION = "type_of_organisation" -WEBSITE = 'website' -COMPANY_DETAILS = "company_details" -COMPANY_DETAILS_PDF = "company_details_pdf" -IS_COMPANY_DETAILS_PDF = "is_company_details_pdf" -COMPANY_DETAILS_PDF_NAMES = "company_details_pdf_names" -PHONE_NUMBER = 'phone_number' -CONTACT_PERSON_NAME = 'contact_person_name' -CITY = 'city' -STATE = 'state' -COUNTRY = 'country' -PINCODE = 'pincode' - -DESIGNATION = 'designation' -DESCRIPTION = 'description' -DESCRIPTION_PDF = 'description_pdf' -DESCRIPTION_PDF_NAMES = 'description_pdf_names' -IS_DESCRIPTION_PDF = 'is_description_pdf' -OPENING_TYPE = 'opening_type' -JOB_LOCATION = 'job_location' -COMPENSATION_CTC = 'compensation_ctc' -COMPENSATION_GROSS = 'compensation_gross' -COMPENSATION_TAKE_HOME = 'compensation_take_home' -COMPENSATION_BONUS = 'compensation_bonus' -COMPENSATION_DETAILS = 'compensation_details' -COMPENSATION_DETAILS_PDF = 'compensation_details_pdf' -COMPENSATION_DETAILS_PDF_NAMES = 'compensation_details_pdf_names' -IS_COMPENSATION_DETAILS_PDF = 'is_compensation_details_pdf' -ALLOWED_BATCH = 'allowed_batch' -ALLOWED_BRANCH = 'allowed_branch' -RS_ELIGIBLE = 'rs_eligible' -BOND_DETAILS = 'bond_details' -SELECTION_PROCEDURE_ROUNDS = 'selection_procedure_rounds' -SELECTION_PROCEDURE_DETAILS = 'selection_procedure_details' -SELECTION_PROCEDURE_DETAILS_PDF = 'selection_procedure_details_pdf' -SELECTION_PROCEDURE_DETAILS_PDF_NAMES = 'selection_procedure_details_pdf_names' -IS_SELECTION_PROCEDURE_DETAILS_PDF = 'is_selection_procedure_details_pdf' -TENTATIVE_DATE_OF_JOINING = 'tentative_date_of_joining' -TENTATIVE_NO_OF_OFFERS = 'tentative_no_of_offers' -OTHER_REQUIREMENTS = 'other_requirements' -DEADLINE_DATETIME = 'deadline_datetime' -OFFER_ACCEPTED = 'offer_accepted' -EMAIL_VERIFIED = 'email_verified' -RECAPTCHA_VALUE = 'recaptchakey' - -STUDENT_LIST = "student_list" -STUDENT_ID = "student_id" -STUDENT_SELECTED = "student_selected" - -EXCLUDE_IN_PDF = ['id', 'is_company_details_pdf', 'offer_accepted', 'is_description_pdf', - 'is_compensation_details_pdf', 'is_selection_procedure_details_pdf', - 'email_verified', 'created_at'] -SPECIAL_FORMAT_IN_PDF = ['website', 'company_details_pdf_names', 'description_pdf_names', - 'compensation_details_pdf_names', - 'selection_procedure_details_pdf_names'] - -COMPANY_OPENING_ERROR_TEMPLATE = "Alert! Error submitting opening for {company_name}." -COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT = "Notification Submitted - {id} - Career Development Cell, IIT Dharwad" -STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT = 'Application Status - {company_name} - {id}' -STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Application Submitted - {company_name}' -STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT = 'CDC - Application Updated - {company_name}' -COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT = 'Email Verification - Career Development Cell, IIT Dharwad' -NOTIFY_STUDENTS_OPENING_TEMPLATE_SUBJECT = 'Placement Opportunity at {company_name}' - -STUDENT_APPLICATION_SUBMITTED_TEMPLATE = 'student_application_submitted.html' -COMPANY_OPENING_SUBMITTED_TEMPLATE = 'company_opening_submitted.html' -STUDENT_APPLICATION_STATUS_SELECTED_TEMPLATE = 'student_application_status_selected.html' -STUDENT_APPLICATION_STATUS_NOT_SELECTED_TEMPLATE = 'student_application_status_not_selected.html' -STUDENT_APPLICATION_UPDATED_TEMPLATE = 'student_application_updated.html' -COMPANY_EMAIL_VERIFICATION_TEMPLATE = 'company_email_verification.html' -COMPANY_JNF_RESPONSE_TEMPLATE = 'company_jnf_response.html' -NOTIFY_STUDENTS_OPENING_TEMPLATE = 'notify_students_new_opening.html' - -APPLICATION_CSV_COL_NAMES = ['Applied At', 'Roll No.', 'Name', 'Email', 'Phone Number', 'Branch', 'Batch', 'CPI', - 'Resume', 'Selected', ] - diff --git a/CDC_Backend/internAPIs/models.py b/CDC_Backend/internAPIs/models.py deleted file mode 100644 index cfb896c..0000000 --- a/CDC_Backend/internAPIs/models.py +++ /dev/null @@ -1,187 +0,0 @@ -from django.db import models - -# Create your models here. -from django.contrib.postgres.fields import ArrayField -from django.db import models -from django.utils import timezone -from simple_history.models import HistoricalRecords - -from .constants import * - -#import models from other apps -from APIs.models import User,Student - -# Create your models here. -class Internship(models.Model): - id = models.CharField(blank=False, primary_key=True, max_length=15) #unique id for each internship - # Company Details - company_name = models.CharField(blank=False, max_length=INF_SMALLTEXT_MAX_CHARACTER_COUNT) - address = models.CharField(blank=False, max_length=INF_TEXTAREA_MAX_CHARACTER_COUNT) - company_type = models.CharField(blank=False, max_length=INF_SMALLTEXT_MAX_CHARACTER_COUNT) - nature_of_business = models.CharField(blank=False, max_length=INF_SMALLTEXT_MAX_CHARACTER_COUNT, default="") - type_of_organisation = models.CharField(max_length=INF_SMALLTEXT_MAX_CHARACTER_COUNT, default="", blank=False) - website = models.CharField(blank=True, max_length=INF_TEXT_MAX_CHARACTER_COUNT) - company_details = models.CharField(max_length=INF_TEXTAREA_MAX_CHARACTER_COUNT, default=None, null=True, blank=True) - company_details_pdf_names = ArrayField( - models.CharField(null=True, default=None, max_length=INF_TEXT_MAX_CHARACTER_COUNT), size=5, - default=list, blank=True) - is_company_details_pdf = models.BooleanField(blank=False, default=False) - #Company Address - city = models.CharField(blank=False, max_length=INF_SMALLTEXT_MAX_CHARACTER_COUNT, default="") - state = models.CharField(blank=False, max_length=INF_SMALLTEXT_MAX_CHARACTER_COUNT, default="") - country = models.CharField(blank=False, max_length=INF_SMALLTEXT_MAX_CHARACTER_COUNT, default="") - pin_code = models.IntegerField(blank=False, default=None, null=True) - # selection process - selection_procedure_rounds = ArrayField( - models.CharField(null=True, default=None, max_length=INF_TEXT_MAX_CHARACTER_COUNT), size=10, - default=list, blank=True) - selection_procedure_details = models.CharField(blank=True, max_length=INF_TEXTAREA_MAX_CHARACTER_COUNT) - selection_procedure_details_pdf_names = ArrayField( - models.CharField(null=True, default=None, max_length=INF_TEXT_MAX_CHARACTER_COUNT), - size=5, default=list, blank=True) - is_selection_procedure_details_pdf = models.BooleanField(blank=False, default=False) - #Internship Details - description_pdf_names = ArrayField( - models.CharField(null=True, default=None, max_length=INF_TEXT_MAX_CHARACTER_COUNT), size=5, default=list, - blank=True) - is_description_pdf = models.BooleanField(blank=False, default=False) - description = models.CharField(blank=False, max_length=INF_TEXTAREA_MAX_CHARACTER_COUNT, default=None, null=True) - interning_period_from = models.DateField(blank=False, default=None, null=True) - interning_period_to = models.DateField(blank=False, default=None, null=True) - season = models.CharField(blank=False, max_length=10, choices=SEASON_CHOICES, default=None) - is_work_from_home = models.BooleanField(blank=False, default=False) - sophomore_eligible = models.BooleanField(blank=False, default=False) - tentative_no_of_offers = models.IntegerField(blank=False, default=None, null=True) - stipend_description_pdf_names=ArrayField( - models.CharField(null=True, default=None, max_length=INF_TEXT_MAX_CHARACTER_COUNT), size=5, default=list, - blank=True) - is_stipend_description_pdf = models.BooleanField(blank=False, default=False) - stipend=models.IntegerField(blank=False, default=None, null=True) - facilities_provided=ArrayField( - models.CharField(choices=FACILITIES_PROVIDED, blank=False, max_length=20), - size=TOTAL_FACILITIES, - default=list - ) - additional_facilities = models.CharField(blank=True, max_length=INF_TEXTAREA_MAX_CHARACTER_COUNT, default=None, null=True) - academic_requirements = models.CharField(blank=True, max_length=INF_TEXTAREA_MAX_CHARACTER_COUNT, default=None, null=True) - #contact details of company person - contact_person_name = models.CharField(blank=False, max_length=INF_TEXT_MAX_CHARACTER_COUNT) - phone_number = models.PositiveBigIntegerField(blank=False) - email = models.EmailField(blank=False) - contact_person_designation = models.CharField(blank=False, max_length=INF_SMALLTEXT_MAX_CHARACTER_COUNT, default="") - telephone_number = models.PositiveBigIntegerField(blank=True, default=None, null=True) - email_verified = models.BooleanField(blank=False, default=False) - #history - created_at = models.DateTimeField(blank=False, default=None, null=True) - updated_at = models.DateTimeField(blank=False, default=None, null=True) - changed_by = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True) - history = HistoricalRecords(user_model=User) - - - def format(self): - if self.company_name is not None: - self.company_name = self.company_name.strip()[:INF_SMALLTEXT_MAX_CHARACTER_COUNT] - if self.company_type is not None: - self.company_type = self.company_type.strip()[:INF_SMALLTEXT_MAX_CHARACTER_COUNT] - if self.company_details is not None: - self.company_details = self.company_details.strip()[:INF_TEXTAREA_MAX_CHARACTER_COUNT] - if self.address is not None: - self.address = self.address.strip()[:INF_TEXTAREA_MAX_CHARACTER_COUNT] - if self.nature_of_business is not None: - self.nature_of_business = self.nature_of_business.strip()[:INF_TEXTAREA_MAX_CHARACTER_COUNT] - if self.type_of_organisation is not None: - self.type_of_organisation = self.type_of_organisation.strip()[:INF_TEXTAREA_MAX_CHARACTER_COUNT] - if self.website is not None: - self.website = self.website.strip()[:INF_TEXT_MAX_CHARACTER_COUNT] - if self.contact_person_name is not None: - self.contact_person_name = self.contact_person_name.strip()[:INF_TEXT_MAX_CHARACTER_COUNT] - if self.city is not None: - self.city = self.city.strip()[:INF_SMALLTEXT_MAX_CHARACTER_COUNT] - if self.state is not None: - self.state = self.state.strip()[:INF_SMALLTEXT_MAX_CHARACTER_COUNT] - if self.country is not None: - self.country = self.country.strip()[:INF_SMALLTEXT_MAX_CHARACTER_COUNT] - if self.city_type is not None: - self.city_type = self.city_type.strip()[:INF_SMALLTEXT_MAX_CHARACTER_COUNT] - if self.selection_procedure_details is not None: - self.selection_procedure_details = self.selection_procedure_details.strip()[:INF_TEXTAREA_MAX_CHARACTER_COUNT] - if self.description is not None: - self.description = self.description.strip()[:INF_TEXTAREA_MAX_CHARACTER_COUNT] - if self.additional_facilities is not None: - self.additional_facilities = self.additional_facilities.strip()[:INF_TEXTAREA_MAX_CHARACTER_COUNT] - if self.academic_requirements is not None: - self.academic_requirements = self.academic_requirements.strip()[:INF_TEXTAREA_MAX_CHARACTER_COUNT] - if self.contact_person_designation is not None: - self.contact_person_designation = self.contact_person_designation.strip()[:INF_SMALLTEXT_MAX_CHARACTER_COUNT] - - @property - def _history_user(self): - return self.changed_by - - @_history_user.setter - def _history_user(self, value): - if isinstance(value, User): - self.changed_by = value - else: - self.changed_by = None - - def save(self, *args, **kwargs): - ''' On save, add timestamps ''' - if not self.created_at: - self.created_at = timezone.now() - self.format() - self.updated_at = timezone.now() - return super(Internship, self).save(*args, **kwargs) - - def __str__(self): - return self.company_name + " - " + self.id - - - -class Season(models.Model): - - season = models.CharField(max_length=10, choices=SEASON_CHOICES, unique=True) - student = models.ForeignKey(Student, on_delete=models.CASCADE, default=None) - - def __str__(self): - return self.season + " Season - " + self.student.id - -class InternshipApplication(models.Model): - id = models.CharField(blank=False, primary_key=True, max_length=15) #unique id for each internship - internship=models.ForeignKey(Internship,blank=False, on_delete=models.CASCADE, default=None) - student=models.ForeignKey(Student,blank=False, on_delete=models.CASCADE, default=None) - resume = models.CharField(max_length=INF_TEXT_MAX_CHARACTER_COUNT, blank=False, null=True, default=None) - additional_info = models.JSONField(blank=True, null=True, default=None) - selected = models.BooleanField(null=True, default=None, blank=True) - offer_accepted = models.BooleanField(null=True, default=None, blank=True) # True if offer accepted, False if rejected, None if not yet decided - applied_at = models.DateTimeField(blank=False, default=None, null=True) - updated_at = models.DateTimeField(blank=False, default=None, null=True) - changed_by = models.ForeignKey(User, blank=False, on_delete=models.RESTRICT, default=None, null=True) - history = HistoricalRecords(user_model=User) - - def save(self, *args, **kwargs): - ''' On save, add timestamps ''' - if not self.applied_at: - self.applied_at = timezone.now() - self.updated_at = timezone.now() - - return super(InternshipApplication, self).save(*args, **kwargs) - - @property - def _history_user(self): - return self.changed_by - - @_history_user.setter - def _history_user(self, value): - if isinstance(value, User): - self.changed_by = value - else: - self.changed_by = None - - class Meta: - verbose_name_plural = "Internship Applications" - unique_together = ('internship', 'student') - - def __str__(self): - return self.internship.company_name + " - " + self.student.name - \ No newline at end of file diff --git a/CDC_Backend/internAPIs/tests.py b/CDC_Backend/internAPIs/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/CDC_Backend/internAPIs/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/CDC_Backend/internAPIs/urls.py b/CDC_Backend/internAPIs/urls.py deleted file mode 100644 index 411db7d..0000000 --- a/CDC_Backend/internAPIs/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.urls import path, include - -from . import companyUrls - -urlpatterns = [ - path('company/', include(companyUrls)), -] diff --git a/CDC_Backend/internAPIs/views.py b/CDC_Backend/internAPIs/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/CDC_Backend/internAPIs/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. From 6a677e931a984fc727b45ec4c42ed281b7e082e9 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 03:51:24 +0530 Subject: [PATCH 18/38] added django tasks --- .github/workflows/django.yml | 30 ++++++++++++++++++++++ .gitignore | 1 - CDC_Backend/APIs/tests/test_adminView.py | 7 +++-- CDC_Backend/APIs/tests/test_studentView.py | 2 +- CDC_Backend/APIs/urls.py | 1 - CDC_Backend/CDC_Backend/urls.py | 1 - 6 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/django.yml diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml new file mode 100644 index 0000000..f2c0f2a --- /dev/null +++ b/.github/workflows/django.yml @@ -0,0 +1,30 @@ +name: Django CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.7, 3.8, 3.9] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run Tests + run: | + python manage.py test diff --git a/.gitignore b/.gitignore index 1c22318..40fddbd 100644 --- a/.gitignore +++ b/.gitignore @@ -129,7 +129,6 @@ dmypy.json /venv/ -/.github/ ./CDC_Backend/static ./CDC_Backend/Storage /CDC_Backend/CDC_Backend/__pycache__/ diff --git a/CDC_Backend/APIs/tests/test_adminView.py b/CDC_Backend/APIs/tests/test_adminView.py index 7ccce2f..da24c04 100644 --- a/CDC_Backend/APIs/tests/test_adminView.py +++ b/CDC_Backend/APIs/tests/test_adminView.py @@ -18,7 +18,7 @@ class AdminView(APITestCase): self.s_admin = User.objects.create(email=str(os.environ.get( "s_email")), id=generateRandomString(), user_type=["s_admin"]) self.user1 = User.objects.create( - email="200010030@iitdh.ac.in", id="200010030", user_type=[STUDENT]) + email="200010032@iitdh.ac.in", id="200010032", user_type=[STUDENT]) self.user2 = User.objects.create( email="200010038@iitdh.ac.in", id="200010038", user_type=[STUDENT]) self.user3 = User.objects.create( @@ -26,7 +26,7 @@ class AdminView(APITestCase): self.user4 = User.objects.create( email="200030058@iitdh.ac.in", id="200030058", user_type=[STUDENT]) self.student1 = Student.objects.create( - name='John Doe', roll_no='200010030', batch='2020', branch='CSE', cpi=9.5, id="200010030", can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf", "8BSLybntULgrPPm_kalera.pdf"], can_apply_internship=True) + name='John Doe', roll_no='200010032', batch='2020', branch='CSE', cpi=9.5, id="200010032", can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf", "8BSLybntULgrPPm_kalera.pdf"], can_apply_internship=True) self.student2 = Student.objects.create( name='Jane Doe', roll_no='200010038', batch='2020', branch='EE', cpi=9.0, id="200010038", can_apply=True, resumes=["8BSLybntULgrPPm_beehyv.pdf"], can_apply_internship=True) self.student3 = Student.objects.create( @@ -84,8 +84,8 @@ class AdminView(APITestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) self.token = response.data['id_token'] - + # TODO: logic Issue Fix The Above Function # def test_get_stats(self): # self.pa1.selected = True # self.pa1.save() @@ -187,7 +187,6 @@ class AdminView(APITestCase): # self.assertEqual( # student4_stats['second_offer_compensation'], None) - # logic Issue Fix The Above Function def test_addPPO(self): # done url = reverse("Add PPO") diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py index e33b8ea..a42098f 100644 --- a/CDC_Backend/APIs/tests/test_studentView.py +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -16,7 +16,7 @@ class StudentViewsTestCase(APITestCase): self.client = APIClient() self.user = User.objects.create( email=str(os.environ.get("email")), - id="200010052", + id=str(os.environ.get("roll_no")), user_type=[STUDENT]) self.assertEqual( self.user.email, User.objects.get(id=self.user.id).email) diff --git a/CDC_Backend/APIs/urls.py b/CDC_Backend/APIs/urls.py index af80640..09025a0 100644 --- a/CDC_Backend/APIs/urls.py +++ b/CDC_Backend/APIs/urls.py @@ -8,5 +8,4 @@ urlpatterns = [ path('student/', include(studentUrls)), path('company/', include(companyUrls)), path('admin/', include(adminUrls)), - ] diff --git a/CDC_Backend/CDC_Backend/urls.py b/CDC_Backend/CDC_Backend/urls.py index 69ba9ea..d1cadf9 100644 --- a/CDC_Backend/CDC_Backend/urls.py +++ b/CDC_Backend/CDC_Backend/urls.py @@ -4,5 +4,4 @@ from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('api/', include('APIs.urls')), - path('internapi/', include('internAPIs.urls')) ] From 4d63afedf5dd8e342df1b37393728f826eb95643 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 04:07:22 +0530 Subject: [PATCH 19/38] change django.yml --- .github/workflows/django.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index f2c0f2a..6baeca7 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -13,7 +13,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: [3.7, 3.8, 3.9] + python-version: [3.9] steps: - uses: actions/checkout@v3 @@ -27,4 +27,4 @@ jobs: pip install -r requirements.txt - name: Run Tests run: | - python manage.py test + cd CDC_Backend && python manage.py test From c9cb9957f407bce25c1006350ec2bd89815dd64b Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 04:34:58 +0530 Subject: [PATCH 20/38] change django.yml --- .github/workflows/django.yml | 64 +++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 6baeca7..a15fdc2 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -1,30 +1,48 @@ -name: Django CI +name: Django CI -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] +env: + HOSTING_URL: "http://localhost:8000/" + DEBUG: True + EMAIL: karthik.murakonda14@gmail.com + EMAIL_PASSWORD: ************** + EMAIL_VERIFICATION_SECRET_KEY: "b'<\xa3\xaf&d6\xa9sf\x19$\x96\xb7\x90\x8b\x88\x84\x0e\x191\xde,M\x90\x17(\xf7\nG\x13\x8d$\x9f&\xb0\xcd\xa4\xaf\xa9\x1b\x15\x02B\x8a\xaf\xff\x0c\x1e\xd5\xb3\x06\xb8\xa6\x9bQ\xa0TR\xe8\x98\x9ae\xe0n}\xcc/[\xdaFz\x18\xfeX\xaf\xbd\xd0\x88\xeal\xe3\xd2\xe3\xb8\x8c\x199{\xf3<\xb0\xc5\xd0\xe7*Rv\xda\xbb \x1d\x85~\xff%>\x1e\xb8\xa7\xbf\xbc\xb2\x06\x86X\xc3\x9f\x13<\x9fd\xea\xb5\x01\xa4\x7f\xa0\x1b\x8bO\x01h\xe8\xfd\x1f\xfe\xba\xbeg\\\xc2\xcb\xc3\xd1~\xff\xd5/9d\xa8\xa7x{\x16\xdb\\\xbb\x08\rI\xcd\x9e7\x8c~\x0f\x1d\x81rXZD\xf0\xf7\x87K\x8f\xfb,\xf4\xf0\xa5\x9e\xde^\xca\xae\x80|9b\x9b\xaaE\xba\xfb\xdf\x80\xb1\x99\x83e[\xf8\xce&Rq\x99\xdb}\xeeO\xd5\x18\x8d\x0bv\xe7\xab\xf9\xb9{\xb5u\xce\xcf\x90\xa6HE\xc5\x92p\x00\x158\xdf'" + DB_NAME: cdc + DB_USER: postgres + DB_PASSWORD: postgres + DB_HOST: localhost + DB_PORT: 5432 + RECAPTCHA_SECRET_KEY: 6LfpadYhAAAAAJUIJQ_JJqkqq3arvalwkVCgW3nG + GOOGLE_OAUTH_CLIENT_ID: 628308091838-nvfn455vabbq7j0odd797sls8itpplmr.apps.googleusercontent.com + SECRET_KEY: 9%2e!&f6(ib^690y48z)&w6fczhwukzzp@3y*^*7u+7%4s-mie + GOOGLE_OAUTH_CLIENT_SECRET: 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 + refresh_token: 1//0gCf5fxAgSqNcCgYIARAAGBASNwF-L9IrIWxWwqmboeJkEzVn0sqxbaeyWXODE5s24V7pSdiAzFM2cxOUC9XT_xp7t_60o3JMfOg + email: 200010030@iitdh.ac.in + roll_no: 200010030 -jobs: - build: +jobs: + build: - runs-on: ubuntu-latest - strategy: - max-parallel: 4 - matrix: - python-version: [3.9] + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.9] - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install Dependencies - run: | + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: | python -m pip install --upgrade pip pip install -r requirements.txt - - name: Run Tests - run: | + - name: Run Tests + run: | cd CDC_Backend && python manage.py test From 0914c0c2a6588799abce83a771fb92f573a88a2e Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 04:37:19 +0530 Subject: [PATCH 21/38] change django.yml --- .github/workflows/django.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index a15fdc2..b1607f7 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -9,7 +9,7 @@ env: HOSTING_URL: "http://localhost:8000/" DEBUG: True EMAIL: karthik.murakonda14@gmail.com - EMAIL_PASSWORD: ************** + EMAIL_PASSWORD: 1234567890 EMAIL_VERIFICATION_SECRET_KEY: "b'<\xa3\xaf&d6\xa9sf\x19$\x96\xb7\x90\x8b\x88\x84\x0e\x191\xde,M\x90\x17(\xf7\nG\x13\x8d$\x9f&\xb0\xcd\xa4\xaf\xa9\x1b\x15\x02B\x8a\xaf\xff\x0c\x1e\xd5\xb3\x06\xb8\xa6\x9bQ\xa0TR\xe8\x98\x9ae\xe0n}\xcc/[\xdaFz\x18\xfeX\xaf\xbd\xd0\x88\xeal\xe3\xd2\xe3\xb8\x8c\x199{\xf3<\xb0\xc5\xd0\xe7*Rv\xda\xbb \x1d\x85~\xff%>\x1e\xb8\xa7\xbf\xbc\xb2\x06\x86X\xc3\x9f\x13<\x9fd\xea\xb5\x01\xa4\x7f\xa0\x1b\x8bO\x01h\xe8\xfd\x1f\xfe\xba\xbeg\\\xc2\xcb\xc3\xd1~\xff\xd5/9d\xa8\xa7x{\x16\xdb\\\xbb\x08\rI\xcd\x9e7\x8c~\x0f\x1d\x81rXZD\xf0\xf7\x87K\x8f\xfb,\xf4\xf0\xa5\x9e\xde^\xca\xae\x80|9b\x9b\xaaE\xba\xfb\xdf\x80\xb1\x99\x83e[\xf8\xce&Rq\x99\xdb}\xeeO\xd5\x18\x8d\x0bv\xe7\xab\xf9\xb9{\xb5u\xce\xcf\x90\xa6HE\xc5\x92p\x00\x158\xdf'" DB_NAME: cdc DB_USER: postgres From 4a9b3ab3b08dfb1cc9dcb10a4b0fac5f431af259 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 04:39:37 +0530 Subject: [PATCH 22/38] change django.yml --- .github/workflows/django.yml | 2 +- CDC_Backend/APIs/tests/test_studentView.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index b1607f7..aeb83d4 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -21,7 +21,7 @@ env: SECRET_KEY: 9%2e!&f6(ib^690y48z)&w6fczhwukzzp@3y*^*7u+7%4s-mie GOOGLE_OAUTH_CLIENT_SECRET: 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 refresh_token: 1//0gCf5fxAgSqNcCgYIARAAGBASNwF-L9IrIWxWwqmboeJkEzVn0sqxbaeyWXODE5s24V7pSdiAzFM2cxOUC9XT_xp7t_60o3JMfOg - email: 200010030@iitdh.ac.in + email_id: 200010030@iitdh.ac.in roll_no: 200010030 jobs: diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py index a42098f..e737387 100644 --- a/CDC_Backend/APIs/tests/test_studentView.py +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -15,7 +15,7 @@ class StudentViewsTestCase(APITestCase): def setUp(self): self.client = APIClient() self.user = User.objects.create( - email=str(os.environ.get("email")), + email=str(os.environ.get("email_id")), id=str(os.environ.get("roll_no")), user_type=[STUDENT]) self.assertEqual( From 405d3a55ff9374debdd44b842709744e7f92e1e8 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 04:44:04 +0530 Subject: [PATCH 23/38] change django.yml --- .github/workflows/django.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index aeb83d4..33fef52 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -28,6 +28,18 @@ jobs: build: runs-on: ubuntu-latest + + services: + postgres: + image: postgres + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: cdc + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + strategy: max-parallel: 4 matrix: From fb5f85b237cea5a12d02a350852fc41a9180cef3 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 04:47:12 +0530 Subject: [PATCH 24/38] change django.yml --- .github/workflows/django.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 33fef52..a7025ba 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -57,4 +57,7 @@ jobs: pip install -r requirements.txt - name: Run Tests run: | - cd CDC_Backend && python manage.py test + cd CDC_Backend + python manage.py makemigrations + python manage.py makemigrations APIs + python manage.py test From 613d0b9d3fd9a069e47e70b45c61b282c11c3756 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 04:50:44 +0530 Subject: [PATCH 25/38] change django.yml --- .github/workflows/django.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index a7025ba..133605f 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -58,6 +58,7 @@ jobs: - name: Run Tests run: | cd CDC_Backend + pythom manage.py collectstatic python manage.py makemigrations python manage.py makemigrations APIs python manage.py test From 79b14703f40d040545cc7707b97198726f373996 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 04:52:24 +0530 Subject: [PATCH 26/38] change django.yml --- .github/workflows/django.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 133605f..736bc91 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -58,7 +58,7 @@ jobs: - name: Run Tests run: | cd CDC_Backend - pythom manage.py collectstatic + python manage.py collectstatic python manage.py makemigrations python manage.py makemigrations APIs python manage.py test From 830602144cfe415096a62978ee0344d4dfcb09df Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 05:04:17 +0530 Subject: [PATCH 27/38] change django.yml --- .github/workflows/django.yml | 1 + CDC_Backend/APIs/tests/test_adminView.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 736bc91..59cf74c 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -22,6 +22,7 @@ env: GOOGLE_OAUTH_CLIENT_SECRET: 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 refresh_token: 1//0gCf5fxAgSqNcCgYIARAAGBASNwF-L9IrIWxWwqmboeJkEzVn0sqxbaeyWXODE5s24V7pSdiAzFM2cxOUC9XT_xp7t_60o3JMfOg email_id: 200010030@iitdh.ac.in + s_email: 200010024@iitdh.ac.in roll_no: 200010030 jobs: diff --git a/CDC_Backend/APIs/tests/test_adminView.py b/CDC_Backend/APIs/tests/test_adminView.py index da24c04..488f441 100644 --- a/CDC_Backend/APIs/tests/test_adminView.py +++ b/CDC_Backend/APIs/tests/test_adminView.py @@ -14,7 +14,7 @@ class AdminView(APITestCase): def setUp(self): self.client = APIClient() self.admin = User.objects.create(email=str(os.environ.get( - "email")), id=generateRandomString(), user_type=[ADMIN]) + "email_id")), id=generateRandomString(), user_type=[ADMIN]) self.s_admin = User.objects.create(email=str(os.environ.get( "s_email")), id=generateRandomString(), user_type=["s_admin"]) self.user1 = User.objects.create( From e09273d00847fcfb2dbd36d3a0636b35d2117206 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 05:54:21 +0530 Subject: [PATCH 28/38] print systrace --- CDC_Backend/APIs/companyViews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CDC_Backend/APIs/companyViews.py b/CDC_Backend/APIs/companyViews.py index cd73ce6..4b62728 100644 --- a/CDC_Backend/APIs/companyViews.py +++ b/CDC_Backend/APIs/companyViews.py @@ -298,7 +298,7 @@ def verifyEmail(request): status=status.HTTP_400_BAD_REQUEST) except: logger.warning("Verify Email: " + str(sys.exc_info())) - return Response({'action': "Verify Email", 'message': "Something went wrong"}, + return Response({'action': "Verify Email", 'message': "Something went wrong\n"+str(sys.exc_info())}, status=status.HTTP_400_BAD_REQUEST) From df0fe95dcc15072e3e8e69b4aba094b0ea95e592 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 06:22:58 +0530 Subject: [PATCH 29/38] added sys trace in generate csv --- CDC_Backend/APIs/adminViews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index c93cdc0..657a408 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -458,7 +458,7 @@ def generateCSV(request, id, email, user_type): status=status.HTTP_200_OK) except: logger.warning("Create csv: " + str(sys.exc_info())) - return Response({'action': "Create csv", 'message': "Something Went Wrong"}, + return Response({'action': "Create csv", 'message': "Something Went Wrong"+str(sys.exc_info())}, status=status.HTTP_400_BAD_REQUEST) From 12ec9619a612067fb4b360110f4d9edbb18fd5dd Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 06:29:44 +0530 Subject: [PATCH 30/38] fix directory if not exists --- CDC_Backend/APIs/adminViews.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index 657a408..b951605 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -425,7 +425,8 @@ def generateCSV(request, id, email, user_type): applications = PlacementApplication.objects.filter(placement=opening) filename = generateRandomString() if not os.path.isdir(STORAGE_DESTINATION_APPLICATION_CSV): - os.mkdir(STORAGE_DESTINATION_APPLICATION_CSV) + # create directory if not present already even if first directory is not present + os.makedirs(STORAGE_DESTINATION_APPLICATION_CSV, exist_ok=True) destination_path = STORAGE_DESTINATION_APPLICATION_CSV + filename + ".csv" f = open(destination_path, 'w') writer = csv.writer(f) From 41adfa3796c12cb72782a9843570038793660fb8 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 07:18:28 +0530 Subject: [PATCH 31/38] fix token errors --- CDC_Backend/APIs/adminViews.py | 3 +-- CDC_Backend/APIs/companyViews.py | 2 +- CDC_Backend/APIs/tests/test_studentView.py | 8 +++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index b951605..50a5ad8 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -425,7 +425,6 @@ def generateCSV(request, id, email, user_type): applications = PlacementApplication.objects.filter(placement=opening) filename = generateRandomString() if not os.path.isdir(STORAGE_DESTINATION_APPLICATION_CSV): - # create directory if not present already even if first directory is not present os.makedirs(STORAGE_DESTINATION_APPLICATION_CSV, exist_ok=True) destination_path = STORAGE_DESTINATION_APPLICATION_CSV + filename + ".csv" f = open(destination_path, 'w') @@ -459,7 +458,7 @@ def generateCSV(request, id, email, user_type): status=status.HTTP_200_OK) except: logger.warning("Create csv: " + str(sys.exc_info())) - return Response({'action': "Create csv", 'message': "Something Went Wrong"+str(sys.exc_info())}, + return Response({'action': "Create csv", 'message': "Something Went Wrong"}, status=status.HTTP_400_BAD_REQUEST) diff --git a/CDC_Backend/APIs/companyViews.py b/CDC_Backend/APIs/companyViews.py index 4b62728..cd73ce6 100644 --- a/CDC_Backend/APIs/companyViews.py +++ b/CDC_Backend/APIs/companyViews.py @@ -298,7 +298,7 @@ def verifyEmail(request): status=status.HTTP_400_BAD_REQUEST) except: logger.warning("Verify Email: " + str(sys.exc_info())) - return Response({'action': "Verify Email", 'message': "Something went wrong\n"+str(sys.exc_info())}, + return Response({'action': "Verify Email", 'message': "Something went wrong"}, status=status.HTTP_400_BAD_REQUEST) diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py index e737387..21ce5ad 100644 --- a/CDC_Backend/APIs/tests/test_studentView.py +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -303,7 +303,7 @@ class StudentViewsTestCase(APITestCase): def test_add_application_placement_deadlinePassed(self): self.placement.deadline_datetime = timezone.now().replace( - hour=0, minute=0, second=0, microsecond=0) + hour=0, minute=0, second=0, microsecond=0) - datetime.timedelta(minutes=5) self.placement.save() # deleted existing application self.placement_application.delete() @@ -561,8 +561,10 @@ class StudentViewsTestCase(APITestCase): student=self.student).count(), 1) def test_add_application_internship_deadlinePassed(self): - self.internship.deadline_datetime = timezone.now().replace( - hour=0, minute=0, second=0, microsecond=0) + # now minus 5 minutes + self.internship.deadline_datetime = timezone.now().replace + (hour=0, minute=0, second=0, microsecond=0) - datetime.timedelta(minutes=5) + self.internship.save() # deleted existing application self.internship_application.delete() From 83b8a772c3e20f2888c5ec951fc61c961f75dce7 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 07:21:53 +0530 Subject: [PATCH 32/38] fix error in testing --- CDC_Backend/APIs/tests/test_studentView.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py index 21ce5ad..89ffd93 100644 --- a/CDC_Backend/APIs/tests/test_studentView.py +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -562,8 +562,7 @@ class StudentViewsTestCase(APITestCase): def test_add_application_internship_deadlinePassed(self): # now minus 5 minutes - self.internship.deadline_datetime = timezone.now().replace - (hour=0, minute=0, second=0, microsecond=0) - datetime.timedelta(minutes=5) + self.internship.deadline_datetime = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) - datetime.timedelta(minutes=5) self.internship.save() # deleted existing application From 653755d4c97ca5562a68f9bbbf283106dc97af12 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Wed, 11 Oct 2023 07:56:06 +0530 Subject: [PATCH 33/38] fix time errors in deadline --- CDC_Backend/APIs/studentViews.py | 4 ++-- CDC_Backend/APIs/tests/test_studentView.py | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index a2e6584..c269a50 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -188,7 +188,7 @@ def submitApplication(request, id, email, user_type): opening = get_object_or_404(Placement, id=data[OPENING_ID], allowed_batch__contains=[student.batch], allowed_branch__contains=[student.branch], - deadline_datetime__gte=datetime.datetime.now().date() + deadline_datetime__gte=timezone.now() ) if not opening.offer_accepted or not opening.email_verified: raise PermissionError("Placement Not Approved") @@ -209,7 +209,7 @@ def submitApplication(request, id, email, user_type): opening = get_object_or_404(Internship, id=data[OPENING_ID], allowed_batch__contains=[student.batch], allowed_branch__contains=[student.branch], - deadline_datetime__gte=datetime.datetime.now().date() + deadline_datetime__gte=timezone.now() ) if not opening.offer_accepted or not opening.email_verified: raise PermissionError("Internship Not Approved") diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py index 89ffd93..3674f7c 100644 --- a/CDC_Backend/APIs/tests/test_studentView.py +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -303,7 +303,7 @@ class StudentViewsTestCase(APITestCase): def test_add_application_placement_deadlinePassed(self): self.placement.deadline_datetime = timezone.now().replace( - hour=0, minute=0, second=0, microsecond=0) - datetime.timedelta(minutes=5) + hour=0, minute=0, second=0, microsecond=0) self.placement.save() # deleted existing application self.placement_application.delete() @@ -561,9 +561,7 @@ class StudentViewsTestCase(APITestCase): student=self.student).count(), 1) def test_add_application_internship_deadlinePassed(self): - # now minus 5 minutes - self.internship.deadline_datetime = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) - datetime.timedelta(minutes=5) - + self.internship.deadline_datetime = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) self.internship.save() # deleted existing application self.internship_application.delete() From 729d3ef59a2e1871f7a96050babc03370c3596ca Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Thu, 19 Oct 2023 03:03:18 +0530 Subject: [PATCH 34/38] changed env variables names --- CDC_Backend/APIs/tests/test_adminView.py | 6 ++---- CDC_Backend/APIs/tests/test_studentView.py | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CDC_Backend/APIs/tests/test_adminView.py b/CDC_Backend/APIs/tests/test_adminView.py index 488f441..cabc1bc 100644 --- a/CDC_Backend/APIs/tests/test_adminView.py +++ b/CDC_Backend/APIs/tests/test_adminView.py @@ -14,9 +14,7 @@ class AdminView(APITestCase): def setUp(self): self.client = APIClient() self.admin = User.objects.create(email=str(os.environ.get( - "email_id")), id=generateRandomString(), user_type=[ADMIN]) - self.s_admin = User.objects.create(email=str(os.environ.get( - "s_email")), id=generateRandomString(), user_type=["s_admin"]) + "EMAIL")), id=generateRandomString(), user_type=[ADMIN]) self.user1 = User.objects.create( email="200010032@iitdh.ac.in", id="200010032", user_type=[STUDENT]) self.user2 = User.objects.create( @@ -79,7 +77,7 @@ class AdminView(APITestCase): id=generateRandomString(), student=self.student3, internship=self.internship2, resume="8BSLybntULgrPPm_beehyv.pdf") response = self.client.post(reverse('Refresh Token'), { - 'refresh_token': os.environ.get("refresh_token")}, format='json') + 'refresh_token': os.environ.get("REFRESH_TOKEN")}, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py index 3674f7c..7ef1cd0 100644 --- a/CDC_Backend/APIs/tests/test_studentView.py +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -15,13 +15,13 @@ class StudentViewsTestCase(APITestCase): def setUp(self): self.client = APIClient() self.user = User.objects.create( - email=str(os.environ.get("email_id")), - id=str(os.environ.get("roll_no")), + email=str(os.environ.get("EMAIL")), + id=str(os.environ.get("ROLL_NO")), user_type=[STUDENT]) self.assertEqual( self.user.email, User.objects.get(id=self.user.id).email) self.student = Student.objects.create( - name="Test Student", id=self.user.id, resumes=["8BSLybntULgrPPm_beehyv.pdf"], roll_no=str(os.environ.get("roll_no")), branch="CSE", batch="2020", phone_number=1234567890, changed_by=self.user, can_apply=True, + name="Test Student", id=self.user.id, resumes=["8BSLybntULgrPPm_beehyv.pdf"], roll_no=str(os.environ.get("ROLL_NO")), branch="CSE", batch="2020", phone_number=1234567890, changed_by=self.user, can_apply=True, can_apply_internship=True, degree="bTech", cpi=7.95, ) self.assertEqual(self.student.name, @@ -61,7 +61,7 @@ class StudentViewsTestCase(APITestCase): # get token from google OAuth API response = self.client.post(reverse('Refresh Token'), { - 'refresh_token': os.environ.get("refresh_token")}, format='json') + 'refresh_token': os.environ.get("REFRESH_TOKEN")}, format='json') self.student_token = response.data['id_token'] def test_student_accept_offer_internship(self): From 32870efd18cf230852a11beee694cf4dcec997d6 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Thu, 19 Oct 2023 03:09:01 +0530 Subject: [PATCH 35/38] clean up --- CDC_Backend/APIs/admin.py | 8 ++++---- CDC_Backend/APIs/adminViews.py | 6 +++--- CDC_Backend/APIs/constants.py | 4 ++-- CDC_Backend/APIs/studentViews.py | 2 +- CDC_Backend/APIs/utils.py | 4 ---- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/CDC_Backend/APIs/admin.py b/CDC_Backend/APIs/admin.py index a14a7d9..e44b2ea 100644 --- a/CDC_Backend/APIs/admin.py +++ b/CDC_Backend/APIs/admin.py @@ -149,8 +149,8 @@ class InternshipApplicationAdmin(ExportMixin, SimpleHistoryAdmin): @admin.register(PlacementApplication) class PlacementApplication(PlacementAdmin): list_display = ('id', 'Placement', 'Student', 'selected') - search_fields = ('id',) - ordering = ('id',) + search_fields = ('id','Placement', 'Student') + ordering = ('id','Placement', 'Student') list_filter = ('selected',) def Placement(self, obj): @@ -161,8 +161,8 @@ class PlacementApplication(PlacementAdmin): @admin.register(InternshipApplication) class InternshipApplication(InternshipApplicationAdmin): list_display = ('id', 'Internship', 'Student', 'selected') - search_fields = ('id',) - ordering = ('id',) + search_fields = ('id', 'Internship', 'Student') + ordering = ('id', 'Internship', 'Student') list_filter = ('selected',) def Internship(self, obj): diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index 50a5ad8..429260e 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -20,10 +20,7 @@ def markStatus(request, id, email, user_type): applications = InternshipApplication.objects.filter(internship_id=data[OPENING_ID]) else: applications = PlacementApplication.objects.filter(placement_id=data[OPENING_ID]) - # Getting all application from db for this opening - # applications = PlacementApplication.objects.filter(placement_id=data[OPENING_ID]) for i in data[STUDENT_LIST]: - # print(i[STUDENT_ID]) issue is using student id instead of roll no both may not be same #remember this application = applications.filter(student__roll_no=i[STUDENT_ID]) # Filtering student's application if len(application) > 0: application = application[0] @@ -565,6 +562,7 @@ def getStats(request, id, email, user_type): "5":0, "6":0, "7":0, + "8":0, "psu":0, }, "EE": { @@ -585,6 +583,7 @@ def getStats(request, id, email, user_type): "5":0, "6":0, "7":0, + "8":0, "psu":0, }, @@ -596,6 +595,7 @@ def getStats(request, id, email, user_type): "5":0, "6":0, "7":0, + "8":0, "psu":0, }, } diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index 8ebfcf1..12ac4fb 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -74,8 +74,8 @@ CDC_REPS_EMAILS = [ "ramesh.nayaka@iitdh.ac.in" ] CDC_REPS_EMAILS_FOR_ISSUE=[ #add reps emails - "support.cdc@iitdh.ac.in" - "irontwist00@gmail.com" + "cdc.support@iitdh.ac.in", + "cdc@iitdh.ac.in" ] # To be Configured Properly diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index c269a50..f373ca8 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -179,7 +179,7 @@ def submitApplication(request, id, email, user_type): # Only Allowing Applications for Placements if data[OPENING_TYPE] == PLACEMENT: - if not student.can_apply: #why not checking in admin + if not student.can_apply: return Response({'action': "Submit Application", 'message': "Student Can't Apply"}, status=status.HTTP_400_BAD_REQUEST) if not len(PlacementApplication.objects.filter( diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index 69e97a2..10f1c0c 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -112,12 +112,10 @@ def isAuthorized(allowed_users=None): def wrapper_func(request, *args, **kwargs): try: headers = request.META - #print(headers) if 'HTTP_AUTHORIZATION' in headers: token_id = headers['HTTP_AUTHORIZATION'][7:] idinfo = id_token.verify_oauth2_token(token_id, requests.Request(), CLIENT_ID) email = idinfo[EMAIL] - # print(idinfo) user = get_object_or_404(User, email=email) if user: user.last_login_time = timezone.now() @@ -169,8 +167,6 @@ def saveFile(file, location): file_name = re.sub(r'[\\/:*?"<>|]', '_', file_name) - # print("Inside saveFile: " + str(file_name)) - if not path.isdir(location): os.makedirs(location) From d78aec241aaa9ac28452c8d89217165ae48a0ace Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Thu, 19 Oct 2023 04:19:49 +0530 Subject: [PATCH 36/38] fixed error --- .github/workflows/django.yml | 7 +++---- CDC_Backend/APIs/admin.py | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 59cf74c..a1e7a09 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -20,10 +20,9 @@ env: GOOGLE_OAUTH_CLIENT_ID: 628308091838-nvfn455vabbq7j0odd797sls8itpplmr.apps.googleusercontent.com SECRET_KEY: 9%2e!&f6(ib^690y48z)&w6fczhwukzzp@3y*^*7u+7%4s-mie GOOGLE_OAUTH_CLIENT_SECRET: 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 - refresh_token: 1//0gCf5fxAgSqNcCgYIARAAGBASNwF-L9IrIWxWwqmboeJkEzVn0sqxbaeyWXODE5s24V7pSdiAzFM2cxOUC9XT_xp7t_60o3JMfOg - email_id: 200010030@iitdh.ac.in - s_email: 200010024@iitdh.ac.in - roll_no: 200010030 + REFRESH_TOKEN: 1//0gCf5fxAgSqNcCgYIARAAGBASNwF-L9IrIWxWwqmboeJkEzVn0sqxbaeyWXODE5s24V7pSdiAzFM2cxOUC9XT_xp7t_60o3JMfOg + EMAIL_ID: 200010030@iitdh.ac.in + ROLL_NO: 200010030 jobs: build: diff --git a/CDC_Backend/APIs/admin.py b/CDC_Backend/APIs/admin.py index e44b2ea..a14a7d9 100644 --- a/CDC_Backend/APIs/admin.py +++ b/CDC_Backend/APIs/admin.py @@ -149,8 +149,8 @@ class InternshipApplicationAdmin(ExportMixin, SimpleHistoryAdmin): @admin.register(PlacementApplication) class PlacementApplication(PlacementAdmin): list_display = ('id', 'Placement', 'Student', 'selected') - search_fields = ('id','Placement', 'Student') - ordering = ('id','Placement', 'Student') + search_fields = ('id',) + ordering = ('id',) list_filter = ('selected',) def Placement(self, obj): @@ -161,8 +161,8 @@ class PlacementApplication(PlacementAdmin): @admin.register(InternshipApplication) class InternshipApplication(InternshipApplicationAdmin): list_display = ('id', 'Internship', 'Student', 'selected') - search_fields = ('id', 'Internship', 'Student') - ordering = ('id', 'Internship', 'Student') + search_fields = ('id',) + ordering = ('id',) list_filter = ('selected',) def Internship(self, obj): From 59b88201d31086f2e680f120a931a8109f0e2511 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Thu, 19 Oct 2023 04:24:55 +0530 Subject: [PATCH 37/38] django env in django.yml --- .github/workflows/django.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index a1e7a09..6bf50b8 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -21,7 +21,7 @@ env: SECRET_KEY: 9%2e!&f6(ib^690y48z)&w6fczhwukzzp@3y*^*7u+7%4s-mie GOOGLE_OAUTH_CLIENT_SECRET: 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 REFRESH_TOKEN: 1//0gCf5fxAgSqNcCgYIARAAGBASNwF-L9IrIWxWwqmboeJkEzVn0sqxbaeyWXODE5s24V7pSdiAzFM2cxOUC9XT_xp7t_60o3JMfOg - EMAIL_ID: 200010030@iitdh.ac.in + EMAIL: 200010030@iitdh.ac.in ROLL_NO: 200010030 jobs: From 761571321348230e1c9a4351253ace9eb3eff904 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Thu, 19 Oct 2023 04:29:52 +0530 Subject: [PATCH 38/38] fixed errors --- .github/workflows/django.yml | 2 +- CDC_Backend/APIs/tests/test_adminView.py | 2 +- CDC_Backend/APIs/tests/test_studentView.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 6bf50b8..a1e7a09 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -21,7 +21,7 @@ env: SECRET_KEY: 9%2e!&f6(ib^690y48z)&w6fczhwukzzp@3y*^*7u+7%4s-mie GOOGLE_OAUTH_CLIENT_SECRET: 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 REFRESH_TOKEN: 1//0gCf5fxAgSqNcCgYIARAAGBASNwF-L9IrIWxWwqmboeJkEzVn0sqxbaeyWXODE5s24V7pSdiAzFM2cxOUC9XT_xp7t_60o3JMfOg - EMAIL: 200010030@iitdh.ac.in + EMAIL_ID: 200010030@iitdh.ac.in ROLL_NO: 200010030 jobs: diff --git a/CDC_Backend/APIs/tests/test_adminView.py b/CDC_Backend/APIs/tests/test_adminView.py index cabc1bc..9f455ab 100644 --- a/CDC_Backend/APIs/tests/test_adminView.py +++ b/CDC_Backend/APIs/tests/test_adminView.py @@ -14,7 +14,7 @@ class AdminView(APITestCase): def setUp(self): self.client = APIClient() self.admin = User.objects.create(email=str(os.environ.get( - "EMAIL")), id=generateRandomString(), user_type=[ADMIN]) + "EMAIL_ID")), id=generateRandomString(), user_type=[ADMIN]) self.user1 = User.objects.create( email="200010032@iitdh.ac.in", id="200010032", user_type=[STUDENT]) self.user2 = User.objects.create( diff --git a/CDC_Backend/APIs/tests/test_studentView.py b/CDC_Backend/APIs/tests/test_studentView.py index 7ef1cd0..f730989 100644 --- a/CDC_Backend/APIs/tests/test_studentView.py +++ b/CDC_Backend/APIs/tests/test_studentView.py @@ -15,7 +15,7 @@ class StudentViewsTestCase(APITestCase): def setUp(self): self.client = APIClient() self.user = User.objects.create( - email=str(os.environ.get("EMAIL")), + email=str(os.environ.get("EMAIL_ID")), id=str(os.environ.get("ROLL_NO")), user_type=[STUDENT]) self.assertEqual(