-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'resitAdel' of https://github.com/Adel-Atzouza/CargoHub …
…into resitAdel
- Loading branch information
Showing
8 changed files
with
2,010 additions
and
1,784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
import requests | ||
import test_helper as helper | ||
|
||
ORDERS_URL = "http://localhost:3000/api/v2/orders" | ||
CLIENTS_URL = "http://localhost:3000/api/v2/Clients" | ||
WAREHOUSES_URL = "http://localhost:3000/api/v2/warehouses" | ||
ITEMS_URL = "http://localhost:3000/api/v2/Items" | ||
INVENTORIES_URL = "http://localhost:3000/api/v2/inventories" | ||
LOCATIONS_URL = "http://localhost:3000/api/v2/Locations" | ||
|
||
|
||
HEADERS = {"Content-Type": "application/json", | ||
'APIKEY': "4125a7b2-7ef8-4c4f-9ff9-3386c0dbcb5c"} | ||
TestOrder_1 = { | ||
"source_id": 1, | ||
"order_date": "2024-11-19T13:39:16.5035533Z", | ||
"request_date": "2024-11-19T13:39:16.5035533Z", | ||
"reference": "ORD123", | ||
"reference_extra": "Urgent Delivery", | ||
"order_status": "Delivered", | ||
"notes": "Order notes", | ||
"shipping_notes": "Handle with care", | ||
"picking_notes": "Fragile items", | ||
"warehouse_id": 1, | ||
"ship_to": 1, | ||
"bill_to": 1, | ||
"shipment_id": None, | ||
"total_amount": 200.00, | ||
"total_discount": 10.00, | ||
"total_tax": 5.00, | ||
"total_surcharge": 2.00, | ||
"Items": | ||
[ | ||
{ | ||
"Item_Id": "P000001", | ||
"Amount": 70 | ||
} | ||
|
||
] | ||
|
||
} | ||
|
||
TestClient_1 = { | ||
"id": 1, | ||
"name": "Raymond Inc", | ||
"address": "1296 Daniel Road Apt. 349", | ||
"city": "Pierceview", | ||
"zip_code": "28301", | ||
"province": "Colorado", | ||
"country": "United States", | ||
"contact_name": "Bryan Clark", | ||
"contact_phone": "242.732.3483x2573", | ||
"contact_email": "robertcharles@example.net", | ||
} | ||
|
||
Test_Warehouse_1 = { | ||
"id": 0, | ||
"code": "GIOMNL90", | ||
"name": "Petten longterm hub", | ||
"address": "Owenweg 731", | ||
"zip": "4615 RB", | ||
"city": "Petten", | ||
"province": "Noord-Holland", | ||
"country": "NL", | ||
"contact": { | ||
"name": "Maud Adryaens", | ||
"phone": "+31836 752702", | ||
"email": "nickteunissen@example.com" | ||
}, | ||
} | ||
|
||
Test_Item_1 = { | ||
"code": "ABC123", | ||
"description": "Sample item", | ||
"short_description": "Sample short description", | ||
"upc_code": "123456789", | ||
"model_number": "XYZ123", | ||
"commodity_code": "A123", | ||
"item_line": 2, | ||
"item_group": 2, | ||
"item_type": 2, | ||
"unit_purchase_quantity": 10, | ||
"unit_order_quantity": 5, | ||
"pack_order_quantity": 5, | ||
"supplier_id": 1, | ||
"supplier_code": "SUP123", | ||
"supplier_part_number": "PART123", | ||
} | ||
Test_Inventory_1 = { | ||
"item_Id": "", | ||
"description": "RandomDescription", | ||
"item_Reference": "REF456", | ||
"locations": [ | ||
], | ||
"total_on_Hand": 500, | ||
"total_Expected": 0, | ||
"total_Ordered": 0, | ||
"total_Allocated": 0, | ||
"total_Available": 500, | ||
} | ||
|
||
Test_Location_1 = { | ||
"Warehouse_id": 0, | ||
"Code": "LOC001", | ||
"Name": "Main Storage" | ||
} | ||
|
||
|
||
def Post_test_order(): | ||
response = requests.post( | ||
ORDERS_URL, headers=HEADERS, json=TestOrder_1) | ||
return response.status_code | ||
|
||
|
||
def post_test_warehouse(): | ||
response = requests.post( | ||
WAREHOUSES_URL, headers=HEADERS, json=Test_Warehouse_1) | ||
json = str(response.json()) | ||
generated_id = helper.get_integer_from_json_string(json) | ||
return generated_id | ||
|
||
|
||
def post_test_client(): | ||
response = requests.post( | ||
CLIENTS_URL, headers=HEADERS, json=TestClient_1) | ||
json = str(response.json()) | ||
generated_id = helper.get_integer_from_json_string(json) | ||
return generated_id | ||
|
||
|
||
def post_test_item(): | ||
response = requests.post(ITEMS_URL, headers=HEADERS, json=Test_Item_1) | ||
# the response is the generated item uid | ||
return response.text | ||
|
||
|
||
def post_test_location(warehouse_id): | ||
Test_Location_1["Warehouse_id"] = warehouse_id | ||
|
||
response = requests.post( | ||
LOCATIONS_URL, headers=HEADERS, json=Test_Location_1) | ||
json = str(response.json()) | ||
generated_id = helper.get_integer_from_json_string(json) | ||
return generated_id | ||
|
||
|
||
def post_test_inventory(item_uid, location_id): | ||
Test_Inventory_1["locations"].append(location_id) | ||
Test_Inventory_1["item_Id"] = item_uid | ||
|
||
response = requests.post( | ||
INVENTORIES_URL, headers=HEADERS, json=Test_Inventory_1) | ||
json = str(response.json()) | ||
generated_id = helper.get_integer_from_json_string(json) | ||
return generated_id | ||
|
||
## This test checks if the api requires valid: items, inventories, locations, warehouses and clients in order to create an order | ||
def test_order_requires_dependencies(): | ||
# test adding an order with clients that don't exist in the database | ||
post_order_without_clients = Post_test_order() | ||
|
||
assert post_order_without_clients == 400 | ||
|
||
# Add a client and then try to add Order | ||
generated_id_for_client = post_test_client() | ||
|
||
# assign the client to the test_order | ||
TestOrder_1["bill_to"] = generated_id_for_client | ||
TestOrder_1["ship_to"] = generated_id_for_client | ||
# try to add the order again | ||
post_order_without_warehouse = Post_test_order() | ||
|
||
# the response should still be 400 because warehouse doesn't exist | ||
assert post_order_without_warehouse == 400 | ||
|
||
# add a warehouse and then try to add Order | ||
generated_id_for_warehouse = post_test_warehouse() | ||
|
||
# assign the warehouse to the test_order | ||
TestOrder_1["warehouse_id"] = generated_id_for_warehouse | ||
|
||
# add an item with its inventory and location to the database and assign that item to the order | ||
generated_id_for_location = post_test_location(generated_id_for_warehouse) | ||
generated_id_for_item = post_test_item() | ||
|
||
post_test_inventory(generated_id_for_item, generated_id_for_location) | ||
|
||
TestOrder_1["Items"] = [{ | ||
"Item_Id": generated_id_for_item, | ||
"Amount": 200 | ||
}] | ||
|
||
## check that you can't add an order with a delivered status (status should be pending) | ||
assert Post_test_order() == 400 | ||
|
||
## assert that the order has been added succesfully | ||
TestOrder_1["order_status"] = "Pending" | ||
assert Post_test_order() == 201 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
namespace CargoHub.Test; | ||
|
||
[TestClass] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[TestClass] | ||
public class OrderStorageServiceTest | ||
{ | ||
private AppDbContext appDbContext; | ||
private OrderStorageService _service; | ||
[TestInitialize] | ||
public void SetUp() | ||
{ | ||
var options = new DbContextOptionsBuilder<AppDbContext>() | ||
.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) | ||
.Options; | ||
|
||
appDbContext = new AppDbContext(options); | ||
|
||
_service = new OrderStorageService(appDbContext); | ||
} | ||
|
||
[TestMethod] | ||
public void OrderStorageService_Create() | ||
{ | ||
|
||
} | ||
} |
Oops, something went wrong.