Skip to content

Commit

Permalink
Add gunaha user to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed Jan 20, 2025
1 parent 3754ef1 commit ea1db60
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
23 changes: 21 additions & 2 deletions cypress/e2e/srseng/basics.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import urls from "../../support/urls";

describe("The Tsúūt'ínà site", function () {
this.beforeEach(() => {
const cookies = Cypress.env('cookies') || []
cookies.forEach(c => cy.setCookie(c.name,c.value))
});

it("works", function () {
cy.visit(`${urls.srseng}`);
cy.get(".branding__heading").contains("Gūnáhà");
});

it("can login before anything", function () {
cy.user_login(`${urls.srseng}/accounts/login/?next=/`)
cy.getCookies().then(cookies => {
var values=""
cookies.forEach(c => values+=`{${c.name},${c.value}}`)
Cypress.log({
name: "cookies",
message: `${values}`,
})
Cypress.env('cookies', cookies)
})
cy.visit(`${urls.srseng}`);
});

it("can search for a word", function () {
cy.visitSearch(`yidiskid`, urls.srseng).searchResultsContain("yídiskid");
cy.visitSearch(`yidiskid`, urls.srseng).searchResultsContain("yídiskid");
});

it("can display a paradigm", function () {
cy.visit(`${urls.srseng}/word/yídiskid`);
cy.get(".paradigm-cell").contains("mídiskid");
});
});
});
5 changes: 5 additions & 0 deletions scripts/create_gunaha_user
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib.auth.models import User, Group
user=User.objects.create_user('test_user', password='test')
group, _ = Group.objects.get_or_create(name="gunaha")
user.groups.add(group)
user.save()
5 changes: 5 additions & 0 deletions scripts/run-cypress
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def main():
for script in manage_scripts:
check_call([script, "ensuretestdb"], env=m_env)

# Create the gunaha user!
for script in manage_scripts:
with open('./create_gunaha_user') as stdin:
check_call([script, "shell"], env=m_env, stdin=stdin)

servers = []
for script in manage_scripts:
servers.append(Popen([script, "runserver"], env=m_env))
Expand Down
10 changes: 10 additions & 0 deletions src/morphodict/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def entry_details(request, slug: str):
:param slug: the stable unique ID of the lemma
"""
if settings.MORPHODICT_REQUIRES_LOGIN_IN_GROUP:
if not request.user.is_authenticated:
return redirect("/accounts/login/?next=%s" % request.path)
else:
groupnames = [x["name"] for x in request.user.groups.values("name")]
if settings.MORPHODICT_REQUIRES_LOGIN_IN_GROUP not in groupnames:
path = request.path
logout(request)
return redirect("/accounts/login/?next=%s" % path)

lemmas = Wordform.objects.filter(slug=slug, is_lemma=True)

if lemmas.count() != 1:
Expand Down

0 comments on commit ea1db60

Please sign in to comment.