Skip to content

Commit

Permalink
added tests for work status
Browse files Browse the repository at this point in the history
  • Loading branch information
saravanpa-aot committed Jan 15, 2024
1 parent cb6f00c commit 10d3efc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
68 changes: 68 additions & 0 deletions epictrack-api/tests/unit/apis/test_work_status.py
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
1 change: 0 additions & 1 deletion epictrack-api/tests/utilities/factory_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class TestStatus(Enum):
status1 = {
"description": fake.sentence(),
"posted_date": fake.date_time_this_decade(tzinfo=None).isoformat(),
"posted_by": fake.name(),
"is_approved": False,
"approved_by": None,
"approved_date": None,
Expand Down

0 comments on commit 10d3efc

Please sign in to comment.