• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DemocracyClub / WhoCanIVoteFor / 78615e59-2602-4373-b4ce-ad20cc5b761e

07 Apr 2025 01:45PM UTC coverage: 58.389% (+0.1%) from 58.293%
78615e59-2602-4373-b4ce-ad20cc5b761e

Pull #2232

circleci

awdem
update PostcodeiCalView to new error handling
Pull Request #2232: handle invalid postcode errors and api 500s differently

31 of 31 new or added lines in 4 files covered. (100.0%)

89 existing lines in 6 files now uncovered.

2812 of 4816 relevant lines covered (58.39%)

0.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.88
/wcivf/apps/elections/devs_dc_client.py
1
from json import JSONDecodeError
1✔
2
from urllib.parse import urljoin
1✔
3

4
import requests
1✔
5
from django.conf import settings
1✔
6

7

8
class DevsDCAPIException(Exception):
1✔
9
    def __init__(self, response: requests.Response):
1✔
10
        try:
1✔
11
            self.message = {"error": response.json().get("message", "")}
1✔
12
        except (JSONDecodeError, AttributeError):
1✔
13
            self.message = ""
1✔
14
        self.status = response.status_code
1✔
15
        self.response = response
1✔
16

17

18
class DevsDCClient:
1✔
19
    def __init__(self, api_base=None, api_key=None):
1✔
20
        if not api_base:
1✔
21
            api_base = settings.DEVS_DC_BASE
1✔
22
        self.API_BASE = api_base
1✔
23
        if not api_key:
1✔
24
            api_key = settings.DEVS_DC_API_KEY
1✔
25
        self.API_KEY = api_key
1✔
26

27
    def make_request(self, postcode, uprn=None, **extra_params):
1✔
28
        path = f"/api/v1/postcode/{postcode}/"
1✔
29
        if uprn:
1✔
30
            path = f"/api/v1/address/{uprn}/"
1✔
31
        url = urljoin(self.API_BASE, path)
1✔
32
        default_params = {"auth_token": self.API_KEY, "include_current": 1}
1✔
33
        if extra_params:
1✔
UNCOV
34
            default_params.update(**extra_params)
×
35
        resp = requests.get(url, params=default_params)
1✔
36
        if resp.status_code >= 400:
1✔
37
            raise DevsDCAPIException(response=resp)
1✔
38
        return resp.json()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc