Commit 18b40df9 authored by bhmeyer's avatar bhmeyer

Merge branch '171-escrever-testes-automatizados' into 'development'

Resolve "Escrever testes automatizados"

Closes #171

See merge request !81
parents c645a080 d6664593
Pipeline #20099 passed with stage
in 3 minutes and 36 seconds
from django.test import TestCase
from django.test import TestCase, Client
from django.contrib.auth.models import User
from submission.models import Submission
from educator.models import Educator
from degree.models import Degree
import sys, os
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../submission/')
from tests import SubmissionMixin
# Create your tests here.
class AdmissionTest(TestCase, SubmissionMixin):
@classmethod
def setUpTestData(cls):
# instantiate a Client to make requests
cls.client = Client(HTTP_USER_AGENT='Mozilla/5.0')
# create user
cls.credentials = {"username":"testuser","email":"testuser@user.com","password":"secret"}
cls.user = User.objects.create_user(**cls.credentials)
cls.user.save()
# create a degree
cls.degree = Degree.objects.create(name="Curso ficticio", code="00A", manager_id=cls.user.id)
cls.degree.save()
# create an educator
cls.educator = Educator.objects.create(user_id=cls.user.id)
cls.educator.save()
cls.educator.degree.add(cls.degree)
cls.educator.save()
# login data
cls.login_data = {
'email': 'testuser@user.com',
'password': 'secret'
}
def testAdmissionRoutes(self):
# logging in
response = self.client.post('/public/', self.login_data, follow=True)
# submitting report
response = self.createSubmission(self.degree.id)
# checks if submission was properly analyzed and gets its id
a_id = self.getSubmissionId()
# trying to access /course/id/
response = self.client.get('/course/' + a_id + '/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /course/id/
# trying to access /course/id/DIS/
response = self.client.get('/course/' + a_id + '/Dis1/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /course/id/DIS/
# trying to access /course/id/compare/
response = self.client.get('/course/' + a_id + '/compare/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /course/id/compare/
# deletes submission
self.deleteSubmission(a_id)
\ No newline at end of file
from django.test import TestCase
from django.test import TestCase, Client
from django.contrib.auth.models import User
from submission.models import Submission
from educator.models import Educator
from degree.models import Degree
import sys, os
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../submission/')
from tests import SubmissionMixin
# Create your tests here.
class CourseTest(TestCase, SubmissionMixin):
@classmethod
def setUpTestData(cls):
# instantiate a Client to make requests
cls.client = Client(HTTP_USER_AGENT='Mozilla/5.0')
# create user
cls.credentials = {"username":"testuser","email":"testuser@user.com","password":"secret"}
cls.user = User.objects.create_user(**cls.credentials)
cls.user.save()
# create a degree
cls.degree = Degree.objects.create(name="Curso ficticio", code="00A", manager_id=cls.user.id)
cls.degree.save()
# create an educator
cls.educator = Educator.objects.create(user_id=cls.user.id)
cls.educator.save()
cls.educator.degree.add(cls.degree)
cls.educator.save()
# login data
cls.login_data = {
'email': 'testuser@user.com',
'password': 'secret'
}
def testCourseRoutes(self):
# logging in
response = self.client.post('/public/', self.login_data, follow=True)
# submitting report
response = self.createSubmission(self.degree.id)
# checks if submission was properly analyzed and gets its id
a_id = self.getSubmissionId()
# trying to access /student/id/
response = self.client.get('/student/' + a_id + '/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /student/id/
# trying to access /student/id/GRR/
response = self.client.get('/student/' + a_id + '/GRR20130000/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /student/id/GRR/
# deletes submission
self.deleteSubmission(a_id)
\ No newline at end of file
from django.test import TestCase
from django.test import TestCase, Client
from django.contrib.auth.models import User
from submission.models import Submission
from educator.models import Educator
from degree.models import Degree
import sys, os
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../submission/')
from tests import SubmissionMixin
# Create your tests here.
class DegreeTest(TestCase, SubmissionMixin):
@classmethod
def setUpTestData(cls):
# instantiate a Client to make requests
cls.client = Client(HTTP_USER_AGENT='Mozilla/5.0')
# create user
cls.credentials = {"username":"testuser","email":"testuser@user.com","password":"secret"}
cls.user = User.objects.create_user(**cls.credentials)
cls.user.save()
# create a degree
cls.degree = Degree.objects.create(name="Curso ficticio", code="00A", manager_id=cls.user.id)
cls.degree.save()
# create an educator
cls.educator = Educator.objects.create(user_id=cls.user.id)
cls.educator.save()
cls.educator.degree.add(cls.degree)
cls.educator.save()
# login data
cls.login_data = {
'email': 'testuser@user.com',
'password': 'secret'
}
def testDegreeRoutes(self):
# logging in
response = self.client.post('/public/', self.login_data, follow=True)
# submitting report
response = self.createSubmission(self.degree.id)
# checks if submission was properly analyzed and gets its id
a_id = self.getSubmissionId()
# trying to access /degree/id/
response = self.client.get('/degree/' + a_id + '/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /degree/id/
# deletes submission
self.deleteSubmission(a_id)
\ No newline at end of file
from django.test import TestCase
from django.test import TestCase, Client
from django.contrib.auth.models import User
from submission.models import Submission
from educator.models import Educator
from degree.models import Degree
import sys, os
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../submission/')
from tests import SubmissionMixin
# Create your tests here.
class StudentTest(TestCase, SubmissionMixin):
@classmethod
def setUpTestData(cls):
# instantiate a Client to make requests
cls.client = Client(HTTP_USER_AGENT='Mozilla/5.0')
# create user
cls.credentials = {"username":"testuser","email":"testuser@user.com","password":"secret"}
cls.user = User.objects.create_user(**cls.credentials)
cls.user.save()
# create a degree
cls.degree = Degree.objects.create(name="Curso ficticio", code="00A", manager_id=cls.user.id)
cls.degree.save()
# create an educator
cls.educator = Educator.objects.create(user_id=cls.user.id)
cls.educator.save()
cls.educator.degree.add(cls.degree)
cls.educator.save()
# login data
cls.login_data = {
'email': 'testuser@user.com',
'password': 'secret'
}
def testStudentRoutes(self):
# logging in
response = self.client.post('/public/', self.login_data, follow=True)
# submitting report
response = self.createSubmission(self.degree.id)
# checks if submission was properly analyzed and gets its id
a_id = self.getSubmissionId()
# trying to access /student/id/
response = self.client.get('/student/' + a_id + '/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /student/id/
# trying to access /student/id/GRR/
response = self.client.get('/student/' + a_id + '/GRR20130000/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /student/id/GRR/
# deletes submission
self.deleteSubmission(a_id)
\ No newline at end of file
from django.test import TestCase
from django.test import TestCase, Client
from django.contrib.auth.models import User
from submission.models import Submission
from educator.models import Educator
from degree.models import Degree
import os
# Create your tests here.
class SubmissionMixin(object):
def createSubmission(self, degree_id):
# trying to submit data for analysis
basePath = os.path.dirname(os.path.abspath(__file__))
historico_path = basePath + '/analysis/test/historico.xls'
matricula_path = basePath + '/analysis/test/matricula.xls'
historico = open(historico_path, 'rb')
matricula = open(matricula_path, 'rb')
report_data = {
'historico': historico,
'matricula': matricula,
'relative_year': '2019',
'relative_semester': '1',
'semester_status': '0',
'degree': str(degree_id)
}
response = self.client.post('/submission/create/', report_data, follow=True)
self.assertEqual(response.status_code, 200) # if ne, failed to submit report to /submission/create/
return response
def deleteSubmission(self, a_id):
# get number of objects
count = len(Submission.objects.all())
# destroying submission via /submission/delete/id
response = self.client.post('/submission/delete/' + a_id, follow=True)
self.assertEqual(len(Submission.objects.all()), count-1) # if ne, failed to delete submission
return response
def getSubmissionId(self):
analysis = Submission.objects.first()
self.assertEqual(analysis.analysis_status, 1) # if ne, failed to analyze submission
return str(analysis.id)
class SubmissionTest(TestCase, SubmissionMixin):
@classmethod
def setUpTestData(cls):
# instantiate a Client to make requests
cls.client = Client(HTTP_USER_AGENT='Mozilla/5.0')
# create user
cls.credentials = {"username":"testuser","email":"testuser@user.com","password":"secret"}
cls.user = User.objects.create_user(**cls.credentials)
cls.user.save()
# create a degree
cls.degree = Degree.objects.create(name="Curso ficticio", code="00A", manager_id=cls.user.id)
cls.degree.save()
# create an educator
cls.educator = Educator.objects.create(user_id=cls.user.id)
cls.educator.save()
cls.educator.degree.add(cls.degree)
cls.educator.save()
# login data
cls.login_data = {
'email': 'testuser@user.com',
'password': 'secret'
}
def testSubmissionRoutes(self):
# logging in
response = self.client.post('/public/', self.login_data, follow=True)
# trying to access /submission/ after logging in
response = self.client.get('/submission/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /submission/
# trying to access /submission/create
response = self.client.get('/submission/create/')
self.assertEqual(response.status_code, 200) # if ne, failed to access /submission/create
# trying to submit data for analysis
response = self.createSubmission(self.degree.id)
self.assertEqual(response.status_code, 200) # if ne, failed to submit report to /submission/create/
# checks if submission was properly analyzed and gets its id
a_id = self.getSubmissionId()
# deletes submission
self.deleteSubmission(a_id)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment