Skip to content

Commit

Permalink
Improve coverage in tests
Browse files Browse the repository at this point in the history
* Remove unused checking function.
* Add a "pragma: no cover" comment to a testing helper
* Reorganize id finding constuction that created some unnecessary
  uncovered code branches
* Convert couple `elif`s to `else`s with an assert
  • Loading branch information
suutari-ai committed Feb 12, 2018
1 parent a0431f1 commit 771ef01
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
3 changes: 2 additions & 1 deletion parkings/tests/api/enforcement/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
def get_url(kind, operator):
if kind == 'list':
return list_url
elif kind == 'detail':
else:
assert kind == 'detail'
return reverse('enforcement:v1:operator-detail',
kwargs={'pk': operator.pk})

Expand Down
3 changes: 2 additions & 1 deletion parkings/tests/api/enforcement/test_valid_parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def get_url(kind, parking):
return list_url
elif kind == 'list_by_reg_num':
return list_url_for(parking.registration_number)
elif kind == 'detail':
else:
assert kind == 'detail'
return reverse('enforcement:v1:valid_parking-detail',
kwargs={'pk': parking.pk})

Expand Down
7 changes: 0 additions & 7 deletions parkings/tests/api/operator/test_parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ def updated_parking_data():
}


def check_parking_data_keys(parking_data):
assert set(parking_data.keys()) == {
'id', 'created_at', 'modified_at', 'location', 'registration_number', 'time_start', 'time_end', 'zone',
'status',
}


def check_parking_data_matches_parking_object(parking_data, parking_obj):
"""
Check that a parking data dict and an actual Parking object match.
Expand Down
11 changes: 7 additions & 4 deletions parkings/tests/api/public/test_parking_area_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ def test_get_list_check_data(api_client, parking_factory, parking_area_factory,
results = get(api_client, list_url)['results']
assert len(results) == 4

stats_data_1 = next(result for result in results if result['id'] == str(parking_area_1.id))
stats_data_2 = next(result for result in results if result['id'] == str(parking_area_2.id))
stats_data_3 = next(result for result in results if result['id'] == str(parking_area_3.id))
stats_data_4 = next(result for result in results if result['id'] == str(parking_area_4.id))
def find_by_obj_id(obj, iterable):
return [x for x in iterable if x['id'] == str(obj.id)][0]

stats_data_1 = find_by_obj_id(parking_area_1, results)
stats_data_2 = find_by_obj_id(parking_area_2, results)
stats_data_3 = find_by_obj_id(parking_area_3, results)
stats_data_4 = find_by_obj_id(parking_area_4, results)

assert stats_data_1.keys() == {'id', 'current_parking_count'}
assert stats_data_1['current_parking_count'] == 4
Expand Down
2 changes: 1 addition & 1 deletion parkings/tests/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def check_required_fields(api_client, url, expected_required_fields, detail_endp

required_fields = set()
for (field, errors) in response_data.items():
if 'This field is required.' in repr(errors):
if 'This field is required.' in repr(errors): # pragma: no cover
required_fields.add(field)

assert required_fields == expected_required_fields, '%s != %s' % (required_fields, expected_required_fields)
Expand Down

0 comments on commit 771ef01

Please sign in to comment.