Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kontr 2.0
Portal API Backend
Commits
93b14274
Verified
Commit
93b14274
authored
Oct 01, 2018
by
Peter Stanko
Browse files
Simplified tests for with assert response and unnecessary headers
parent
bf102b33
Pipeline
#14376
failed with stage
in 37 seconds
Changes
14
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/conftest.py
View file @
93b14274
...
@@ -4,7 +4,9 @@ import pytest
...
@@ -4,7 +4,9 @@ import pytest
from
management.data
import
DataManagement
from
management.data
import
DataManagement
from
portal
import
create_app
,
db
from
portal
import
create_app
,
db
from
portal.database
import
ProjectConfig
from
portal.logger
import
load_config
from
portal.logger
import
load_config
from
tests.utils.ent_mocker
import
EntitiesMocker
load_config
(
'test'
)
load_config
(
'test'
)
...
@@ -39,3 +41,13 @@ def rest_service():
...
@@ -39,3 +41,13 @@ def rest_service():
def
ent_mocker
(
app
):
def
ent_mocker
(
app
):
from
tests.utils.ent_mocker
import
EntitiesMocker
from
tests.utils.ent_mocker
import
EntitiesMocker
return
EntitiesMocker
(
app
,
db
=
db
)
return
EntitiesMocker
(
app
,
db
=
db
)
@
pytest
.
fixture
()
def
mocked_submission
(
ent_mocker
:
EntitiesMocker
,
rest_service
):
submission
=
ent_mocker
.
create_submission
()
rest_service
.
submissions
.
write_entity
(
submission
)
ent_mocker
.
create_submission_storage
(
submission
=
submission
)
project_config
:
ProjectConfig
=
submission
.
project
.
config
project_config
.
test_files_commit_hash
=
'some-random-hash'
return
submission
tests/rest/test_clients.py
View file @
93b14274
...
@@ -4,6 +4,7 @@ import pytest
...
@@ -4,6 +4,7 @@ import pytest
from
portal.database.models
import
Client
,
Secret
from
portal.database.models
import
Client
,
Secret
from
tests.rest
import
rest_tools
from
tests.rest
import
rest_tools
from
tests.rest.rest_tools
import
assert_response
@
pytest
.
fixture
@
pytest
.
fixture
...
@@ -27,9 +28,8 @@ def worker_credentials():
...
@@ -27,9 +28,8 @@ def worker_credentials():
def
test_client_detail_using_student_cred
(
client
,
student_credentials
):
def
test_client_detail_using_student_cred
(
client
,
student_credentials
):
path
=
f
'/client'
path
=
f
'/client'
response
=
rest_tools
.
make_request
(
response
=
rest_tools
.
make_request
(
client
,
path
,
'get'
,
credentials
=
student_credentials
)
client
,
path
,
credentials
=
student_credentials
)
assert
response
.
status_code
==
200
assert_response
(
response
,
200
)
assert
response
.
mimetype
==
'application/json'
data
=
response
.
json
data
=
response
.
json
assert
data
[
'username'
]
==
'student1'
assert
data
[
'username'
]
==
'student1'
assert
data
[
'type'
]
==
'ClientType.USER'
assert
data
[
'type'
]
==
'ClientType.USER'
...
@@ -38,9 +38,9 @@ def test_client_detail_using_student_cred(client, student_credentials):
...
@@ -38,9 +38,9 @@ def test_client_detail_using_student_cred(client, student_credentials):
def
test_client_detail_using_executor_cred
(
client
,
worker_credentials
):
def
test_client_detail_using_executor_cred
(
client
,
worker_credentials
):
path
=
f
'/client'
path
=
f
'/client'
response
=
rest_tools
.
make_request
(
response
=
rest_tools
.
make_request
(
client
,
path
,
'get'
,
credentials
=
worker_credentials
)
client
,
path
,
credentials
=
worker_credentials
)
assert
response
.
status_code
==
200
assert
_
response
(
response
,
200
)
assert
response
.
mimetype
==
'application/json'
data
=
response
.
json
data
=
response
.
json
assert
data
[
'name'
]
==
'executor'
assert
data
[
'name'
]
==
'executor'
assert
data
[
'type'
]
==
'ClientType.WORKER'
assert
data
[
'type'
]
==
'ClientType.WORKER'
...
@@ -50,12 +50,10 @@ def test_create_secret(client):
...
@@ -50,12 +50,10 @@ def test_create_secret(client):
instance
=
Client
.
query
.
filter_by
(
codename
=
"executor"
).
first
()
instance
=
Client
.
query
.
filter_by
(
codename
=
"executor"
).
first
()
request_dict
=
dict
(
name
=
"new_secret"
)
request_dict
=
dict
(
name
=
"new_secret"
)
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
instance
.
id
}
/secrets'
,
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
instance
.
id
}
/secrets'
,
headers
=
{
"content-type"
:
"application/json"
},
json
=
request_dict
,
data
=
json
.
dumps
(
request_dict
),
method
=
'post'
)
method
=
'post'
)
assert
response
.
status_code
==
201
assert_response
(
response
,
201
)
assert
response
.
mimetype
==
'application/json'
parsed
=
response
.
json
parsed
=
response
.
json
assert
parsed
[
'value'
]
is
not
None
assert
parsed
[
'value'
]
is
not
None
assert
parsed
[
'id'
]
is
not
None
assert
parsed
[
'id'
]
is
not
None
...
@@ -67,12 +65,9 @@ def test_create_secret(client):
...
@@ -67,12 +65,9 @@ def test_create_secret(client):
def
test_list_secret
(
client
):
def
test_list_secret
(
client
):
instance
=
Client
.
query
.
filter_by
(
codename
=
"executor"
).
first
()
instance
=
Client
.
query
.
filter_by
(
codename
=
"executor"
).
first
()
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
instance
.
id
}
/secrets'
,
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
instance
.
id
}
/secrets'
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'get'
)
assert
response
.
status_code
==
200
assert_response
(
response
,
200
)
assert
response
.
mimetype
==
'application/json'
secrets
=
rest_tools
.
extract_data
(
response
)
secrets
=
rest_tools
.
extract_data
(
response
)
assert
len
(
secrets
)
==
1
assert
len
(
secrets
)
==
1
...
@@ -81,7 +76,6 @@ def test_delete_secret(client):
...
@@ -81,7 +76,6 @@ def test_delete_secret(client):
worker
=
Client
.
query
.
filter_by
(
codename
=
"executor"
).
first
()
worker
=
Client
.
query
.
filter_by
(
codename
=
"executor"
).
first
()
secret
=
Secret
.
query
.
filter_by
(
client
=
worker
).
first
()
secret
=
Secret
.
query
.
filter_by
(
client
=
worker
).
first
()
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
worker
.
id
}
/secrets/
{
secret
.
id
}
'
,
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
worker
.
id
}
/secrets/
{
secret
.
id
}
'
,
headers
=
{
"content-type"
:
"application/json"
},
method
=
'delete'
)
method
=
'delete'
)
assert
response
.
status_code
==
204
assert
response
.
status_code
==
204
...
@@ -92,12 +86,9 @@ def test_delete_secret(client):
...
@@ -92,12 +86,9 @@ def test_delete_secret(client):
def
test_read_secret
(
client
):
def
test_read_secret
(
client
):
instance
=
Client
.
query
.
filter_by
(
codename
=
"executor"
).
first
()
instance
=
Client
.
query
.
filter_by
(
codename
=
"executor"
).
first
()
secret
=
Secret
.
query
.
filter_by
(
client
=
instance
).
first
()
secret
=
Secret
.
query
.
filter_by
(
client
=
instance
).
first
()
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
instance
.
id
}
/secrets/
{
secret
.
id
}
'
,
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
instance
.
id
}
/secrets/
{
secret
.
id
}
'
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'get'
)
assert
response
.
status_code
==
200
assert_response
(
response
,
200
)
assert
response
.
mimetype
==
'application/json'
response_secret
=
rest_tools
.
extract_data
(
response
)
response_secret
=
rest_tools
.
extract_data
(
response
)
assert
response_secret
[
'id'
]
==
secret
.
id
assert
response_secret
[
'id'
]
==
secret
.
id
assert
response_secret
[
'name'
]
==
secret
.
name
assert
response_secret
[
'name'
]
==
secret
.
name
...
@@ -110,11 +101,10 @@ def test_update_secret(client):
...
@@ -110,11 +101,10 @@ def test_update_secret(client):
request_dict
=
dict
(
name
=
"new_name"
)
request_dict
=
dict
(
name
=
"new_name"
)
secret
=
Secret
.
query
.
filter_by
(
client
=
instance
).
first
()
secret
=
Secret
.
query
.
filter_by
(
client
=
instance
).
first
()
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
instance
.
id
}
/secrets/
{
secret
.
id
}
'
,
response
=
rest_tools
.
make_request
(
client
,
f
'/clients/
{
instance
.
id
}
/secrets/
{
secret
.
id
}
'
,
headers
=
{
"content-type"
:
"application/json"
},
json
=
request_dict
,
data
=
json
.
dumps
(
request_dict
),
method
=
'put'
)
method
=
'put'
)
assert
response
.
status_code
==
204
assert
_
response
(
response
,
204
)
updated_secret
=
Secret
.
query
.
filter_by
(
client
=
instance
).
first
()
updated_secret
=
Secret
.
query
.
filter_by
(
client
=
instance
).
first
()
assert
updated_secret
.
id
==
secret
.
id
assert
updated_secret
.
id
==
secret
.
id
assert
updated_secret
.
name
==
"new_name"
assert
updated_secret
.
name
==
"new_name"
...
...
tests/rest/test_course.py
View file @
93b14274
import
json
import
json
from
portal.database.models
import
Course
from
portal.database.models
import
Course
from
portal.service
import
courses
,
general
from
tests.rest.rest_tools
import
assert_response
from
portal.service.courses
import
CourseService
from
.
import
rest_tools
from
.
import
rest_tools
def
test_list
(
client
):
def
test_list
(
client
):
response
=
rest_tools
.
make_request
(
client
,
'/courses'
,
method
=
'get'
)
response
=
rest_tools
.
make_request
(
client
,
'/courses'
)
assert
response
.
status_code
==
200
assert_response
(
response
)
assert
response
.
mimetype
==
'application/json'
courses_response
=
rest_tools
.
extract_data
(
response
)
courses_response
=
rest_tools
.
extract_data
(
response
)
assert
len
(
courses_response
)
==
2
assert
len
(
courses_response
)
==
2
...
@@ -22,16 +20,11 @@ def test_create(client):
...
@@ -22,16 +20,11 @@ def test_create(client):
request_dict
=
dict
(
request_dict
=
dict
(
name
=
"java"
,
name
=
"java"
,
codename
=
"PA165"
,
codename
=
"PA165"
,
)
)
db_courses_number
=
len
(
Course
.
query
.
all
())
db_courses_number
=
len
(
Course
.
query
.
all
())
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
'/courses'
,
json
=
request_dict
,
method
=
'post'
)
response
=
rest_tools
.
make_request
(
client
,
'/courses'
,
data
=
request_json
,
assert_response
(
response
,
201
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'post'
)
assert
response
.
status_code
==
201
assert
response
.
mimetype
==
'application/json'
resp_new_course
=
rest_tools
.
extract_data
(
response
)
resp_new_course
=
rest_tools
.
extract_data
(
response
)
db_courses
=
Course
.
query
.
all
()
db_courses
=
Course
.
query
.
all
()
assert
len
(
db_courses
)
==
db_courses_number
+
1
assert
len
(
db_courses
)
==
db_courses_number
+
1
...
@@ -43,15 +36,11 @@ def test_create_extra_key(client):
...
@@ -43,15 +36,11 @@ def test_create_extra_key(client):
name
=
"java"
,
name
=
"java"
,
codename
=
"PA165"
,
codename
=
"PA165"
,
extra
=
"should not be here"
extra
=
"should not be here"
)
)
db_courses_number
=
len
(
Course
.
query
.
all
())
db_courses_number
=
len
(
Course
.
query
.
all
())
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
'/courses'
,
json
=
request_dict
,
method
=
'post'
)
response
=
rest_tools
.
make_request
(
client
,
'/courses'
,
data
=
request_json
,
assert_response
(
response
,
201
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'post'
)
assert
response
.
status_code
==
201
assert
response
.
mimetype
==
'application/json'
resp_new_course
=
rest_tools
.
extract_data
(
response
)
resp_new_course
=
rest_tools
.
extract_data
(
response
)
db_courses
=
Course
.
query
.
all
()
db_courses
=
Course
.
query
.
all
()
...
@@ -63,12 +52,9 @@ def test_create_missing_name(client):
...
@@ -63,12 +52,9 @@ def test_create_missing_name(client):
request_dict
=
dict
(
codename
=
"PA165"
)
request_dict
=
dict
(
codename
=
"PA165"
)
db_courses_number
=
len
(
Course
.
query
.
all
())
db_courses_number
=
len
(
Course
.
query
.
all
())
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
'/courses'
,
json
=
request_dict
,
method
=
'post'
)
response
=
rest_tools
.
make_request
(
client
,
'/courses'
,
data
=
request_json
,
assert_response
(
response
,
400
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'post'
)
assert
response
.
status_code
==
400
assert
response
.
mimetype
==
'application/json'
assert
len
(
Course
.
query
.
all
())
==
db_courses_number
assert
len
(
Course
.
query
.
all
())
==
db_courses_number
...
@@ -76,24 +62,18 @@ def test_create_invalid_value(client):
...
@@ -76,24 +62,18 @@ def test_create_invalid_value(client):
request_dict
=
dict
(
request_dict
=
dict
(
name
=
456
,
name
=
456
,
codename
=
"PA165"
,
codename
=
"PA165"
,
)
)
db_courses_number
=
len
(
Course
.
query
.
all
())
db_courses_number
=
len
(
Course
.
query
.
all
())
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
'/courses'
,
json
=
request_dict
,
method
=
'post'
)
response
=
rest_tools
.
make_request
(
client
,
'/courses'
,
data
=
request_json
,
assert_response
(
response
,
400
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'post'
)
assert
response
.
status_code
==
400
assert
response
.
mimetype
==
'application/json'
assert
len
(
Course
.
query
.
all
())
==
db_courses_number
assert
len
(
Course
.
query
.
all
())
==
db_courses_number
def
test_read
(
client
):
def
test_read
(
client
):
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
c
.
id
}
"
,
method
=
'get'
)
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
c
.
id
}
"
)
assert
response
.
status_code
==
200
assert_response
(
response
,
200
)
assert
response
.
mimetype
==
'application/json'
course
=
rest_tools
.
extract_data
(
response
)
course
=
rest_tools
.
extract_data
(
response
)
rest_tools
.
assert_course
(
c
,
course
)
rest_tools
.
assert_course
(
c
,
course
)
...
@@ -104,13 +84,11 @@ def test_update(client):
...
@@ -104,13 +84,11 @@ def test_update(client):
request_dict
=
dict
(
request_dict
=
dict
(
name
=
"new_cpp"
,
name
=
"new_cpp"
,
codename
=
"testcourse1_new"
,
codename
=
"testcourse1_new"
,
)
)
request_json
=
json
.
dumps
(
request_dict
)
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
f
'/courses/
{
c
.
id
}
'
,
data
=
request_json
,
response
=
rest_tools
.
make_request
(
client
,
f
'/courses/
{
c
.
id
}
'
,
data
=
request_json
,
method
=
'put'
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'put'
)
assert
response
.
status_code
==
204
assert_response
(
response
,
204
)
assert
response
.
mimetype
==
'application/json'
assert
not
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
assert
not
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
course_from_db
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1-new"
).
first
()
course_from_db
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1-new"
).
first
()
...
@@ -119,22 +97,16 @@ def test_update(client):
...
@@ -119,22 +97,16 @@ def test_update(client):
def
test_delete
(
client
):
def
test_delete
(
client
):
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
response
=
rest_tools
.
make_request
(
client
,
f
'/courses/
{
c
.
id
}
'
,
response
=
rest_tools
.
make_request
(
client
,
f
'/courses/
{
c
.
id
}
'
,
method
=
'delete'
)
headers
=
{
"content-type"
:
"application/json"
},
assert_response
(
response
,
204
)
method
=
'delete'
)
assert
response
.
status_code
==
204
assert
response
.
mimetype
==
'application/json'
assert
not
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
assert
not
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
def
test_notes_token_read
(
client
):
def
test_notes_token_read
(
client
):
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
response
=
rest_tools
.
make_request
(
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
c
.
id
}
/notes_access_token"
,
method
=
'get'
)
client
,
f
"/courses/
{
c
.
id
}
/notes_access_token"
)
assert
response
.
status_code
==
200
assert_response
(
response
,
200
)
assert
response
.
mimetype
==
'application/json'
data
=
rest_tools
.
extract_data
(
response
)
data
=
rest_tools
.
extract_data
(
response
)
assert
data
==
"testcourse2_token"
assert
data
==
"testcourse2_token"
...
@@ -143,10 +115,8 @@ def test_notes_token_read(client):
...
@@ -143,10 +115,8 @@ def test_notes_token_read(client):
def
test_notes_token_create
(
client
):
def
test_notes_token_create
(
client
):
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
c
.
id
}
/notes_access_token"
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
c
.
id
}
/notes_access_token"
,
data
=
json
.
dumps
({
"token"
:
"new_token"
}),
json
=
{
"token"
:
"new_token"
},
method
=
'put'
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'put'
)
assert_response
(
response
,
204
)
assert
response
.
status_code
==
204
assert
response
.
mimetype
==
'application/json'
updated
=
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
updated
=
Course
.
query
.
filter_by
(
codename
=
"testcourse2"
).
first
()
assert
updated
.
notes_access_token
==
"new_token"
assert
updated
.
notes_access_token
==
"new_token"
...
@@ -155,10 +125,8 @@ def test_notes_token_create(client):
...
@@ -155,10 +125,8 @@ def test_notes_token_create(client):
def
test_notes_token_update
(
client
):
def
test_notes_token_update
(
client
):
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
c
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
c
.
id
}
/notes_access_token"
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
c
.
id
}
/notes_access_token"
,
data
=
json
.
dumps
({
"token"
:
"new_token"
}),
json
=
{
"token"
:
"new_token"
},
method
=
'put'
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'put'
)
assert_response
(
response
,
204
)
assert
response
.
status_code
==
204
assert
response
.
mimetype
==
'application/json'
updated
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
updated
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
assert
updated
.
notes_access_token
==
"new_token"
assert
updated
.
notes_access_token
==
"new_token"
...
@@ -173,26 +141,14 @@ def test_copy_from_course(rest_service, client):
...
@@ -173,26 +141,14 @@ def test_copy_from_course(rest_service, client):
"roles"
:
"with_clients"
,
"roles"
:
"with_clients"
,
"groups"
:
"with_users"
,
"groups"
:
"with_users"
,
"projects"
:
"bare"
,
"projects"
:
"bare"
,
}
}
}
request_json
=
json
.
dumps
(
request_dict
)
}
response
=
rest_tools
.
make_request
(
client
,
f
'/courses/
{
target
.
codename
}
/import'
,
response
=
rest_tools
.
make_request
(
client
,
f
'/courses/
{
target
.
codename
}
/import'
,
data
=
request_json
,
json
=
request_dict
,
method
=
'put'
)
headers
=
{
"content-type"
:
"application/json"
},
assert_response
(
response
,
200
)
method
=
'put'
)
assert
response
.
status_code
==
200
assert
response
.
mimetype
==
"application/json"
updated_course
:
Course
=
rest_service
.
find
.
course
(
target
.
codename
)
updated_course
:
Course
=
rest_service
.
find
.
course
(
target
.
codename
)
print
(
f
"CPP projects:
{
source
.
projects
}
\n
Target projects:
{
updated_course
.
projects
}
\n\n
"
)
print
(
f
"CPP roles:
{
source
.
roles
}
\n
Target roles:
{
updated_course
.
roles
}
\n\n
"
)
print
(
f
"CPP groups:
{
source
.
groups
}
\n
Target groups:
{
updated_course
.
groups
}
\n\n
"
)
assert_collections
(
source
,
updated_course
,
'projects'
)
assert_collections
(
source
,
updated_course
,
'projects'
)
assert_collections
(
source
,
updated_course
,
'roles'
)
assert_collections
(
source
,
updated_course
,
'roles'
)
assert_collections
(
source
,
updated_course
,
'groups'
)
assert_collections
(
source
,
updated_course
,
'groups'
)
...
...
tests/rest/test_group.py
View file @
93b14274
import
json
import
json
from
portal.database.models
import
Course
,
Group
,
Role
,
User
from
portal.database.models
import
Course
,
Group
,
Role
,
User
from
tests.rest.rest_tools
import
assert_response
from
.
import
rest_tools
from
.
import
rest_tools
def
test_list
(
client
):
def
test_list
(
client
):
cpp
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
cpp
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
response
=
rest_tools
.
make_request
(
response
=
rest_tools
.
make_request
(
client
,
f
'/courses/
{
cpp
.
codename
}
/groups'
,
method
=
'get'
)
client
,
f
'/courses/
{
cpp
.
codename
}
/groups'
)
assert
response
.
status_code
==
200
assert_response
(
response
,
200
)
assert
response
.
mimetype
==
'application/json'
groups
=
rest_tools
.
extract_data
(
response
)
groups
=
rest_tools
.
extract_data
(
response
)
assert
len
(
groups
)
==
len
(
cpp
.
groups
)
assert
len
(
groups
)
==
len
(
cpp
.
groups
)
...
@@ -25,11 +25,10 @@ def test_create(client):
...
@@ -25,11 +25,10 @@ def test_create(client):
name
=
"newgrp"
,
name
=
"newgrp"
,
codename
=
'newgrp'
codename
=
'newgrp'
)
)
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups"
,
json
=
request_dict
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups"
,
data
=
request_json
,
method
=
'post'
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'post'
)
assert_response
(
response
,
201
)
assert
response
.
status_code
==
201
assert
response
.
mimetype
==
"application/json"
resp_new_group
=
rest_tools
.
extract_data
(
response
)
resp_new_group
=
rest_tools
.
extract_data
(
response
)
cpp_updated
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
cpp_updated
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
...
@@ -43,7 +42,7 @@ def test_read(client):
...
@@ -43,7 +42,7 @@ def test_read(client):
cpp
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
cpp
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
g
=
cpp
.
groups
[
0
]
g
=
cpp
.
groups
[
0
]
response
=
rest_tools
.
make_request
(
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
name
}
"
,
method
=
'get'
)
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
name
}
"
)
assert
response
.
status_code
==
200
assert
response
.
status_code
==
200
assert
response
.
mimetype
==
'application/json'
assert
response
.
mimetype
==
'application/json'
...
@@ -59,8 +58,7 @@ def test_update(client):
...
@@ -59,8 +58,7 @@ def test_update(client):
)
)
request_json
=
json
.
dumps
(
request_dict
)
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
name
}
"
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
name
}
"
,
data
=
request_json
,
data
=
request_json
,
method
=
'put'
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'put'
)
assert
response
.
status_code
==
204
assert
response
.
status_code
==
204
assert
response
.
mimetype
==
'application/json'
assert
response
.
mimetype
==
'application/json'
...
@@ -87,8 +85,7 @@ def test_delete(client):
...
@@ -87,8 +85,7 @@ def test_delete(client):
def
test_list_users
(
client
):
def
test_list_users
(
client
):
cpp
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
cpp
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
g
=
cpp
.
groups
[
0
]
g
=
cpp
.
groups
[
0
]
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
id
}
/users"
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
id
}
/users"
)
method
=
'get'
)
assert
response
.
status_code
==
200
assert
response
.
status_code
==
200
assert
response
.
mimetype
==
'application/json'
assert
response
.
mimetype
==
'application/json'
...
@@ -105,8 +102,7 @@ def test_list_users_filter(client):
...
@@ -105,8 +102,7 @@ def test_list_users_filter(client):
name
=
"student"
).
first
()
name
=
"student"
).
first
()
students
=
[
user
for
user
in
g
.
users
if
role
in
user
.
roles
]
students
=
[
user
for
user
in
g
.
users
if
role
in
user
.
roles
]
response
=
rest_tools
.
make_request
(
client
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
id
}
/users?role=
{
role
.
name
}
"
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
id
}
/users?role=
{
role
.
name
}
"
)
method
=
'get'
)
assert
response
.
status_code
==
200
assert
response
.
status_code
==
200
assert
response
.
mimetype
==
'application/json'
assert
response
.
mimetype
==
'application/json'
...
@@ -130,8 +126,7 @@ def test_update_users_add(client):
...
@@ -130,8 +126,7 @@ def test_update_users_add(client):
)
)
request_json
=
json
.
dumps
(
request_dict
)
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
tc2
.
codename
}
/groups/
{
g
.
name
}
/users"
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
tc2
.
codename
}
/groups/
{
g
.
name
}
/users"
,
data
=
request_json
,
data
=
request_json
,
method
=
'put'
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'put'
)
assert
response
.
status_code
==
204
assert
response
.
status_code
==
204
assert
response
.
mimetype
==
'application/json'
assert
response
.
mimetype
==
'application/json'
...
@@ -154,8 +149,7 @@ def test_update_users_add_duplicate(client):
...
@@ -154,8 +149,7 @@ def test_update_users_add_duplicate(client):
)
)
request_json
=
json
.
dumps
(
request_dict
)
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
name
}
/users"
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
name
}
/users"
,
data
=
request_json
,
data
=
request_json
,
method
=
'put'
)
headers
=
{
"content-type"
:
"application/json"
},
method
=
'put'
)
assert
response
.
status_code
==
204
assert
response
.
status_code
==
204
assert
response
.
mimetype
==
'application/json'
assert
response
.
mimetype
==
'application/json'
...
@@ -179,7 +173,7 @@ def test_update_users_remove(client):
...
@@ -179,7 +173,7 @@ def test_update_users_remove(client):
request_json
=
json
.
dumps
(
request_dict
)
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
name
}
/users"
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
cpp
.
codename
}
/groups/
{
g
.
name
}
/users"
,
data
=
request_json
,
data
=
request_json
,
headers
=
{
"content-type"
:
"application/json"
},
method
=
'put'
)
method
=
'put'
)
assert
response
.
status_code
==
204
assert
response
.
status_code
==
204
assert
response
.
mimetype
==
'application/json'
assert
response
.
mimetype
==
'application/json'
...
@@ -299,8 +293,7 @@ def test_import(client):
...
@@ -299,8 +293,7 @@ def test_import(client):
}
}
request_json
=
json
.
dumps
(
request_dict
)
request_json
=
json
.
dumps
(
request_dict
)
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
c
.
codename
}
/groups/import"
,
response
=
rest_tools
.
make_request
(
client
,
f
"/courses/
{
c
.
codename
}
/groups/import"
,
data
=
request_json
,
data
=
request_json
,
method
=
'put'
)