Skip to content

Commit

Permalink
test: Fix tests (#975)
Browse files Browse the repository at this point in the history
* fix: typo

* fix: Set English language before checking for it.

* chore: noqa false flags from flake8

* chore: noqa false flags from flake8

* chore: noqa false flags from flake8

* chore: noqa false flags from flake8
  • Loading branch information
marksweb authored Apr 21, 2024
1 parent bd74d02 commit 9f3b7a7
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def __str__(self):
return self.subject

def get_rsvp_link(self, code):
return f"http://djangogirls.org/{self.form.event.page_url}/rsvp/{code}"
return f"http://djangogirls.org/{self.form.event.page_url}/rsvp/{code}" # noqa: E231

def add_rsvp_links(self, body, application):
body = body.replace("[rsvp-url-yes]", self.get_rsvp_link(application.get_rsvp_yes_code()))
Expand Down
2 changes: 1 addition & 1 deletion applications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def applications_csv(request, page_url):
except: # TODO: what's the exception here?
return redirect("core:event", page_url=page_url)
response = HttpResponse(content_type="text/csv")
response["Content-Disposition"] = f'attachment; filename="{page_url}.csv"'
response["Content-Disposition"] = f'attachment; filename="{page_url}.csv"' # noqa: E702
writer = csv.writer(response)
csv_header = [_("Application Number"), _("Application State"), _("RSVP Status"), _("Average Score")]
question_set = event.form.question_set
Expand Down
2 changes: 1 addition & 1 deletion coach/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def photo_display_for_admin(self):
return f"""
<a href=\"{coach_change_url}\" target=\"_blank\">
<img src=\"{self.photo_url}\" width=\"100\" />
</a>"""
</a>""" # noqa: E221, E222

photo_display_for_admin.allow_tags = True

Expand Down
2 changes: 1 addition & 1 deletion core/admin/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def has_stats(self, obj):
@admin.display(description=_("page URL"))
def full_url(self, obj):
url = reverse("core:event", kwargs={"page_url": obj.page_url})
url = f"https://djangogirls.org{url}"
url = f"https://djangogirls.org{url}" # noqa: E231
return mark_safe('<a href="{url}">{url}</a>'.format(url=url))

def get_readonly_fields(self, request, obj=None):
Expand Down
3 changes: 2 additions & 1 deletion core/flickr_api_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def get_photo_files(photo_list):
try:
for photo in photo_list:
request = requests.get(
f'https://live.staticflickr.com/{photo["server"]}/' f'{photo["id"]}_{photo["secret"]}_b.jpg'
f'https://live.staticflickr.com/{photo["server"]}/' # noqa: E231
f'{photo["id"]}_{photo["secret"]}_b.jpg'
)
photo_file = ImageFile(io.BytesIO(request.content), name=f'{photo["id"]}.jpg')
photo_files_list.append(photo_file)
Expand Down
4 changes: 3 additions & 1 deletion core/management/commands/copy_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def command():
brag_on_slack_bang(new_event.city, new_event.country, new_event.team.all())

click.echo(
click.style(f"Website is ready here: https://djangogirls.org/{new_event.page_url}", bold=True, fg="green")
click.style(
f"Website is ready here: https://djangogirls.org/{new_event.page_url}", bold=True, fg="green" # noqa: E231
)
)
click.echo("Congrats on yet another event!")
4 changes: 2 additions & 2 deletions core/management/commands/new_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def command(short):
click.secho("OOPS! Something went wrong!", fg="red")
for field, errors in form.errors.items():
for error in errors:
click.secho(f" {field:10} {error}", fg="red")
click.secho(f" {field:10} {error}", fg="red") # noqa: E231
return
event = form.save()

Expand All @@ -86,7 +86,7 @@ def command(short):

event.save()

click.secho(f"Website is ready here: http://djangogirls.org/{url}", fg="green")
click.secho(f"Website is ready here: http://djangogirls.org/{url}", fg="green") # noqa: E231
click.echo(DELIMITER)

click.secho("Ok, now follow this:", fg="black", bg="green")
Expand Down
2 changes: 1 addition & 1 deletion core/management/commands/prepare_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def generate_html_content(event_list):
for event in event_list:
city = event.city
url = event.page_url
html = f"<a href='https://djangogirls.org/{url}'>{city}</a>"
html = f"<a href='https://djangogirls.org/{url}'>{city}</a>" # noqa: E231
result.append(html)
return result

Expand Down
2 changes: 1 addition & 1 deletion core/management_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def brag_on_slack_bang(city, country, team):
"""
if settings.ENABLE_SLACK_NOTIFICATIONS:
text = (
f":django_pony: :zap: Woohoo! :tada: New Django Girls alert! "
f":django_pony: :zap: Woohoo! :tada: New Django Girls alert! " # noqa: E203, E231
f"Welcome Django Girls {city}, {country}. "
f"Congrats {', '.join(['{} {}'.format(x.first_name, x.last_name) for x in team])}!"
)
Expand Down
3 changes: 2 additions & 1 deletion djangogirls/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def gettext(s):

DATABASES = {}
DATABASES["default"] = dj_database_url.config(
default=f"postgres://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB}"
default=f"postgres://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}" # noqa: E231
f"/{POSTGRES_DB}"
)

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/core/event/view_manage_organizers.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block content %}
<h1 style="margin: 0 0 10px 0">{% trans "Remove event organizers" %}</h1>
<p>{% trans "Here you can remove exisiting event organizers." %}</p>
<p>{% trans "Here you can remove existing event organizers." %}</p>

