Skip to content

Commit fc10931

Browse files
#1523 - added test cases for following APIs (#1547) (#1553)
- Act section - EAO Teams - Positions - Project types - Regions - Responsibility - Work type #1536 - Fixed issue with reports download API due to date format Co-authored-by: Salabh A N <salabh.n@aot-technologies.com>
1 parent 3ce2fb3 commit fc10931

14 files changed

+176
-119
lines changed

epictrack-api/src/api/resources/eao_team.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
from flask import jsonify
1818
from flask_restx import Namespace, Resource, cors
19-
from api.schemas.eao_team import EAOTeamSchema
2019

20+
from api.schemas.eao_team import EAOTeamSchema
2121
from api.services.eao_team_service import EAOTeamService
2222
from api.utils import auth, constants, profiletime
2323
from api.utils.caching import AppCache

epictrack-api/src/api/resources/phase.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515

1616
from http import HTTPStatus
1717

18-
from flask_restx import Namespace, Resource, cors
1918
from flask import jsonify
19+
from flask_restx import Namespace, Resource, cors
2020

21+
from api.schemas import response as res
2122
from api.services.phaseservice import PhaseService
2223
from api.utils import auth, constants, profiletime
2324
from api.utils.caching import AppCache
2425
from api.utils.util import cors_preflight
25-
from api.schemas import response as res
26+
2627

2728
API = Namespace('phases', description='Phases')
2829

epictrack-api/src/api/resources/region.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616

1717
from flask import jsonify, request
1818
from flask_restx import Namespace, Resource, cors
19-
from api.schemas.region import RegionSchema
2019

20+
from api.schemas import request as req
21+
from api.schemas.region import RegionSchema
2122
from api.services.region import RegionService
2223
from api.utils import auth, constants, profiletime
2324
from api.utils.caching import AppCache
2425
from api.utils.util import cors_preflight
2526

26-
from api.schemas import request as req
2727

2828
API = Namespace("regions", description="Regions")
2929

3030

3131
@cors_preflight("GET")
3232
@API.route("", methods=["GET", "OPTIONS"])
33-
class SubTypes(Resource):
33+
class Regions(Resource):
3434
"""Endpoint resource to return regions based on region type."""
3535

3636
@staticmethod
@@ -39,7 +39,7 @@ class SubTypes(Resource):
3939
@profiletime
4040
@AppCache.cache.cached(timeout=constants.CACHE_DAY_TIMEOUT, query_string=True)
4141
def get():
42-
"""Return all sub_types based on type."""
42+
"""Return all regions based on region type."""
4343
req.RegionTypePathParameterSchema().load(request.args)
4444
region_type = request.args.get("type", None)
4545
regions = RegionService.find_regions_by_type(region_type)

epictrack-api/src/api/resources/reports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class FileReport(Resource):
7777
@profiletime
7878
def post(report_type):
7979
"""Generate report from given date."""
80-
report_date = datetime.strptime(API.payload['report_date'], '%m-%d-%Y')
80+
report_date = datetime.strptime(API.payload['report_date'], '%Y-%m-%d')
8181
filters = API.payload.get('filters', None)
8282
report, file_name = ReportService.generate_report(report_type, report_date, 'file', filters=filters)
8383
if report:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright © 2019 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the 'License');
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an 'AS IS' BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Test suite for Act Section."""
16+
from http import HTTPStatus
17+
from urllib.parse import urljoin
18+
19+
20+
API_BASE_URL = '/api/v1/'
21+
22+
23+
def test_get_act_section_by_ea_act(client):
24+
"""Test get act section by EA Act."""
25+
url = urljoin(API_BASE_URL, 'act-sections?ea_act_id=3')
26+
result = client.get(url)
27+
assert result.status_code == HTTPStatus.OK

epictrack-api/tests/unit/apis/test_milestones.py renamed to epictrack-api/tests/unit/apis/test_eao_teams.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""Test suite for phases."""
1514

15+
"""Test suite for EAO Teams."""
1616
from http import HTTPStatus
1717
from urllib.parse import urljoin
1818

1919

2020
API_BASE_URL = '/api/v1/'
2121

2222

23-
def test_get_phases(client):
24-
"""Test get phases."""
25-
url = urljoin(API_BASE_URL, 'milestones/phases/11')
23+
def test_get_eao_teams(client):
24+
"""Test get EAO Teams."""
25+
url = urljoin(API_BASE_URL, 'eao-teams')
2626
result = client.get(url)
2727
assert result.status_code == HTTPStatus.OK

