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

DemocracyClub / yournextrepresentative / 06fffc96-31fa-407b-8443-1731e4db6cf1

04 Apr 2024 08:24AM CUT coverage: 68.368% (+1.1%) from 67.282%
06fffc96-31fa-407b-8443-1731e4db6cf1

Pull #2269

circleci

symroe
Clean up some testsing code

Misc fixes to the test code
Pull Request #2269: Redesign SOPN models

1749 of 2922 branches covered (59.86%)

Branch coverage included in aggregate %.

415 of 488 new or added lines in 25 files covered. (85.04%)

18 existing lines in 4 files now uncovered.

7093 of 10011 relevant lines covered (70.85%)

0.71 hits per line

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

0.0
/ynr/apps/sopn_parsing/management/commands/sopn_parsing_parse_tables.py
1
from bulk_adding.models import RawPeople
×
2
from sopn_parsing.helpers.command_helpers import BaseSOPNParsingCommand
×
3
from sopn_parsing.helpers.parse_tables import parse_raw_data_for_ballot
×
4

5

6
class Command(BaseSOPNParsingCommand):
×
7
    help = """
×
8
    Convert the raw extracted tables on the CamelotParsedSOPN model to a parsed
9
    RawPeople model, and set the status as parsed.
10

11
    """
12

13
    def build_filter_kwargs(self, options):
×
14
        """
15
        Build kwargs used to filter the BallotQuerySet that is parsed
16
        - Always skip any ballots where we do not have a CamelotParsedSOPN to try to
17
        extract candidates from
18
        - When test flag is used, dont make any changes
19
        - When parsing a single ballot, dont make any changes
20
        - When reparsing, only use ballots where we have previously created a
21
          RawPeople object from a CamelotParsedSOPN
22
        - Otherwise filter by unparsed CamelotParsedSOPN objects
23
        """
24
        # Always skip any ballots where we do not have a CamelotParsedSOPN to try to
25
        # extract candidates from
NEW
26
        filter_kwargs = {"sopn__camelotparsedsopn__isnull": False}
×
27
        if options.get("testing"):
×
28
            return filter_kwargs
×
29

30
        if options.get("ballot"):
×
31
            return filter_kwargs
×
32

33
        if options.get("reparse"):
×
34
            filter_kwargs[
×
35
                "rawpeople__source_type"
36
            ] = RawPeople.SOURCE_PARSED_PDF
37
            return filter_kwargs
×
38

NEW
39
        filter_kwargs["sopn__camelotparsedsopn__parsed_data"] = None
×
40

41
        # Where the status is unparsed
NEW
42
        filter_kwargs["sopn__camelotparsedsopn__status"] = "unparsed"
×
43

44
        return filter_kwargs
×
45

46
    def handle(self, *args, **options):
×
47
        # filters that we never change with args. These two would raise
48
        # ValueErrors in the parse_raw_data_for_ballot function
49
        base_qs = self.get_queryset(options)
×
50

51
        filter_kwargs = self.build_filter_kwargs(options)
×
52

53
        qs = base_qs.filter(**filter_kwargs)
×
54
        qs = qs.filter(
×
55
            candidates_locked=False,  # Never parse a locked ballot
56
            suggestedpostlock=None,  # Never parse a ballot with lock suggestions
57
        )
58

59
        if not qs.exists():
×
60
            msg = ["No ballots to parse found."]
×
61

62
            if options.get("ballot"):
×
63
                msg.append(
×
64
                    "This ballot might be locked or have lock suggestions"
65
                )
66

67
            self.stderr.write("\n".join(msg))
×
68

69
        for ballot in qs:
×
70
            parse_raw_data_for_ballot(ballot)
×
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