Skip to content

Commit

Permalink
new exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rv0lt committed Oct 23, 2023
1 parent 4f4ff91 commit ca97094
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
9 changes: 8 additions & 1 deletion dds_web/api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def patch(self):
# some variable definition
curr_date = dds_web.utils.current_time()
send_email = False
default_unit_days = project.responsible_unit.days_in_expired

# Update the deadline functionality
if new_deadline_in:
Expand All @@ -254,7 +255,13 @@ def patch(self):
message="The deadline atribute passed should be of type Int (i.e a number)."
)

# it shouldnt surpass 90 days
# New deadline shouldnt surpass the default unit days
if new_deadline_in > default_unit_days:
raise DDSArgumentError(
message=f"You requested the deadline to be extended {new_deadline_in}. The number of days has to be lower than the default deadline extension number of {default_unit_days} days"
)

# the new deadline + days left shouldnt surpass 90 days
current_deadline = (project.current_deadline - curr_date).days
if new_deadline_in + current_deadline > 90:
raise DDSArgumentError(
Expand Down
52 changes: 42 additions & 10 deletions tests/api/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
# "date_updated",
]

release_project_small_deadline = {"new_status": "Available", "deadline": 5}
release_project = {"new_status": "Available"}
release_project_small_deadline = {**release_project, "deadline": 5}
release_project_big_deadline = {**release_project, "deadline": 80}

extend_deadline_data_no_confirmed = {
"new_deadline_in": 20,
Expand Down Expand Up @@ -1127,7 +1129,7 @@ def test_extend_deadline_bad_confirmed(module_client, boto3_session):

# create project and release it
project_id, project = create_and_release_project(
client=module_client, proj_data=proj_data, release_data={"new_status": "Available"}
client=module_client, proj_data=proj_data, release_data=release_project
)
assert project.times_expired == 0
time.sleep(1) # tests are too fast
Expand All @@ -1148,7 +1150,7 @@ def test_extend_deadline_no_confirmed(module_client, boto3_session):

# create project and release it
project_id, project = create_and_release_project(
client=module_client, proj_data=proj_data, release_data={"new_status": "Available"}
client=module_client, proj_data=proj_data, release_data=release_project
)
assert project.times_expired == 0
time.sleep(1) # tests are too fast
Expand All @@ -1172,7 +1174,7 @@ def test_extend_deadline_when_busy(module_client, boto3_session):

# create project and release it
project_id, project = create_and_release_project(
client=module_client, proj_data=proj_data, release_data={"new_status": "Available"}
client=module_client, proj_data=proj_data, release_data=release_project
)
assert project.times_expired == 0
time.sleep(1) # tests are too fast
Expand Down Expand Up @@ -1206,7 +1208,7 @@ def test_extend_deadline_no_deadline(module_client, boto3_session):

# create project and release it
project_id, project = create_and_release_project(
client=module_client, proj_data=proj_data, release_data={"new_status": "Available"}
client=module_client, proj_data=proj_data, release_data=release_project
)
assert project.times_expired == 0
time.sleep(1) # tests are too fast
Expand Down Expand Up @@ -1259,15 +1261,15 @@ def test_extend_deadline_project_not_available(module_client, boto3_session):
def test_extend_deadline_too_much_days(module_client, boto3_session):
"""If the new deadline together with the time left already is more than 90 days it should not work"""

# create project and release it
# create project and release it with big dealdine
project_id, project = create_and_release_project(
client=module_client, proj_data=proj_data, release_data=release_project_small_deadline
client=module_client, proj_data=proj_data, release_data=release_project_big_deadline
)
assert project.times_expired == 0
time.sleep(1) # tests are too fast

# try to extend deadline by a lot of days
extend_deadline_data_big_deadline = {**extend_deadline_data, "new_deadline_in": 90}
# try to extend deadline -> 80 + 11 > 90
extend_deadline_data_big_deadline = {**extend_deadline_data, "new_deadline_in": 11}
response = module_client.patch(
tests.DDSEndpoint.PROJECT_STATUS,
headers=tests.UserAuth(tests.USER_CREDENTIALS["unitadmin"]).token(module_client),
Expand All @@ -1285,7 +1287,7 @@ def test_extend_deadline_bad_new_deadline(module_client, boto3_session):

# create project and release it
project_id, project = create_and_release_project(
client=module_client, proj_data=proj_data, release_data=release_project_small_deadline
client=module_client, proj_data=proj_data, release_data=release_project
)
assert project.times_expired == 0
time.sleep(1) # tests are too fast
Expand All @@ -1305,6 +1307,36 @@ def test_extend_deadline_bad_new_deadline(module_client, boto3_session):
)


def test_extend_deadline_more_than_default(module_client, boto3_session):
"""If the new deadline provided is more than the default unit days to release a project it should fail"""

# create project and release it
project_id, project = create_and_release_project(
client=module_client, proj_data=proj_data, release_data=release_project_small_deadline
)
assert project.times_expired == 0
time.sleep(1) # tests are too fast

default_unit_days = project.responsible_unit.days_in_expired

# try to extend deadline with a bigger deadline that it is suppose to have
extend_deadline_data_bad_deadline = {
**extend_deadline_data,
"new_deadline_in": default_unit_days + 1,
}
response = module_client.patch(
tests.DDSEndpoint.PROJECT_STATUS,
headers=tests.UserAuth(tests.USER_CREDENTIALS["unitadmin"]).token(module_client),
query_string={"project": project_id},
json=extend_deadline_data_bad_deadline,
)
assert response.status_code == http.HTTPStatus.BAD_REQUEST
assert (
"The number of days has to be lower than the default deadline extension number"
in response.json["message"]
)


def test_extend_deadline_maxium_number_available_exceded(module_client, boto3_session):
"""If the deadline has been extended more than 2 times it should not work"""

Expand Down

0 comments on commit ca97094

Please sign in to comment.