Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add test

Patryk Zawadzki976263150664
diff --git a/templates/product/details.html b/templates/product/details.html
index 5de55d83ac..7eb051ddd9 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -22,9 +22,9 @@
{% block outercontent %}
{% if not is_visible %}
-<div class="alert alert-warning" role="alert">
- {% blocktrans with date=product.available_on|date %}<strong>Warning!</strong> You are previewing a product that will become visible on <strong>{{ date }}</strong>.{% endblocktrans %}
-</div>
+ <div class="alert alert-warning" role="alert">
+ {% blocktrans with date=product.available_on|date %}<strong>Warning!</strong> You are previewing a product that will become visible on <strong>{{ date }}</strong>.{% endblocktrans %}
+ </div>
{% endif %}
<div itemscope itemtype="http://schema.org/Product">
<div class="row">
diff --git a/tests/conftest.py b/tests/conftest.py
index 419f17906f..d7f4e29339 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -4,7 +4,32 @@ from __future__ import unicode_literals
import pytest
from saleor.product.models import Product, ProductVariant, Stock
-from saleor.userprofile.models import Address
+from saleor.userprofile.models import Address, User
+
+
+def admin_user(db):
+ """A Django admin user.
+
+ This uses an existing user with username "admin", or creates a new one with
+ password "password".
+ """
+ try:
+ user = User.objects.get(email='[email protected]')
+ except User.DoesNotExist:
+ user = User.objects.create_superuser(
+ '[email protected]', 'password')
+ return user
+
+
+def admin_client(db, admin_user):
+ """A Django test client logged in as an admin user."""
+ from django.test.client import Client
+
+ client = Client()
+ client.login(username=admin_user.email, password='password')
+ return client
@pytest.fixture
diff --git a/tests/dashboard/conftest.py b/tests/dashboard/conftest.py
deleted file mode 100644
index 6c2ac8397b..0000000000
--- a/tests/dashboard/conftest.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
-import pytest
-
-
-def admin_user(db, django_user_model, django_username_field):
- """A Django admin user.
-
- This uses an existing user with username "admin", or creates a new one with
- password "password".
- """
- UserModel = django_user_model
- username_field = django_username_field
-
- try:
- user = UserModel._default_manager.get(**{username_field: 'admin'})
- except UserModel.DoesNotExist:
- extra_fields = {}
- if username_field not in {'username', 'email'}:
- extra_fields[username_field] = 'admin'
- user = UserModel._default_manager.create_superuser(
- '[email protected]', 'password', **extra_fields)
- return user
-
-
-def admin_client(db, admin_user):
- """A Django test client logged in as an admin user."""
- from django.test.client import Client
-
- client = Client()
- client.login(username=admin_user.email, password='password')
- return client
diff --git a/tests/test_product.py b/tests/test_product.py
index e5dd38e7fa..9d4c94227f 100644
--- a/tests/test_product.py
+++ b/tests/test_product.py
@@ -1,3 +1,5 @@
+import datetime
+
import pytest
from saleor.product import models
@@ -16,3 +18,13 @@ def test_stock_allocator(product_in_stock):
models.Stock.objects.allocate_stock(stock, 1)
stock = models.Stock.objects.get(pk=stock.pk)
assert stock.quantity_allocated == 1
+
+
+def test_product_preview(admin_client, client, product_in_stock):
+ product_in_stock.available_on = (
+ datetime.date.today() + datetime.timedelta(days=7))
+ product_in_stock.save()
+ response = client.get(product_in_stock.get_absolute_url())
+ assert response.status_code == 404
+ response = admin_client.get(product_in_stock.get_absolute_url())
+ assert response.status_code == 200