Browse Source

added functests orders, happy path only

funding-tag
Holger Frey 5 years ago
parent
commit
39525d51f8
  1. 16
      ordr3/static/script.js
  2. 1
      ordr3/templates/layout_full.jinja2
  3. 2
      ordr3/templates/orders/batch_delete.jinja2
  4. 2
      ordr3/templates/orders/batch_edit.jinja2
  5. 3
      ordr3/views/orders.py
  6. 35
      tests/functional/conftest.py
  7. 141
      tests/functional/test_a_order.py
  8. 125
      tests/functional/test_order_list.py

16
ordr3/static/script.js

@ -63,6 +63,14 @@ $(function() {
} }
}); });
$(".o3-reg-username-source").on("keyup", function(event) {
// automatic username creation
var first_name = $(".o3-reg-firstname").val();
var last_name = $(".o3-reg-lastname").val();
var user_name = capitalize(first_name) + capitalize(last_name)
$(".o3-reg-username").val(user_name);
});
$(".o3-details").on("click", function(event){ $(".o3-details").on("click", function(event){
// handle detail visibility // handle detail visibility
var target = $(event.delegateTarget) var target = $(event.delegateTarget)
@ -77,14 +85,6 @@ $(function() {
} }
}); });
$(".o3-reg-username-source").on("keyup", function(event) {
// automatic username creation
var first_name = $(".o3-reg-firstname").val();
var last_name = $(".o3-reg-lastname").val();
var user_name = capitalize(first_name) + capitalize(last_name)
$(".o3-reg-username").val(user_name);
});
$("#o3-selectall").on("click", function(event) { $("#o3-selectall").on("click", function(event) {
// select all checkboxes // select all checkboxes
var target = $(event.delegateTarget); var target = $(event.delegateTarget);

1
ordr3/templates/layout_full.jinja2

@ -84,6 +84,7 @@
</li> </li>
</ul> </ul>
</div> </div>
</div>
</header> </header>
<div class="container-fluid o3-head-space o3-content"> <div class="container-fluid o3-head-space o3-content">
<div class="row"> <div class="row">

2
ordr3/templates/orders/batch_delete.jinja2

@ -46,7 +46,7 @@
{{ order.vendor }} {{ order.vendor }}
</td> </td>
<td class="text-right"> <td class="text-right">
<span class="o3-dont-wrap">{{ "%.2f"|format(order.total_price)|replace(".", ",") }}</a> {{ order.currency }}</span> <span class="o3-dont-wrap">{{ "%.2f"|format(order.total_price)|replace(".", ",") }} {{ order.currency }}</span>
</td> </td>
<td> <td>
{{ order.created_by }} {{ order.created_by }}

2
ordr3/templates/orders/batch_edit.jinja2

@ -43,7 +43,7 @@
{{ order.vendor }} {{ order.vendor }}
</td> </td>
<td class="text-right"> <td class="text-right">
<span class="o3-dont-wrap">{{ "%.2f"|format(order.total_price)|replace(".", ",") }}</a> {{ order.currency }}</span> <span class="o3-dont-wrap">{{ "%.2f"|format(order.total_price)|replace(".", ",") }} {{ order.currency }}</span>
</td> </td>
<td> <td>
{{ order.created_by }} {{ order.created_by }}

3
ordr3/views/orders.py

@ -151,7 +151,8 @@ def order_list(context, request):
renderer="ordr3:templates/orders/batch_delete.jinja2", renderer="ordr3:templates/orders/batch_delete.jinja2",
) )
def batch_delete(context, request): def batch_delete(context, request):
orders = get_multiple_orders(context, request) subnmitted_orders = get_multiple_orders(context, request)
orders = [o for o in subnmitted_orders if not o.in_process]
if not orders: if not orders:
return HTTPFound(request.resource_url(context)) return HTTPFound(request.resource_url(context))

35
tests/functional/conftest.py

@ -147,16 +147,47 @@ def _example_data(_sqlite_repo):
3, 3,
"USD", "USD",
"Toto", "Toto",
"gefunden bei http://www.example.com/foo", "auf der Seite http://www.example.com/foo gefunden",
) )
_sqlite_repo.add_order(order_3) _sqlite_repo.add_order(order_3)
log_entry = models.LogEntry( log_entry = models.LogEntry(
order_3.id, order_3.id,
models.OrderStatus.COMPLETED, models.OrderStatus.OPEN,
user.username, user.username,
today - timedelta(days=3), today - timedelta(days=3),
) )
order_3.add_to_log(log_entry) order_3.add_to_log(log_entry)
log_entry = models.LogEntry(
order_3.id,
models.OrderStatus.COMPLETED,
admin.username,
today - timedelta(days=2),
)
order_3.add_to_log(log_entry)
order_4 = models.OrderItem(
4,
"Spritzen",
"456",
"Sigma Aldrich",
models.OrderCategory.BIOLAB,
"4 St",
4.5,
4,
"EUR",
"",
"",
)
_sqlite_repo.add_order(order_4)
log_entry = models.LogEntry(
order_4.id,
models.OrderStatus.OPEN,
user.username,
today - timedelta(days=4),
)
order_4.add_to_log(log_entry)
_sqlite_repo.session.flush()
@pytest.fixture @pytest.fixture

141
tests/functional/test_a_order.py

@ -0,0 +1,141 @@
def test_add_order(testapp, login_as):
response = testapp.get("/", status=302).follow(status=200)
assert "Please Log In" in response
response = login_as("TestAdmin", "jane").follow(status=200)
assert "My Orders" in response
assert "Eppis" in response
assert "Ethanol" in response
assert "NaCl" in response
assert "Spritzen" in response
assert "Aceton" not in response
response = testapp.get("/orders/add/")
form = response.forms[1]
form["cas_description"] = "Aceton"
form["category"] = "SOLVENT"
form["catalog_nr"] = "567"
form["vendor"] = "Carl Roth"
form["package_size"] = "25 l"
form["quantity"] = "5"
form["account"] = "DFG"
form["comment"] = "Ein Kommentar!"
form.fields["amount"][0].value = "5.67"
form.fields["amount"][1].value = "5.67"
form.fields["currency"][0].value = "USD"
form.fields["currency"][1].value = "USD"
form.submit("Place_Order")
response = testapp.get("/orders/")
assert "My Orders" in response
assert "Eppis" in response
assert "Ethanol" in response
assert "NaCl" in response
assert "Spritzen" in response
assert "Aceton" in response
response = testapp.get("/orders/5/view/")
assert "Aceton" in response
assert "Solvent" in response
assert "567" in response
assert "Carl Roth" in response
assert "25 l" in response
assert "DFG" in response
assert "Ein Kommentar!" in response
assert "5.67" in response
assert "28.35" in response
def test_view_order(testapp, login_as):
response = testapp.get("/", status=302).follow(status=200)
assert "Please Log In" in response
response = login_as("TestAdmin", "jane").follow(status=200)
assert "My Orders" in response
response = testapp.get("/orders/3/view/")
assert "Eppis" in response
assert "345" in response
assert "VWR" in response
assert "Biolab" in response
assert "3 St" in response
assert "34.50" in response
assert "3" in response
assert "USD" in response
assert "103.50" in response
assert "Toto" in response
assert "auf der Seite" in response
assert 'href="http://www.example.com/foo"' in response
assert ">http://www.example.com/foo</a>" in response
assert "open" in response
assert "completed" in response
assert "TestAdmin" in response
assert "TestUser" in response
def test_edit_order_ok(testapp, login_as):
response = testapp.get("/", status=302).follow(status=200)
assert "Please Log In" in response
response = login_as("TestAdmin", "jane").follow(status=200)
assert "My Orders" in response
response = testapp.get("/orders/3/edit/")
form = response.forms[1]
form["cas_description"] = "Aceton"
form["category"] = "SOLVENT"
form["catalog_nr"] = "567"
form["vendor"] = "Carl Roth"
form["package_size"] = "25 l"
form["quantity"] = "5"
form["account"] = "DFG"
form["comment"] = "Ein Kommentar!"
form.fields["amount"][0].value = "5.67"
form.fields["amount"][1].value = "5.67"
form.fields["currency"][0].value = "USD"
form.fields["currency"][1].value = "USD"
form.submit("Save_Changes")
response = testapp.get("/orders/")
assert "My Orders" in response
assert "Eppis" not in response
assert "Ethanol" in response
assert "NaCl" in response
assert "Spritzen" in response
assert "Aceton" in response
response = testapp.get("/orders/3/view/")
assert "Aceton" in response
assert "Solvent" in response
assert "567" in response
assert "Carl Roth" in response
assert "25 l" in response
assert "DFG" in response
assert "Ein Kommentar!" in response
assert "5.67" in response
assert "28.35" in response
def test_delete_order(testapp, login_as):
response = testapp.get("/", status=302).follow(status=200)
assert "Please Log In" in response
response = login_as("TestAdmin", "jane").follow(status=200)
assert "My Orders" in response
assert "Eppis" in response
assert "Ethanol" in response
assert "NaCl" in response
assert "/orders/4/edit" in response
response = testapp.get("/orders/4/delete")
form = response.forms[1]
form["confirmation"].checked = True
form.submit("delete")
response = testapp.get("/orders/")
assert "has been deleted" in response
assert "My Orders" in response
assert "Eppis" in response
assert "Ethanol" in response
assert "NaCl" in response
assert "/orders/4/edit" not in response

125
tests/functional/test_order_list.py

@ -0,0 +1,125 @@
def test_order_list(testapp, login_as):
response = testapp.get("/", status=302).follow(status=200)
assert "Please Log In" in response
response = login_as("TestAdmin", "jane").follow(status=200)
assert "My Orders" in response
assert "Eppis" in response
assert "Ethanol" in response
assert "NaCl" in response
assert "Spritzen" in response
response = testapp.get("/orders?status=completed", status=200)
assert "Eppis" in response
assert "Ethanol" in response
assert "NaCl" not in response
assert "Spritzen" not in response
response = testapp.get("/orders?user=TestAdmin", status=200)
assert "Eppis" not in response
assert "Ethanol" in response
assert "NaCl" in response
assert "Spritzen" not in response
response = testapp.get(
"/orders?user=TestAdmin&status=completed", status=200
)
assert "Eppis" not in response
assert "Ethanol" in response
assert "NaCl" not in response
assert "Spritzen" not in response
response = testapp.get(
"/orders?user=TestAdmin&status=approval", status=200
)
assert "Eppis" not in response
assert "Ethanol" not in response
assert "NaCl" in response
assert "Spritzen" not in response
response = testapp.get("/orders?user=-purchaser-", status=200)
assert "Eppis" in response
assert "Ethanol" in response
assert "NaCl" in response
assert "Spritzen" not in response
response = testapp.get("/orders?search=vwr", status=200)
assert "Eppis" in response
assert "Ethanol" in response
assert "NaCl" not in response
assert "Spritzen" not in response
def test_multi_edit_ok(testapp, login_as):
response = testapp.get("/", status=302).follow(status=200)
assert "Please Log In" in response
response = login_as("TestAdmin", "jane").follow(status=200)
assert "My Orders" in response
form = response.forms[1]
form.action = "/orders/batch-edit/"
select_checkboxes = form.fields["selection"]
select_checkboxes[0].checked = True
select_checkboxes[1].checked = True
response = form.submit()
assert "Eppis" not in response
assert "Ethanol" in response
assert "NaCl" in response
assert "Spritzen" not in response
form = response.forms[1]
form["status-1"].value = "HOLD"
form["status-2"].value = "HOLD"
form.submit("change")
response = testapp.get("/orders?status=completed", status=200)
assert "orders have been updated." in response
assert "Eppis" in response
assert "Ethanol" not in response
assert "NaCl" not in response
assert "Spritzen" not in response
response = testapp.get("/orders?status=open", status=200)
assert "Eppis" not in response
assert "Ethanol" not in response
assert "NaCl" not in response
assert "Spritzen" in response
response = testapp.get("/orders?status=hold", status=200)
assert "Eppis" not in response
assert "Ethanol" in response
assert "NaCl" in response
assert "Spritzen" not in response
def test_multi_delete_ok(testapp, login_as):
response = testapp.get("/", status=302).follow(status=200)
assert "Please Log In" in response
response = login_as("TestAdmin", "jane").follow(status=200)
assert "My Orders" in response
form = response.forms[1]
form.action = "/orders/batch-delete/"
select_checkboxes = form.fields["selection"]
select_checkboxes[0].checked = True
select_checkboxes[3].checked = True
response = form.submit()
assert "Eppis" not in response
assert "Ethanol" not in response
assert "NaCl" not in response
assert "Spritzen" in response
form = response.forms[1]
form["confirmation"].checked = True
form.submit("delete")
response = testapp.get("/orders", status=200)
assert "orders have been deleted." in response
assert "Eppis" in response
assert "Ethanol" in response
assert "NaCl" in response
assert "Spritzen" not in response
Loading…
Cancel
Save