-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb6f00c
commit 10d3efc
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright © 2019 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Test suite for projects.""" | ||
|
||
from http import HTTPStatus | ||
from urllib.parse import urljoin | ||
|
||
from faker import Faker | ||
from flask import g | ||
|
||
from tests.utilities.factory_scenarios import (TestJwtClaims, TestStatus) | ||
from tests.utilities.factory_utils import factory_work_model, factory_auth_header | ||
|
||
API_BASE_URL = "/api/v1/" | ||
|
||
fake = Faker() | ||
|
||
|
||
def test_get_empty_work(client): | ||
"""Test get empty project.""" | ||
work = factory_work_model() | ||
url = urljoin(API_BASE_URL, f'work/{work.id}/statuses') | ||
result = client.get(url) | ||
assert result.status_code == HTTPStatus.OK | ||
|
||
|
||
def test_create_and_fetch_work_status(client, jwt): | ||
"""Test create and fetch WorkStatus.""" | ||
work = factory_work_model() | ||
url_create_status = urljoin(API_BASE_URL, f'work/{work.id}/statuses') | ||
status_data = TestStatus.status1.value | ||
|
||
staff_user = TestJwtClaims.staff_admin_role | ||
headers = factory_auth_header(jwt=jwt, claims=staff_user) | ||
g.token_info = staff_user | ||
result_create_status = client.post(url_create_status, headers=headers, json=status_data) | ||
assert result_create_status.status_code == HTTPStatus.CREATED | ||
result_json = result_create_status.json | ||
assert "id" in result_json | ||
assert result_json.get('work_id') == work.id | ||
|
||
# Fetch WorkStatus | ||
url_fetch_status = urljoin(API_BASE_URL, f'work/{work.id}/statuses') | ||
result_fetch_status = client.get(url_fetch_status, headers=headers) | ||
assert result_fetch_status.status_code == HTTPStatus.OK | ||
assert len(result_fetch_status.json) == 1, 'only one status got created' | ||
|
||
retrieved_status_json = result_fetch_status.json[0] | ||
|
||
assert "id" in retrieved_status_json | ||
assert retrieved_status_json["work_id"] == work.id | ||
assert status_data['description'] == retrieved_status_json["description"] | ||
assert staff_user['preferred_username'] == retrieved_status_json["posted_by"] | ||
|
||
assert not retrieved_status_json["is_approved"] | ||
assert retrieved_status_json["approved_by"] is None | ||
assert retrieved_status_json["approved_date"] is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters