mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-05 06:13:55 +01:00
parent
3506f0becc
commit
66afe8265b
4 changed files with 59 additions and 6 deletions
6
.idea/sonarlint.xml
Normal file
6
.idea/sonarlint.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SonarLintProjectSettings">
|
||||
<option name="bindingSuggestionsEnabled" value="false" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,5 +1,6 @@
|
|||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.models import Q
|
||||
|
||||
from character.models import Character
|
||||
from party.models import Party
|
||||
|
@ -9,9 +10,16 @@ class PartyForm(forms.ModelForm):
|
|||
def __init__(self, *args, **kwargs):
|
||||
self.original_instance = kwargs.get("instance")
|
||||
super().__init__(*args, **kwargs)
|
||||
qs = Character.objects.filter(private=False)
|
||||
qs = Character.objects.all()
|
||||
if self.original_instance:
|
||||
qs = qs.union(self.original_instance.invited_characters.all())
|
||||
qs = qs.filter(
|
||||
Q(private=False)
|
||||
| Q(
|
||||
pk__in=self.original_instance.invited_characters.all().values_list(
|
||||
"pk", flat=True
|
||||
)
|
||||
)
|
||||
)
|
||||
self.fields["invited_characters"].queryset = qs
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -12,19 +12,19 @@
|
|||
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
|
||||
{% for party in managed_parties %}
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card party" data-id="{{ party.pk }}">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">
|
||||
{{ party.name }}
|
||||
</h5>
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="{% url "party:details" pk=party.pk %}" class="btn btn-success">
|
||||
<a href="{% url "party:details" pk=party.pk %}" class="btn btn-success access">
|
||||
<i class="fa-solid fa-users"></i> Accéder
|
||||
</a>
|
||||
<a href="{% url "party:change" pk=party.pk %}" class="btn btn-secondary">
|
||||
<a href="{% url "party:change" pk=party.pk %}" class="btn btn-secondary edit">
|
||||
<i class="fa-solid fa-gear"></i> Modifier
|
||||
</a>
|
||||
<a href="{% url "party:delete" pk=party.pk %}" class="btn btn-danger">
|
||||
<a href="{% url "party:delete" pk=party.pk %}" class="btn btn-danger delete">
|
||||
<i class="fa-solid fa-users-slash"></i> Supprimer
|
||||
</a>
|
||||
</div>
|
||||
|
|
39
src/party/tests/test_interactions.py
Normal file
39
src/party/tests/test_interactions.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import pytest
|
||||
from django.core.management import call_command
|
||||
from django.urls import reverse
|
||||
from model_bakery import baker
|
||||
from pytest_django.live_server_helper import LiveServer
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.firefox.webdriver import WebDriver
|
||||
from selenium.webdriver.support.select import Select
|
||||
|
||||
from character.models import Character
|
||||
from character.tests.test_interactions import login
|
||||
from common.models import User
|
||||
from party.models import Party
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_add_character_to_existing_group(selenium: WebDriver, live_server: LiveServer):
|
||||
call_command("loaddata", "initial_data")
|
||||
|
||||
username, password = "gm", "password"
|
||||
gm = User.objects.create_user(username, password=password)
|
||||
player = User.objects.create_user("player")
|
||||
character = baker.make(Character, player=player)
|
||||
party = baker.make(Party, game_master=gm)
|
||||
|
||||
selenium.get(live_server.url)
|
||||
login(selenium, username, password)
|
||||
|
||||
selenium.get(live_server.url + reverse("party:list"))
|
||||
selenium.find_element(
|
||||
By.CSS_SELECTOR, f".party[data-id='{party.pk}'] .edit"
|
||||
).click()
|
||||
invited = Select(selenium.find_element(By.ID, "id_invited_characters"))
|
||||
invited.select_by_index(0)
|
||||
selenium.find_element(By.CSS_SELECTOR, "[type=submit]").click()
|
||||
|
||||
assert selenium.current_url == live_server.url + reverse("party:list")
|
||||
party.refresh_from_db()
|
||||
assert set(party.invited_characters.all()) == {character}
|
Loading…
Reference in a new issue