Skip to content

Commit

Permalink
Resolved fixable warnings when running pytest (#3206)
Browse files Browse the repository at this point in the history
Co-authored-by: Harmit Goswami <hgoswami@LH7VKLQY46.local>
  • Loading branch information
harmitgoswami and Harmit Goswami committed May 9, 2024
1 parent c5bc26d commit 1ee7ee1
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 4.2.11 on 2024-05-09 13:51

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("base", "0059_alter_translation_machinery_sources"),
]

operations = [
migrations.RenameIndex(
model_name="entity",
new_name="base_entity_resourc_f99fa1_idx",
old_fields=("resource", "obsolete", "string_plural"),
),
migrations.RenameIndex(
model_name="translation",
new_name="base_transl_date_30b613_idx",
old_fields=("date", "locale"),
),
migrations.RenameIndex(
model_name="translation",
new_name="base_transl_entity__0b63dc_idx",
old_fields=("entity", "user", "approved", "pretranslated"),
),
migrations.RenameIndex(
model_name="translation",
new_name="base_transl_entity__afb3fd_idx",
old_fields=("entity", "locale", "approved"),
),
migrations.RenameIndex(
model_name="translation",
new_name="base_transl_entity__e71151_idx",
old_fields=("entity", "locale", "fuzzy"),
),
migrations.RenameIndex(
model_name="translation",
new_name="base_transl_entity__30552e_idx",
old_fields=("entity", "locale", "pretranslated"),
),
migrations.RenameIndex(
model_name="translation",
new_name="base_transl_approve_e5fa5f_idx",
old_fields=("approved_date", "locale"),
),
migrations.RenameIndex(
model_name="translation",
new_name="base_transl_locale__0c5933_idx",
old_fields=("locale", "user", "entity"),
),
]
4 changes: 3 additions & 1 deletion pontoon/base/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ class Entity(DirtyFieldsMixin, models.Model):
objects = EntityQuerySet.as_manager()

class Meta:
index_together = (("resource", "obsolete", "string_plural"),)
indexes = [
models.Index(fields=["resource", "obsolete", "string_plural"]),
]

@property
def cleaned_key(self):
Expand Down
18 changes: 9 additions & 9 deletions pontoon/base/models/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ class MachinerySource(models.TextChoices):
objects = TranslationQuerySet.as_manager()

