Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests #67

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_get_all_clients():

# Test to retrieve a specific client by ID
def test_get_client_by_id():
client_id = 5 # Replace with a valid ID for your test
client_id = 1 # Replace with a valid ID for your test
response = requests.get(f"{BASE_URL}/{client_id}", headers=headers)
assert response.status_code == 200
client = response.json()
Expand Down
11 changes: 6 additions & 5 deletions Tests/test_item_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_Post():
assert generated_id != 0

# get the same entity that has been posted
get_response = requests.get(BASE_URL + f"/{generated_id}")
get_response = requests.get(BASE_URL + f"/{generated_id}", headers=HEADERS)
json = get_response.json()
assert get_response.status_code == 200
assert json["name"] == VALID_ITEM_GROUP["Name"]
Expand All @@ -39,7 +39,7 @@ def test_Post():
assert "updated_at" in json, "updated_at key was not created"

delete_response = requests.delete(
BASE_URL+f"/{generated_id}")
BASE_URL+f"/{generated_id}", headers=HEADERS)

assert delete_response.status_code == 200

Expand All @@ -62,6 +62,7 @@ def test_put():
generated_id = test_helper.get_integer_from_json_string(json)
assert generated_id != 0
# modify the added item group
UPDATED_ITEM_GROUP["id"] = generated_id
put_response = requests.put(
BASE_URL + f"/{generated_id}", headers=HEADERS, json=UPDATED_ITEM_GROUP)
assert put_response.status_code == 200
Expand All @@ -74,16 +75,16 @@ def test_put_Item_group_that_does_not_exist():


def test_delete():
post_response = requests.post(BASE_URL, json=VALID_ITEM_GROUP)
post_response = requests.post(BASE_URL, json=VALID_ITEM_GROUP, headers=HEADERS)
json = str(post_response.json())
generated_id = test_helper.get_integer_from_json_string(json)
assert generated_id != 0

delete_response = requests.delete(
BASE_URL+f"/{generated_id}")
BASE_URL+f"/{generated_id}", headers=HEADERS)

assert delete_response.status_code == 200

get_response = requests.get(BASE_URL + str(generated_id))
get_response = requests.get(BASE_URL + str(generated_id), headers=HEADERS)
assert get_response.status_code == 404

11 changes: 6 additions & 5 deletions Tests/test_item_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_Post():
assert generated_id != 0

# get the same entity that has been posted
get_response = requests.get(BASE_URL + f"/{generated_id}")
get_response = requests.get(BASE_URL + f"/{generated_id}", headers=HEADERS)
json = get_response.json()
assert get_response.status_code == 200
assert json["name"] == VALID_ITEM_LINE["Name"]
Expand All @@ -39,7 +39,7 @@ def test_Post():
assert "updated_at" in json, "updated_at key was not created"

delete_response = requests.delete(
BASE_URL+f"/{generated_id}")
BASE_URL+f"/{generated_id}", headers=HEADERS)

assert delete_response.status_code == 200

Expand All @@ -62,6 +62,7 @@ def test_put():
generated_id = test_helper.get_integer_from_json_string(json)
assert generated_id != 0
# modify the added item line
UPDATED_ITEM_LINE["id"] = generated_id
put_response = requests.put(
BASE_URL + f"/{generated_id}", headers=HEADERS, json=UPDATED_ITEM_LINE)
assert put_response.status_code == 200
Expand All @@ -74,16 +75,16 @@ def test_put_Item_line_that_does_not_exist():


def test_delete():
post_response = requests.post(BASE_URL, json=VALID_ITEM_LINE)
post_response = requests.post(BASE_URL, json=VALID_ITEM_LINE, headers=HEADERS)
json = str(post_response.json())
generated_id = test_helper.get_integer_from_json_string(json)
assert generated_id != 0

delete_response = requests.delete(
BASE_URL+f"/{generated_id}")
BASE_URL+f"/{generated_id}", headers=HEADERS)

assert delete_response.status_code == 200

get_response = requests.get(BASE_URL + str(generated_id))
get_response = requests.get(BASE_URL + str(generated_id), headers=HEADERS)
assert get_response.status_code == 404

91 changes: 91 additions & 0 deletions Tests/test_item_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import requests
import test_helper


BASE_URL = "http://localhost:3000/api/v2/ItemTypes"

VALID_ITEM_TYPE = {
"Name": "Test Name",
"Description": "Test Description"
}

INVALID_ITEM_TYPE_1 = {}
HEADERS = {"Content-Type": "application/json", 'APIKEY': "4125a7b2-7ef8-4c4f-9ff9-3386c0dbcb5c"}

UPDATED_ITEM_TYPE = {
"id": 1,
"Name": "Updated test name",
"Description": "Updated test description"
}


def test_Post():
# post the test body
post_response = requests.post(
BASE_URL, headers=HEADERS, json=VALID_ITEM_TYPE)
# convert the json response to a string and look for the id of the created Entity
json = str(post_response.json())
# look here for an integer (digit)

generated_id = test_helper.get_integer_from_json_string(json)
assert generated_id != 0

# get the same entity that has been posted
get_response = requests.get(BASE_URL + f"/{generated_id}", headers=HEADERS)
json = get_response.json()
assert get_response.status_code == 200
assert json["name"] == VALID_ITEM_TYPE["Name"]
assert json["description"] == VALID_ITEM_TYPE["Description"]
assert "created_at" in json, "created_at key was not created"
assert "updated_at" in json, "updated_at key was not created"

delete_response = requests.delete(
BASE_URL+f"/{generated_id}", headers=HEADERS)

assert delete_response.status_code == 200


def test_invalid_post():
# post an item TYPE with an empty body
post_response = requests.post(
BASE_URL, headers=HEADERS, json=INVALID_ITEM_TYPE_1)
# the response should return a bad request
assert post_response.status_code == 400


def test_put():
# post an item type
post_response = requests.post(
BASE_URL, headers=HEADERS, json=VALID_ITEM_TYPE)
# convert the json response to a string and look for the id of the created Entity
json = str(post_response.json())
# look here for an integer (digit)
generated_id = test_helper.get_integer_from_json_string(json)
assert generated_id != 0
# modify the added item TYPE
UPDATED_ITEM_TYPE["id"] = generated_id
put_response = requests.put(
BASE_URL + f"/{generated_id}", headers=HEADERS, json=UPDATED_ITEM_TYPE)
assert put_response.status_code == 200
requests.delete(BASE_URL + f"/{generated_id}")


def test_put_Item_type_that_does_not_exist():
put_response = requests.put(
BASE_URL + "999999999999", json=VALID_ITEM_TYPE)
assert put_response.status_code == 404


def test_delete():
post_response = requests.post(BASE_URL, json=VALID_ITEM_TYPE, headers=HEADERS)
json = str(post_response.json())
generated_id = test_helper.get_integer_from_json_string(json)
assert generated_id != 0

delete_response = requests.delete(
BASE_URL+f"/{generated_id}", headers=HEADERS)

assert delete_response.status_code == 200

get_response = requests.get(BASE_URL + str(generated_id), headers=HEADERS)
assert get_response.status_code == 404
45 changes: 45 additions & 0 deletions Tests/test_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import requests
import test_helper


BASE_URL = "http://localhost:3000/api/v2/items"

VALID_ITEM = {
"Name": "Test Name",
"Description": "Test Description"
}

INVALID_ITEM_1 = {}
HEADERS = {"Content-Type": "application/json", 'APIKEY': "4125a7b2-7ef8-4c4f-9ff9-3386c0dbcb5c"}

UPDATED_ITEM = {
"code": "XLE77785i",
"description": "Focused human-resource implementation",
"short_description": "offer",
"upc_code": "7946503676171",
"model_number": "fM-605648-lbu",
"commodity_code": "qB-2533",
"item_line": 1,
"item_group": 1,
"item_type": 1,
"unit_purchase_quantity": 27,
"unit_order_quantity": 20,
"pack_order_quantity": 16,
"supplier_id": 45,
"supplier_code": "SUP127",
"supplier_part_number": "Ay-062669-VVl"
}


def test_invalid_post():
# post an item TYPE with an empty body
post_response = requests.post(
BASE_URL, headers=HEADERS, json=INVALID_ITEM_1)
# the response should return a bad request
assert post_response.status_code == 400


def test_put_Item_that_does_not_exist():
put_response = requests.put(
BASE_URL + "999999999999", json=VALID_ITEM)
assert put_response.status_code == 404
File renamed without changes.
2 changes: 1 addition & 1 deletion Tests/Test_orders.py → Tests/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,4 @@ def test_delete_order(setup_environment):
assert delete_response.status_code == 200, f"Failed to delete order: {delete_response.text}"

get_response = requests.get(f"{BASE_URL}/{order_id}", headers=HEADERS)
assert get_response.status_code == 404, f"Deleted order still exists: {get_response.text}"
assert get_response.status_code == 404, f"Deleted order still exists: {get_response.text}"
File renamed without changes.
30 changes: 0 additions & 30 deletions UnitTest/ItemStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,4 @@ public async Task TestGetItemsForItemGroup()
Assert.AreEqual(2, result.Count);
Assert.IsTrue(result.All(item => item.ItemGroup == 2));
}

[TestMethod]
public async Task TestValidateItems_AllValid()
{
// Arrange
await _dbContext.ItemTypes.AddAsync(TestHelper.TestItemType1WithId);
await _dbContext.ItemGroups.AddAsync(TestHelper.TestItemGroup1WithId);
await _dbContext.ItemLines.AddAsync(TestHelper.TestItemLine1WithId);
await _dbContext.SaveChangesAsync();

// Act
var isValid = await _itemStorageService.ValidateItems(1, 1, 1);

// Assert
Assert.IsTrue(isValid);
}

[TestMethod]
public async Task ValidateItems_False()
{
await _dbContext.ItemTypes.AddAsync(TestHelper.TestItemType1WithId);
await _dbContext.ItemGroups.AddAsync(TestHelper.TestItemGroup1WithId);
await _dbContext.ItemLines.AddAsync(TestHelper.TestItemLine1WithId);
await _dbContext.SaveChangesAsync();

Assert.IsFalse(await _itemStorageService.ValidateItems(1, 1, 2)); //itemLine
Assert.IsFalse(await _itemStorageService.ValidateItems(1, 2, 1)); //itemGroup
Assert.IsFalse(await _itemStorageService.ValidateItems(2, 1, 1)); //itemType
Assert.IsFalse(await _itemStorageService.ValidateItems(2, 2, 2)); //All fail
}
}
Loading