{% if all_events.count > 1 %}
<p>{% trans "To get started, choose an event:" %}</p>
Expand Down
2 changes: 2 additions & 0 deletions tests/applications/views/test_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db import connection
from django.test.utils import CaptureQueriesContext
from django.urls import reverse
from django.utils import translation

from applications.models import Application, Score
from applications.views import application_list
Expand Down Expand Up @@ -35,6 +36,7 @@ def test_organiser_only_decorator_without_page_url(rf, user, future_event):


def test_organiser_menu_in_applications_list(admin_client, future_event):
translation.activate("en")
applications_url = reverse("applications:applications", kwargs={"page_url": future_event.page_url})
resp = admin_client.get(applications_url)
messaging_url = reverse("applications:communication", kwargs={"page_url": future_event.page_url})
Expand Down
8 changes: 5 additions & 3 deletions tests/applications/views/test_applications_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
from io import StringIO

from django.urls import reverse
from django.utils import translation

from applications.models import Answer, Application, Question


def test_download_applications_list(admin_client, future_event, future_event_form, applications):
translation.activate("en")
applications_url = reverse("applications:applications_csv", kwargs={"page_url": future_event.page_url})
resp = admin_client.get(applications_url)
assert resp.status_code == 200
assert resp.get("Content-Disposition") == f'attachment; filename="{future_event.page_url}.csv"'
assert resp.get("Content-Disposition") == f'attachment; filename="{future_event.page_url}.csv"' # noqa: E702
csv_file = StringIO(resp.content.decode("utf-8"))
reader = csv.reader(csv_file)
csv_list = list(reader)
Expand All @@ -30,7 +32,7 @@ def test_download_applications_list_uses_query_parameters_to_filter_applications
applications_url = reverse("applications:applications_csv", kwargs={"page_url": future_event.page_url})
resp = admin_client.get(applications_url + "?state=submitted&state=accepted")
assert resp.status_code == 200
assert resp.get("Content-Disposition") == f'attachment; filename="{future_event.page_url}.csv"'
assert resp.get("Content-Disposition") == f'attachment; filename="{future_event.page_url}.csv"' # noqa: E702
csv_file = StringIO(resp.content.decode("utf-8"))
reader = csv.reader(csv_file)
csv_list = list(reader)
Expand Down Expand Up @@ -59,7 +61,7 @@ def test_download_applications_list_with_question_added(
resp = admin_client.get(applications_url)

assert resp.status_code == 200
assert resp.get("Content-Disposition") == f'attachment; filename="{future_event.page_url}.csv"'
assert resp.get("Content-Disposition") == f'attachment; filename="{future_event.page_url}.csv"' # noqa: E702
csv_file = StringIO(resp.content.decode("utf-8"))
reader = csv.reader(csv_file)
csv_list = list(reader)
Expand Down

0 comments on commit 9f3b7a7

Please sign in to comment.