class Meta:
index_together = (
("entity", "user", "approved", "pretranslated"),
("entity", "locale", "approved"),
("entity", "locale", "pretranslated"),
("entity", "locale", "fuzzy"),
("locale", "user", "entity"),
("date", "locale"),
("approved_date", "locale"),
)
indexes = [
models.Index(fields=["entity", "user", "approved", "pretranslated"]),
models.Index(fields=["entity", "locale", "approved"]),
models.Index(fields=["entity", "locale", "pretranslated"]),
models.Index(fields=["entity", "locale", "fuzzy"]),
models.Index(fields=["locale", "user", "entity"]),
models.Index(fields=["date", "locale"]),
models.Index(fields=["approved_date", "locale"]),
]
constraints = [
models.UniqueConstraint(
name="entity_locale_plural_form_active",
Expand Down
16 changes: 7 additions & 9 deletions pontoon/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import zipfile

from collections import defaultdict
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from guardian.decorators import permission_required as guardian_permission_required
from urllib.parse import urljoin
from xml.sax.saxutils import escape, quoteattr
Expand All @@ -22,7 +22,7 @@
from django.http import HttpResponseBadRequest, Http404
from django.shortcuts import redirect, get_object_or_404
from django.urls import reverse
from django.utils import timezone
from django.utils.timezone import make_aware, now
from django.utils.text import slugify
from django.utils.translation import trans_real

Expand Down Expand Up @@ -350,9 +350,7 @@ def handle_upload_content(slug, code, part, f, user):
resource_file = formats.parse(temp.name)

# Update database objects from file
changeset = ChangeSet(
project, VCSProject(project, locales=[locale]), timezone.now()
)
changeset = ChangeSet(project, VCSProject(project, locales=[locale]), now())
entities_qs = (
Entity.objects.filter(
resource__project=project, resource__path=part, obsolete=False
Expand All @@ -368,7 +366,7 @@ def handle_upload_content(slug, code, part, f, user):
Prefetch(
"translation_set",
queryset=Translation.objects.filter(
locale=locale, approved_date__lte=timezone.now()
locale=locale, approved_date__lte=now()
),
to_attr="db_translations_approved_before_sync",
)
Expand Down Expand Up @@ -424,7 +422,7 @@ def handle_upload_content(slug, code, part, f, user):

def aware_datetime(*args, **kwargs):
"""Return an aware datetime using Django's configured timezone."""
return timezone.make_aware(datetime(*args, **kwargs))
return make_aware(datetime(*args, **kwargs))


def latest_datetime(datetimes):
Expand All @@ -436,7 +434,7 @@ def latest_datetime(datetimes):
if all(map(lambda d: d is None, datetimes)):
return None

min_datetime = timezone.make_aware(datetime.min)
min_datetime = make_aware(datetime.min)
datetimes = map(lambda d: d or min_datetime, datetimes)
return max(datetimes)

Expand All @@ -449,7 +447,7 @@ def parse_time_interval(interval):
"""

def parse_timestamp(timestamp):
return timezone.make_aware(
return make_aware(
datetime.strptime(timestamp, "%Y%m%d%H%M"), timezone=timezone.utc
)

Expand Down
12 changes: 6 additions & 6 deletions pontoon/contributors/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def action_a(translation_a):
action_type=ActionLog.ActionType.TRANSLATION_CREATED,
translation=translation_a,
)
action.created_at = datetime(2020, 1, 1)
action.created_at = timezone.make_aware(datetime(2020, 1, 1))
action.save()
return action

Expand All @@ -38,7 +38,7 @@ def action_b(translation_a):
action_type=ActionLog.ActionType.TRANSLATION_CREATED,
translation=translation_a,
)
action.created_at = datetime(2020, 1, 1)
action.created_at = timezone.make_aware(datetime(2020, 1, 1))
action.save()
return action

Expand All @@ -49,7 +49,7 @@ def action_c(translation_a):
action_type=ActionLog.ActionType.TRANSLATION_CREATED,
translation=translation_a,
)
action.created_at = datetime(2020, 2, 1)
action.created_at = timezone.make_aware(datetime(2020, 2, 1))
action.save()
return action

Expand All @@ -61,7 +61,7 @@ def action_user_a(translation_a, user_a):
performed_by=user_a,
translation=translation_a,
)
action.created_at = datetime.now() - relativedelta(months=1)
action.created_at = timezone.now() - relativedelta(months=1)
action.save()
return action

Expand All @@ -73,7 +73,7 @@ def action_user_b(translation_a, user_b):
performed_by=user_b,
translation=translation_a,
)
action.created_at = datetime.now()
action.created_at = timezone.now()
action.save()
return action

Expand All @@ -85,7 +85,7 @@ def yesterdays_action_user_a(translation_a, user_a):
performed_by=user_a,
translation=translation_a,
)
action.created_at = datetime.now() - relativedelta(days=1)
action.created_at = timezone.now() - relativedelta(days=1)
action.save()
return action

Expand Down
13 changes: 6 additions & 7 deletions pontoon/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,12 @@ def _default_from_email():
# Example: "http://media.lawrence.com/static/"
STATIC_URL = STATIC_HOST + "/static/"

STATICFILES_STORAGE = "pontoon.base.storage.CompressedManifestPipelineStorage"
STORAGES = {
"staticfiles": {
"BACKEND": "pontoon.base.storage.CompressedManifestPipelineStorage",
},
}

STATICFILES_FINDERS = (
"pipeline.finders.PipelineFinder",
"django.contrib.staticfiles.finders.FileSystemFinder",
Expand All @@ -719,9 +724,7 @@ def _default_from_email():
"django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
"django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
"django.contrib.auth.hashers.BCryptPasswordHasher",
"django.contrib.auth.hashers.SHA1PasswordHasher",
"django.contrib.auth.hashers.MD5PasswordHasher",
"django.contrib.auth.hashers.UnsaltedMD5PasswordHasher",
)

# Logging
Expand Down Expand Up @@ -850,10 +853,6 @@ def _default_from_email():
# to load the internationalization machinery.
USE_I18N = False

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = False

# Enable Bugs tab on the team pages, pulling data from bugzilla.mozilla.org.
# See bug 1567402 for details. A Mozilla-specific variable.
ENABLE_BUGS_TAB = os.environ.get("ENABLE_BUGS_TAB", "False") != "False"
Expand Down

0 comments on commit 1ee7ee1

Please sign in to comment.