зеркало из https://github.com/mozilla/kitsune.git
use visible instead of unrestricted for dashboards (#5890)
* use visible instead of unrestricted in dashboards * adjust test_readouts test to account for visible method * adjust test_templates to account for visible method
This commit is contained in:
Родитель
b11d5a848d
Коммит
8d58be99ae
|
@ -113,7 +113,7 @@ def kb_overview_rows(user=None, mode=None, max=None, locale=None, product=None,
|
|||
if mode is None:
|
||||
mode = LAST_30_DAYS
|
||||
|
||||
docs = Document.objects.unrestricted(
|
||||
docs = Document.objects.visible(
|
||||
user, locale=settings.WIKI_DEFAULT_LANGUAGE, is_archived=False
|
||||
).exclude(html__startswith=REDIRECT_HTML)
|
||||
|
||||
|
@ -198,7 +198,7 @@ def l10n_overview_rows(locale, product=None, user=None):
|
|||
HOW_TO_CONTRIBUTE_CATEGORY,
|
||||
]
|
||||
|
||||
total = Document.objects.unrestricted(
|
||||
total = Document.objects.visible(
|
||||
user,
|
||||
locale=settings.WIKI_DEFAULT_LANGUAGE,
|
||||
is_archived=False,
|
||||
|
@ -231,7 +231,7 @@ def l10n_overview_rows(locale, product=None, user=None):
|
|||
)
|
||||
|
||||
up_to_date_translation_count = (
|
||||
Document.objects.unrestricted(
|
||||
Document.objects.visible(
|
||||
user,
|
||||
locale=locale,
|
||||
is_archived=False,
|
||||
|
@ -255,7 +255,7 @@ def l10n_overview_rows(locale, product=None, user=None):
|
|||
translated_templates = up_to_date_translation_count.filter(is_template=True).count()
|
||||
|
||||
top_n_query = (
|
||||
Document.objects.unrestricted(
|
||||
Document.objects.visible(
|
||||
user,
|
||||
locale=settings.WIKI_DEFAULT_LANGUAGE,
|
||||
is_archived=False,
|
||||
|
@ -493,7 +493,7 @@ class MostVisitedDefaultLanguageReadout(Readout):
|
|||
period = self.default_mode
|
||||
|
||||
qs = (
|
||||
Document.objects.unrestricted(
|
||||
Document.objects.visible(
|
||||
self.user,
|
||||
locale=self.locale,
|
||||
is_archived=False,
|
||||
|
@ -559,7 +559,7 @@ class CategoryReadout(Readout):
|
|||
else:
|
||||
period = self.default_mode
|
||||
|
||||
qs = Document.objects.unrestricted(
|
||||
qs = Document.objects.visible(
|
||||
self.user,
|
||||
locale=self.locale,
|
||||
is_archived=False,
|
||||
|
@ -668,7 +668,7 @@ class MostVisitedTranslationsReadout(MostVisitedDefaultLanguageReadout):
|
|||
HOW_TO_CONTRIBUTE_CATEGORY,
|
||||
]
|
||||
|
||||
qs = Document.objects.unrestricted(
|
||||
qs = Document.objects.visible(
|
||||
self.user,
|
||||
locale=settings.WIKI_DEFAULT_LANGUAGE,
|
||||
is_archived=False,
|
||||
|
@ -771,7 +771,7 @@ class TemplateTranslationsReadout(Readout):
|
|||
default_mode = None
|
||||
|
||||
def get_queryset(self, max=None):
|
||||
qs = Document.objects.unrestricted(
|
||||
qs = Document.objects.visible(
|
||||
self.user,
|
||||
locale=settings.WIKI_DEFAULT_LANGUAGE,
|
||||
is_template=True,
|
||||
|
@ -854,7 +854,7 @@ class UnreviewedReadout(Readout):
|
|||
order_by_args = (F("num_visits").desc(nulls_last=True), "title")
|
||||
|
||||
qs = (
|
||||
Revision.objects.unrestricted(
|
||||
Revision.objects.visible(
|
||||
self.user,
|
||||
reviewed__isnull=True,
|
||||
document__locale=self.locale,
|
||||
|
@ -985,7 +985,7 @@ class UnreadyForLocalizationReadout(Readout):
|
|||
order_by_args = (F("num_visits").desc(nulls_last=True), "title")
|
||||
|
||||
qs = (
|
||||
Revision.objects.unrestricted(
|
||||
Revision.objects.visible(
|
||||
self.user,
|
||||
is_approved=True,
|
||||
is_ready_for_localization=False,
|
||||
|
@ -1054,7 +1054,7 @@ class NeedsChangesReadout(Readout):
|
|||
default_mode = MOST_VIEWED
|
||||
|
||||
def get_queryset(self, max=None):
|
||||
qs = Document.objects.unrestricted(
|
||||
qs = Document.objects.visible(
|
||||
self.user,
|
||||
locale=settings.WIKI_DEFAULT_LANGUAGE,
|
||||
is_archived=False,
|
||||
|
@ -1098,7 +1098,7 @@ class CannedResponsesReadout(Readout):
|
|||
return request.LANGUAGE_CODE in QuestionLocale.objects.locales_list()
|
||||
|
||||
def get_queryset(self, max=None):
|
||||
qs = Document.objects.unrestricted(
|
||||
qs = Document.objects.visible(
|
||||
self.user,
|
||||
locale=settings.WIKI_DEFAULT_LANGUAGE,
|
||||
is_archived=False,
|
||||
|
|
|
@ -71,14 +71,14 @@ class KBOverviewTests(TestCase):
|
|||
def test_unapproved_articles(self):
|
||||
self.assertEqual(0, len(kb_overview_rows()))
|
||||
RevisionFactory()
|
||||
self.assertEqual(1, len(kb_overview_rows()))
|
||||
self.assertEqual(0, len(kb_overview_rows()))
|
||||
ApprovedRevisionFactory()
|
||||
self.assertEqual(2, len(kb_overview_rows()))
|
||||
self.assertEqual(1, len(kb_overview_rows()))
|
||||
group1 = GroupFactory(name="group1")
|
||||
RevisionFactory(document__restrict_to_groups=[group1])
|
||||
self.assertEqual(2, len(kb_overview_rows()))
|
||||
ApprovedRevisionFactory(document__restrict_to_groups=[group1])
|
||||
self.assertEqual(1, len(kb_overview_rows()))
|
||||
user1 = UserFactory(groups=[group1])
|
||||
self.assertEqual(3, len(kb_overview_rows(user=user1)))
|
||||
self.assertEqual(2, len(kb_overview_rows(user=user1)))
|
||||
|
||||
def test_ready_for_l10n(self):
|
||||
d = DocumentFactory()
|
||||
|
@ -96,18 +96,20 @@ class KBOverviewTests(TestCase):
|
|||
self.assertEqual(True, data[0]["ready_for_l10n"])
|
||||
|
||||
def test_filter_by_category(self):
|
||||
RevisionFactory(document__category=CATEGORIES[1][0])
|
||||
ApprovedRevisionFactory(document__category=CATEGORIES[1][0])
|
||||
|
||||
self.assertEqual(1, len(kb_overview_rows()))
|
||||
self.assertEqual(0, len(kb_overview_rows(category=CATEGORIES[0][0])))
|
||||
self.assertEqual(1, len(kb_overview_rows(category=CATEGORIES[1][0])))
|
||||
|
||||
def test_num_visits(self):
|
||||
d1 = DocumentFactory()
|
||||
d2 = DocumentFactory()
|
||||
DocumentFactory()
|
||||
DocumentFactory()
|
||||
d3 = DocumentFactory(restrict_to_groups=[GroupFactory(name="group1")])
|
||||
d1 = ApprovedRevisionFactory().document
|
||||
d2 = ApprovedRevisionFactory().document
|
||||
ApprovedRevisionFactory()
|
||||
ApprovedRevisionFactory()
|
||||
d3 = ApprovedRevisionFactory(
|
||||
document__restrict_to_groups=[GroupFactory(name="group1")]
|
||||
).document
|
||||
|
||||
WikiDocumentVisits.objects.create(document=d1, visits=5, period=LAST_30_DAYS)
|
||||
WikiDocumentVisits.objects.create(document=d2, visits=1, period=LAST_30_DAYS)
|
||||
|
@ -357,8 +359,11 @@ class UnreviewedChangesTests(ReadoutTestCase):
|
|||
rev2 = RevisionFactory(reviewed=None, document=rev1.document, created=datetime(2000, 2, 1))
|
||||
rev3 = RevisionFactory(reviewed=None, document=rev1.document, created=datetime(2000, 3, 1))
|
||||
|
||||
doc_de = TranslatedRevisionFactory(
|
||||
document__locale="de", reviewed=None, is_approved=True, created=datetime(2023, 1, 1)
|
||||
).document
|
||||
rev4 = TranslatedRevisionFactory(
|
||||
document__locale="de", reviewed=None, is_approved=False, created=datetime(2023, 1, 1)
|
||||
document=doc_de, reviewed=None, is_approved=False, created=datetime(2023, 1, 2)
|
||||
)
|
||||
rev5 = RevisionFactory(reviewed=None, document=rev4.document, created=datetime(2023, 2, 1))
|
||||
rev6 = RevisionFactory(reviewed=None, document=rev4.document, created=datetime(2023, 3, 1))
|
||||
|
@ -434,9 +439,10 @@ class UnreviewedChangesTests(ReadoutTestCase):
|
|||
|
||||
def test_current_revision_null(self):
|
||||
"""Show all unreviewed revisions if none have been approved yet."""
|
||||
unreviewed = TranslatedRevisionFactory(
|
||||
is_approved=False, reviewed=None, document__locale="de"
|
||||
)
|
||||
doc_de = TranslatedRevisionFactory(
|
||||
is_approved=True, reviewed=None, document__locale="de"
|
||||
).document
|
||||
unreviewed = TranslatedRevisionFactory(is_approved=False, reviewed=None, document=doc_de)
|
||||
assert unreviewed.document.title in self.titles()
|
||||
|
||||
def test_rejected_newer_than_current(self):
|
||||
|
@ -449,9 +455,10 @@ class UnreviewedChangesTests(ReadoutTestCase):
|
|||
def test_by_product(self):
|
||||
"""Test the product filtering of the readout."""
|
||||
p = ProductFactory(title="Firefox", slug="firefox")
|
||||
unreviewed = TranslatedRevisionFactory(
|
||||
is_approved=False, reviewed=None, document__locale="de"
|
||||
)
|
||||
doc_de = TranslatedRevisionFactory(
|
||||
is_approved=True, reviewed=None, document__locale="de"
|
||||
).document
|
||||
unreviewed = TranslatedRevisionFactory(is_approved=False, reviewed=None, document=doc_de)
|
||||
|
||||
# There shouldn't be any rows yet.
|
||||
self.assertEqual(0, len(self.rows(product=p)))
|
||||
|
@ -496,9 +503,13 @@ class TemplateTests(ReadoutTestCase):
|
|||
|
||||
d = DocumentFactory(products=[p])
|
||||
t = TemplateDocumentFactory(products=[p])
|
||||
ApprovedRevisionFactory(document=t)
|
||||
ApprovedRevisionFactory(document=d)
|
||||
ApprovedRevisionFactory(document=TemplateDocumentFactory())
|
||||
TemplateDocumentFactory(restrict_to_groups=[GroupFactory(name="group1")], products=[p])
|
||||
rt = TemplateDocumentFactory(
|
||||
restrict_to_groups=[GroupFactory(name="group1")], products=[p]
|
||||
)
|
||||
ApprovedRevisionFactory(document=rt)
|
||||
|
||||
self.assertEqual(1, len(self.rows(locale=locale, product=p)))
|
||||
self.assertEqual(t.title, self.row(locale=locale, product=p)["title"])
|
||||
|
@ -519,6 +530,7 @@ class TemplateTests(ReadoutTestCase):
|
|||
"""Test status for article that needs review"""
|
||||
locale = settings.WIKI_DEFAULT_LANGUAGE
|
||||
d = TemplateDocumentFactory()
|
||||
ApprovedRevisionFactory(document=d)
|
||||
RevisionFactory(document=d)
|
||||
|
||||
row = self.row(locale=locale)
|
||||
|
@ -828,12 +840,12 @@ class NeedsChangesTests(ReadoutTestCase):
|
|||
|
||||
readout = NeedsChangesReadout
|
||||
|
||||
def test_unrevieweds_after_current(self):
|
||||
def test_needs_change(self):
|
||||
"""A document marked with needs_change=True should show up."""
|
||||
document = DocumentFactory(
|
||||
needs_change=True, needs_change_comment="Please update for Firefox.next"
|
||||
)
|
||||
RevisionFactory(document=document)
|
||||
ApprovedRevisionFactory(document=document)
|
||||
titles = self.titles()
|
||||
self.assertEqual(1, len(titles))
|
||||
assert document.title in titles
|
||||
|
@ -844,7 +856,7 @@ class NeedsChangesTests(ReadoutTestCase):
|
|||
d = DocumentFactory(
|
||||
needs_change=True, needs_change_comment="Please update for Firefox.next"
|
||||
)
|
||||
RevisionFactory(document=d)
|
||||
ApprovedRevisionFactory(document=d)
|
||||
|
||||
# There shouldn't be any rows yet.
|
||||
self.assertEqual(0, len(self.rows(product=p)))
|
||||
|
|
|
@ -25,8 +25,9 @@ class LocalizationDashTests(TestCase):
|
|||
def test_render(self):
|
||||
"""Assert main dash and all the readouts render and don't crash."""
|
||||
# Put some stuff in the DB so at least one row renders for each readout:
|
||||
doc_de = TranslatedRevisionFactory(document__locale="de", is_approved=True).document
|
||||
unreviewed = TranslatedRevisionFactory(
|
||||
document__locale="de", reviewed=None, is_approved=False, is_ready_for_localization=True
|
||||
document=doc_de, reviewed=None, is_approved=False, is_ready_for_localization=True
|
||||
)
|
||||
|
||||
response = self.client.get(reverse("dashboards.localization", locale="de"), follow=False)
|
||||
|
|
Загрузка…
Ссылка в новой задаче