-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from DemocracyClub/ruff
Ruff
- Loading branch information
Showing
76 changed files
with
987 additions
and
1,062 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
electionleaflets/apps/analysis/migrations/0004_auto_20210424_1221.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,61 @@ | ||
import pytest | ||
from electionleaflets.apps.api.views import LeafletFilter | ||
from leaflets.models import Leaflet | ||
from django.utils import timezone | ||
from leaflets.models import Leaflet | ||
from uk_political_parties.models import Party | ||
|
||
from electionleaflets.apps.api.views import LeafletFilter | ||
|
||
|
||
@pytest.fixture | ||
def all_leaflets(): | ||
return [ | ||
Leaflet.objects.create( | ||
title=f"Test Leaflet {i}", | ||
status="live", | ||
date_uploaded=timezone.now(), | ||
modified=timezone.now() | ||
) | ||
for i in range(10) | ||
] | ||
|
||
return [ | ||
Leaflet.objects.create( | ||
title=f"Test Leaflet {i}", | ||
status="live", | ||
date_uploaded=timezone.now(), | ||
modified=timezone.now(), | ||
) | ||
for i in range(10) | ||
] | ||
|
||
|
||
@pytest.fixture | ||
def party(): | ||
return Party.objects.create( | ||
party_name="Test Party", | ||
party_id="party:1" | ||
) | ||
|
||
return Party.objects.create(party_name="Test Party", party_id="party:1") | ||
|
||
|
||
@pytest.fixture | ||
def leaflet_with_party(all_leaflets, party): | ||
leaflet = all_leaflets[0] | ||
leaflet.publisher_party = party | ||
leaflet.save() | ||
return leaflet | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestLeafletFilter: | ||
def test_ballot_filter(self, all_leaflets): | ||
leaflet = all_leaflets[0] | ||
leaflet.ballots = [{"ballot_paper_id": "test"}] | ||
leaflet.save() | ||
filter = LeafletFilter(data={"ballot": "test"}, queryset=Leaflet.objects.all()) | ||
assert filter.ballot_filter(Leaflet.objects.all(), "ballot", "test").count() == 1 | ||
|
||
filter = LeafletFilter( | ||
data={"ballot": "test"}, queryset=Leaflet.objects.all() | ||
) | ||
assert ( | ||
filter.ballot_filter( | ||
Leaflet.objects.all(), "ballot", "test" | ||
).count() | ||
== 1 | ||
) | ||
|
||
def test_party_filter(self, leaflet_with_party): | ||
party = Party.objects.get(party_id="party:1") | ||
filter = LeafletFilter(data={"party": party}, queryset=Leaflet.objects.all()) | ||
assert filter.party_filter(Leaflet.objects.all(), party, party.party_id).count() == 1 | ||
|
||
filter = LeafletFilter( | ||
data={"party": party}, queryset=Leaflet.objects.all() | ||
) | ||
assert ( | ||
filter.party_filter( | ||
Leaflet.objects.all(), party, party.party_id | ||
).count() | ||
== 1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.