Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
adega
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
64
Issues
64
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
adega
adega
Commits
b99c3551
Commit
b99c3551
authored
Apr 14, 2019
by
Wellington Gabriel Vicente de Souza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#171
: refactoring of code and moving tests to correct files
parent
cb2cccc8
Pipeline
#20019
failed with stage
in 2 minutes and 41 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
278 additions
and
78 deletions
+278
-78
src/admission/tests.py
src/admission/tests.py
+60
-2
src/course/tests.py
src/course/tests.py
+56
-2
src/degree/tests.py
src/degree/tests.py
+52
-2
src/student/tests.py
src/student/tests.py
+56
-2
src/submission/tests.py
src/submission/tests.py
+54
-70
No files found.
src/admission/tests.py
View file @
b99c3551
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
src/course/tests.py
View file @
b99c3551
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
src/degree/tests.py
View file @
b99c3551
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
src/student/tests.py
View file @
b99c3551
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
src/submission/tests.py
View file @
b99c3551
...
...
@@ -4,7 +4,45 @@ from submission.models import Submission
from
educator.models
import
Educator
from
degree.models
import
Degree
class
SubmissionTest
(
TestCase
):
class
SubmissionMixin
(
object
):
def
createSubmission
(
self
,
degree_id
):
# trying to submit data for analysis
historico_path
=
'/adega/src/submission/analysis/test/historico.xls'
matricula_path
=
'/adega/src/submission/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
...
...
@@ -15,7 +53,7 @@ class SubmissionTest(TestCase):
cls
.
user
=
User
.
objects
.
create_user
(
**
cls
.
credentials
)
cls
.
user
.
save
()
# create
s
a degree
# create a degree
cls
.
degree
=
Degree
.
objects
.
create
(
name
=
"Curso ficticio"
,
code
=
"00A"
,
manager_id
=
cls
.
user
.
id
)
cls
.
degree
.
save
()
...
...
@@ -25,84 +63,30 @@ class SubmissionTest(TestCase):
cls
.
educator
.
degree
.
add
(
cls
.
degree
)
cls
.
educator
.
save
()
def
testSubmissionRoutes
(
self
):
# login
login_data
=
{
# login data
cls
.
login_data
=
{
'email'
:
'testuser@user.com'
,
'password'
:
'secret'
}
response
=
self
.
client
.
post
(
'/public/'
,
login_data
,
follow
=
True
)
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/
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
historico_path
=
'/adega/src/submission/analysis/test/historico.xls'
matricula_path
=
'/adega/src/submission/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'
:
'1'
}
response
=
self
.
client
.
post
(
'/submission/create/'
,
report_data
,
follow
=
True
)
response
=
self
.
createSubmission
(
self
.
degree
.
id
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# if ne, failed to submit report to /submission/create/
# checking if the submission was properly analyzed
analysis
=
Submission
.
objects
.
first
()
self
.
assertEqual
(
analysis
.
analysis_status
,
1
)
# if ne, failed to analyze report
# store for use in the following tests
a_id
=
str
(
analysis
.
id
)
# 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/
# 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/
# 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/
# trying to access /admission/id/
response
=
self
.
client
.
get
(
'/admission/'
+
a_id
+
'/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# if ne, failed to access /admission/id/
# trying to access /admission/id/YEAR/SEMESTER
response
=
self
.
client
.
get
(
'/admission/'
+
a_id
+
'/2012/1/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# if ne, failed to access /admission/id/YEAR/SEMESTER
# leave for last, destroying submission via /submission/delete/id
response
=
self
.
client
.
post
(
'/submission/delete/'
+
a_id
,
follow
=
True
)
self
.
assertEqual
(
len
(
Submission
.
objects
.
all
()),
0
)
# if ne, failed to delete submission
# 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment