testcases

This commit is contained in:
uttamthummala 2023-10-06 03:19:25 +05:30
parent 32de7eebb5
commit 814ed005f1
4 changed files with 1230 additions and 3 deletions

View File

@ -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:

View File

View File

@ -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")
# ---------------------------------------------------------------------------

View File

@ -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)