epictrack-api/tests/unit/apis/test_phases.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ def test_get_phases(client):
2626
url = f'{url}/ea_acts/3/work_types/6'
2727
result = client.get(url)
2828
assert result.status_code == HTTPStatus.OK
29-
assert 'milestones' in result.json[0]
29+
30+
31+
def test_get_all_phases(client):
32+
"""Test GET all phases."""
33+
url = urljoin(API_BASE_URL, 'phases/')
34+
result = client.get(url)
35+
assert result.status_code == HTTPStatus.OK
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright © 2019 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the 'License');
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an 'AS IS' BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Test suite for Positions."""
16+
from http import HTTPStatus
17+
from urllib.parse import urljoin
18+
19+
20+
API_BASE_URL = '/api/v1/'
21+
22+
23+
def test_get_positions(client):
24+
"""Test get positions."""
25+
url = urljoin(API_BASE_URL, 'positions')
26+
result = client.get(url)
27+
assert result.status_code == HTTPStatus.OK
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright © 2019 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the 'License');
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an 'AS IS' BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Test suite for project types."""
16+
from http import HTTPStatus
17+
from urllib.parse import urljoin
18+
19+
20+
API_BASE_URL = '/api/v1/'
21+
22+
23+
def test_get_project_types(client):
24+
"""Test get project types."""
25+
url = urljoin(API_BASE_URL, 'project-types')
26+
result = client.get(url)
27+
assert result.status_code == HTTPStatus.OK

epictrack-api/tests/unit/apis/test_projects.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ def test_create_project(client):
2525
payload = {
2626
"name": "New Project",
2727
"description": "Testing the create project endpoint",
28-
"latitude": "54.2681",
29-
"longitude": "-130.3828",
28+
"location": "Victoria, BC",
29+
"address": "Helsinki Airport, Artesaaninkuja, Lemminkäinen, Tuusula, Helsinki sub-region, \
30+
Uusimaa, Southern Finland, Mainland Finland, 04360, Finland",
3031
"type_id": 1,
3132
"sub_type_id": 1,
3233
"proponent_id": 1,
3334
"region_id_env": 1,
3435
"region_id_flnro": 1,
36+
"latitude": "54.2681",
37+
"longitude": "-130.3828",
38+
"abbreviation": "NP",
3539
}
3640
url = urljoin(API_BASE_URL, "projects")
3741
response = client.post(url, json=payload)
@@ -58,6 +62,9 @@ def test_update_project(client):
5862
"proponent_id": 1,
5963
"region_id_env": 1,
6064
"region_id_flnro": 1,
65+
"type_id": 1,
66+
"sub_type_id": 1,
67+
"abbreviation": "NPC",
6168
}
6269
# Create a project
6370
url = urljoin(API_BASE_URL, "projects")
@@ -84,6 +91,9 @@ def test_delete_project(client):
8491
"proponent_id": 1,
8592
"region_id_env": 1,
8693
"region_id_flnro": 1,
94+
"type_id": 1,
95+
"sub_type_id": 1,
96+
"abbreviation": "NPD",
8797
}
8898
# Create a project
8999
projects_url = urljoin(API_BASE_URL, "projects")
@@ -100,7 +110,7 @@ def test_delete_project(client):
100110
def test_project_detail(client):
101111
"""Test project details."""
102112
payload = {
103-
"name": "New Project for details",
113+
"name": "New Project for details testing",
104114
"description": "Testing the create project endpoint",
105115
"latitude": "54.2681",
106116
"longitude": "-130.3828",
@@ -109,6 +119,7 @@ def test_project_detail(client):
109119
"proponent_id": 1,
110120
"region_id_env": 1,
111121
"region_id_flnro": 1,
122+
"abbreviation": "NPDT",
112123
}
113124
# Create a project
114125
projects_url = urljoin(API_BASE_URL, "projects")

epictrack-api/tests/unit/apis/test_outcome.py renamed to epictrack-api/tests/unit/apis/test_regions.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,23 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""Test suite for outcome."""
1514

15+
"""Test suite for Region."""
1616
from http import HTTPStatus
1717
from urllib.parse import urljoin
1818

1919

2020
API_BASE_URL = '/api/v1/'
2121

2222

23-
def test_get_staff_by_position(client):
24-
"""Test get staff by position."""
25-
url = urljoin(API_BASE_URL, 'outcomes/milestones/3')
23+
def test_get_regions_by_type(client):
24+
"""Test get regions by type."""
25+
# type = ENV
26+
url = urljoin(API_BASE_URL, 'regions?type=ENV')
2627
result = client.get(url)
2728
assert result.status_code == HTTPStatus.OK
2829

29-
30-
def test_get_all_active_staff(client):
31-
"""Test get all active staff."""
32-
url = urljoin(API_BASE_URL, 'staffs')
30+
# type = FLNR
31+
url = urljoin(API_BASE_URL, 'regions?type=FLNR')
3332
result = client.get(url)
3433
assert result.status_code == HTTPStatus.OK
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright © 2019 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the 'License');
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an 'AS IS' BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Test suite for Responsibilities."""
15+
16+
from http import HTTPStatus
17+
from urllib.parse import urljoin
18+
19+
20+
API_BASE_URL = "/api/v1/"
21+
22+
23+
def test_get_all_responsibilities(client):
24+
"""Test get all responsibilities."""
25+
url = urljoin(API_BASE_URL, "responsibilities")
26+
result = client.get(url)
27+
assert result.status_code == HTTPStatus.OK

0 commit comments

Comments
 (0)