mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-02 11:52:27 +02:00
63 autocomplete personal informations
This commit is contained in:
parent
d2053c7da9
commit
12f91b55bd
5 changed files with 80 additions and 20 deletions
|
@ -4,6 +4,7 @@ import pytest
|
|||
from django.utils import timezone
|
||||
|
||||
from la_chariotte.order.models import GroupedOrder, Item
|
||||
from la_chariotte.tests.utils import create_grouped_order
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -23,6 +24,18 @@ def other_user(django_user_model):
|
|||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def authenticated_user_with_name(django_user_model):
|
||||
username = "toto@gmail.com"
|
||||
password = "tata"
|
||||
first_name = "boule"
|
||||
last_name = "bill"
|
||||
user = django_user_model.objects.create_user(
|
||||
username=username, password=password, first_name=first_name, last_name=last_name
|
||||
)
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def simple_grouped_order(other_user):
|
||||
date = timezone.now().date() + datetime.timedelta(days=30)
|
||||
|
@ -39,6 +52,19 @@ def simple_grouped_order(other_user):
|
|||
return grouped_order
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def connected_grouped_order(client, authenticated_user_with_name):
|
||||
client.force_login(authenticated_user_with_name)
|
||||
grouped_order = create_grouped_order(
|
||||
name="Test grouped order",
|
||||
orga_user=authenticated_user_with_name,
|
||||
days_before_delivery_date=30,
|
||||
days_before_deadline=5,
|
||||
)
|
||||
item = Item.objects.create(name="test item", grouped_order=grouped_order, price=2)
|
||||
return grouped_order
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def password_hasher_setup(settings):
|
||||
# Use a weaker password hasher during tests, for speed
|
||||
|
|
|
@ -97,8 +97,6 @@ class GroupedOrder(models.Model):
|
|||
class OrderAuthor(models.Model):
|
||||
"""Used when a user orders (with or without an account)"""
|
||||
|
||||
# TODO faire le lien avec CustomUser (CustomUser hérite de OrderAuthor),
|
||||
# pour ensuite préremplir quand on est connecté·e
|
||||
first_name = models.CharField(verbose_name="Prénom")
|
||||
last_name = models.CharField(verbose_name="Nom")
|
||||
phone = models.CharField(
|
||||
|
|
|
@ -152,18 +152,18 @@
|
|||
<div class="column">
|
||||
<p><label for="first_name">Prénom : </label>
|
||||
<input id="first_name" type="text" name="first_name" placeholder="Votre prénom"
|
||||
value="{{ author.first_name }}" required></p>
|
||||
value="{{ order_author.first_name }}" required></p>
|
||||
<p><label for="first_name">Nom : </label>
|
||||
<input id="last_name" type="text" name="last_name" placeholder="Votre nom"
|
||||
value="{{ author.last_name }}" required></p>
|
||||
value="{{ order_author.last_name }}" required></p>
|
||||
</div>
|
||||
<div class="column">
|
||||
<p><label for="phone">Numéro de téléphone :</label>
|
||||
<input id="phone" type="tel" pattern="[0-9]{10}" placeholder="0601020304" name="phone"
|
||||
value="{{ author.phone }}" required></p>
|
||||
value="{{ order_author.phone }}" required></p>
|
||||
<p><label for="email">Adresse mail : </label>
|
||||
<input id="email" type="email" placeholder="exemple@mail.fr" name="email"
|
||||
value="{{ author.email }}" required></p>
|
||||
value="{{ order_author.email }}" required></p>
|
||||
</div>
|
||||
</div>
|
||||
<p><label for="note">Note à l'organisateur·ice</label>
|
||||
|
|
|
@ -117,12 +117,23 @@ class GroupedOrderDetailView(generic.DetailView):
|
|||
remaining_qty = {item.id: item.get_remaining_nb() for item in items}
|
||||
prices_dict = {item.id: item.price for item in items}
|
||||
|
||||
if self.request.user.is_authenticated:
|
||||
order_author = OrderAuthor.objects.create(
|
||||
first_name=self.request.user.first_name,
|
||||
last_name=self.request.user.last_name,
|
||||
email=self.request.user.username,
|
||||
)
|
||||
order_author.save()
|
||||
else:
|
||||
order_author = None
|
||||
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update(
|
||||
{
|
||||
# Used for the js display of total price of an order
|
||||
"prices_dict": json.dumps(prices_dict, cls=DjangoJSONEncoder),
|
||||
"remaining_qty": remaining_qty,
|
||||
"order_author": order_author,
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
|
|
@ -4,14 +4,14 @@ from io import StringIO
|
|||
|
||||
import pytest
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth import get_user
|
||||
from django.forms.utils import to_current_timezone
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from icalendar import Calendar
|
||||
from icalendar import Calendar, vText
|
||||
|
||||
from la_chariotte.order import models
|
||||
|
||||
from .utils import create_grouped_order, order_items_in_grouped_order
|
||||
from la_chariotte.tests.utils import create_grouped_order, order_items_in_grouped_order
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
@ -215,11 +215,32 @@ class TestJoinGroupedOrderView:
|
|||
response = client.post(join_url, {"code": "123456"})
|
||||
|
||||
assert (
|
||||
"nous ne trouvons aucune commande avec ce code" in response.content.decode()
|
||||
"Désolé, nous ne trouvons aucune commande avec ce code"
|
||||
in response.content.decode()
|
||||
)
|
||||
|
||||
|
||||
class TestGroupedOrderDetailView:
|
||||
def test_order_item_with_authenticated_user(self, client, connected_grouped_order):
|
||||
detail_url = reverse(
|
||||
"order:grouped_order_detail",
|
||||
kwargs={
|
||||
"code": connected_grouped_order.code,
|
||||
},
|
||||
)
|
||||
response = client.get(detail_url)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
order_author = response.context[0]["order_author"]
|
||||
current_user = get_user(client)
|
||||
|
||||
assert order_author is not None
|
||||
|
||||
assert order_author.first_name == current_user.first_name
|
||||
assert order_author.email == current_user.username
|
||||
assert order_author.last_name == current_user.last_name
|
||||
|
||||
def test_order_item(self, client, other_user):
|
||||
"""
|
||||
From the OrderDetailView, we order an item using the order form, and it creates an models.Order with an Ordered_item inside
|
||||
|
@ -300,7 +321,9 @@ class TestGroupedOrderDetailView:
|
|||
# OrderedItems are not created when the ordered quantity is 0
|
||||
assert models.OrderedItem.objects.count() == 2
|
||||
|
||||
def test_order_item__no_articles_ordered(self, client, other_user):
|
||||
def test_order_item__no_articles_ordered(
|
||||
self, client, authenticated_user_with_name
|
||||
):
|
||||
"""
|
||||
From the OrderDetailView, we order without having changed any item quantity.
|
||||
An error is raised.
|
||||
|
@ -310,7 +333,7 @@ class TestGroupedOrderDetailView:
|
|||
days_before_delivery_date=5,
|
||||
days_before_deadline=2,
|
||||
name="gr order test",
|
||||
orga_user=other_user,
|
||||
orga_user=authenticated_user_with_name,
|
||||
)
|
||||
item = models.Item.objects.create(
|
||||
name="test item 1", grouped_order=grouped_order, price=1
|
||||
|
@ -336,10 +359,10 @@ class TestGroupedOrderDetailView:
|
|||
order_url,
|
||||
{
|
||||
f"quantity_{item.pk}": [0, 0],
|
||||
"first_name": "Prénom test",
|
||||
"last_name": "Nom test",
|
||||
"first_name": {authenticated_user_with_name.first_name},
|
||||
"last_name": {authenticated_user_with_name.last_name},
|
||||
"phone": "0645632569",
|
||||
"email": "test@mail.fr",
|
||||
"email": {authenticated_user_with_name.email},
|
||||
"note": "test note",
|
||||
},
|
||||
)
|
||||
|
@ -348,12 +371,14 @@ class TestGroupedOrderDetailView:
|
|||
response.context["error_message"]
|
||||
== "Veuillez commander au moins un produit"
|
||||
)
|
||||
assert response.context["author"].first_name == "Prénom test"
|
||||
assert (
|
||||
response.context["author"].first_name
|
||||
== authenticated_user_with_name.first_name
|
||||
)
|
||||
content = response.content.decode()
|
||||
assert "Prénom test" in content
|
||||
assert "Nom test" in content
|
||||
assert "0645632569" in content
|
||||
assert "test@mail.fr" in content
|
||||
assert authenticated_user_with_name.first_name in content
|
||||
assert authenticated_user_with_name.last_name in content
|
||||
assert authenticated_user_with_name.email in content
|
||||
assert "test note" in content
|
||||
assert not models.Order.objects.first()
|
||||
assert not models.OrderAuthor.objects.first()
|
||||
|
|
Loading…
Reference in a new issue