From 2876c7f4825bf40108a3c7842e5840fe3352589e Mon Sep 17 00:00:00 2001 From: mark-175 <152170112+mark-175@users.noreply.github.com> Date: Mon, 20 Jan 2025 13:06:32 +0100 Subject: [PATCH 1/4] ..... --- CargoHub/Models/Location.cs | 2 ++ CargoHub/Models/Order.cs | 1 + CargoHub/Models/Supplier.cs | 20 +++++++++++--------- CargoHub/Models/Warehouse.cs | 4 +++- CargoHub/Services/ClassificationService.cs | 3 +-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CargoHub/Models/Location.cs b/CargoHub/Models/Location.cs index db8a314..a8544b2 100644 --- a/CargoHub/Models/Location.cs +++ b/CargoHub/Models/Location.cs @@ -12,5 +12,7 @@ public class Location : BaseModel, IContainsClassification public ICollection Inventories { get; } = []; public required string Code { get; set; } public required string Name { get; set; } + [JsonIgnore] + public List Classifications { get; set; } = []; } } diff --git a/CargoHub/Models/Order.cs b/CargoHub/Models/Order.cs index c94288f..717e9e1 100644 --- a/CargoHub/Models/Order.cs +++ b/CargoHub/Models/Order.cs @@ -35,6 +35,7 @@ public class Order : BaseModel, IContainsClassification // Avoid serializing the OrderItems navigation property public List? OrderItems { get; set; } = new List(); + [JsonIgnore] public List Classifications { get; set; } = []; } diff --git a/CargoHub/Models/Supplier.cs b/CargoHub/Models/Supplier.cs index 1f25e85..55c7c07 100644 --- a/CargoHub/Models/Supplier.cs +++ b/CargoHub/Models/Supplier.cs @@ -4,19 +4,21 @@ namespace CargoHub.Models { public class Supplier : BaseModel, IContainsClassification { - public required string Code {get; set;} - public required string Name {get; set;} - public required string Address {get; set;} + public required string Code { get; set; } + public required string Name { get; set; } + public required string Address { get; set; } [JsonPropertyName("address_extra")] public required string AddressExtra { get; set; } public required string City { get; set; } [JsonPropertyName("zip_code")] - public required string ZipCode {get; set;} - public required string Province {get; set;} - public required string Country {get; set;} + public required string ZipCode { get; set; } + public required string Province { get; set; } + public required string Country { get; set; } [JsonPropertyName("contact_name")] - public required string ContactName {get; set;} - public required string Phonenumber {get; set;} - public required string Reference {get; set;} + public required string ContactName { get; set; } + public required string Phonenumber { get; set; } + public required string Reference { get; set; } + [JsonIgnore] + public List Classifications { get; set; } = []; } } diff --git a/CargoHub/Models/Warehouse.cs b/CargoHub/Models/Warehouse.cs index 9bcf376..27cd952 100644 --- a/CargoHub/Models/Warehouse.cs +++ b/CargoHub/Models/Warehouse.cs @@ -45,6 +45,8 @@ public class Warehouse : BaseModel, IContainsClassification } [JsonIgnore] - public ICollection Locations { get; } = []; + public ICollection Locations { get; } = []; + [JsonIgnore] + public List Classifications { get; set; } = []; } } diff --git a/CargoHub/Services/ClassificationService.cs b/CargoHub/Services/ClassificationService.cs index fccebb0..18000b2 100644 --- a/CargoHub/Services/ClassificationService.cs +++ b/CargoHub/Services/ClassificationService.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore; namespace CargoHub.Services { - public class ClassificationService : BaseStorageService + public class ClassificationService : BaseStorageService { private readonly AppDbContext _context; @@ -26,7 +26,6 @@ public async Task AssignClassificationToEntity(int Id, int Classificati try { Entity.Classifications.Add(FoundClassification); - // appDbContext.Set().Add(Entity); int rowsChanged = await appDbContext.SaveChangesAsync(); return rowsChanged > 0; } From 9dd5f07d17a318b76a61ec113cb8d7e51027c4cd Mon Sep 17 00:00:00 2001 From: mark-175 <152170112+mark-175@users.noreply.github.com> Date: Mon, 20 Jan 2025 15:12:59 +0100 Subject: [PATCH 2/4] JsonPropertyName attribute fixed --- CargoHub/LogTransferData.csv | 13 ------- CargoHub/Models/Client.cs | 27 +++++++++----- CargoHub/Models/Inventory.cs | 21 ++++++----- CargoHub/Models/Item.cs | 18 ++++----- CargoHub/Models/ItemGroup.cs | 7 +++- CargoHub/Models/ItemLine.cs | 8 +++- CargoHub/Models/ItemType.cs | 8 +++- CargoHub/Models/Location.cs | 8 +++- CargoHub/Models/Supplier.cs | 37 +++++++++++++------ CargoHub/Models/Transfer.cs | 10 +++-- CargoHub/Models/TransferData.cs | 8 ++-- CargoHub/Models/Warehouse.cs | 35 +++++++++++++----- CargoHub/Services/APIKeyService.cs | 12 ++++++ CargoHub/Services/AuthorizationFilter.cs | 39 ++++++++++++++++++++ CargoHub/Services/InventoryStorageService.cs | 10 ++--- 15 files changed, 178 insertions(+), 83 deletions(-) delete mode 100644 CargoHub/LogTransferData.csv create mode 100644 CargoHub/Services/AuthorizationFilter.cs diff --git a/CargoHub/LogTransferData.csv b/CargoHub/LogTransferData.csv deleted file mode 100644 index dd1d92b..0000000 --- a/CargoHub/LogTransferData.csv +++ /dev/null @@ -1,13 +0,0 @@ -File,DateOfTransfer,RowsChanged,TransferTime,Error -../data\clients.json,18-01-25,9820,00:00:02, -../data\inventories.json,18-01-25,11720,00:00:04, -../data\items.json,18-01-25,11720,00:00:08, -../data\item_groups.json,18-01-25,100,00:00:08, -../data\item_lines.json,18-01-25,97,00:00:08, -../data\item_types.json,18-01-25,100,00:00:08, -../data\locations.json,18-01-25,34533,00:00:13, -../data\orders.json,18-01-25,0,00:00:14,Error: The entity type 'JsonOrder' was not found. Ensure that the entity type has been added to the model. -../data\shipments.json,18-01-25,0,00:00:14,Error: The entity type 'JsonShipment' was not found. Ensure that the entity type has been added to the model. -../data\suppliers.json,18-01-25,497,00:00:14, -../data\transfers.json,18-01-25,119240,00:00:39, -../data\warehouses.json,18-01-25,58,00:00:39, diff --git a/CargoHub/Models/Client.cs b/CargoHub/Models/Client.cs index 5cf3b00..b96358d 100644 --- a/CargoHub/Models/Client.cs +++ b/CargoHub/Models/Client.cs @@ -4,18 +4,27 @@ namespace CargoHub.Models { public class Client : BaseModel { - public required string Name { get; set; } - public required string Address { get; set; } - public required string City { get; set; } + [JsonPropertyName("name")] + public required string? Name { get; set; } + [JsonPropertyName("address")] + + public required string? Address { get; set; } + [JsonPropertyName("city")] + + public required string? City { get; set; } [JsonPropertyName("zip_code")] - public required string ZipCode { get; set; } - public required string Province { get; set; } - public required string Country { get; set; } + public required string? ZipCode { get; set; } + [JsonPropertyName("province")] + + public required string? Province { get; set; } + [JsonPropertyName("country")] + + public required string? Country { get; set; } [JsonPropertyName("contact_name")] - public required string ContactName { get; set; } + public required string? ContactName { get; set; } [JsonPropertyName("contact_phone")] - public required string ContactPhone { get; set; } + public required string? ContactPhone { get; set; } [JsonPropertyName("contact_email")] - public required string ContactEmail { get; set; } + public required string? ContactEmail { get; set; } } } diff --git a/CargoHub/Models/Inventory.cs b/CargoHub/Models/Inventory.cs index 528fec3..061d8b7 100644 --- a/CargoHub/Models/Inventory.cs +++ b/CargoHub/Models/Inventory.cs @@ -10,31 +10,32 @@ public class Inventory : BaseModel { [JsonPropertyName("item_id")] - public required string ItemId { get; set; } - - public required string Description { get; set; } + public required string? ItemId { get; set; } + [JsonPropertyName("description")] + + public required string? Description { get; set; } [JsonPropertyName("item_reference")] - public required string ItemReference { get; set; } + public required string? ItemReference { get; set; } [JsonPropertyName("locations")] [NotMapped] - public required List LocationIds { get; set; } = []; + public required List LocationIds { get; set; } = []; [JsonIgnore] public ICollection Locations { get; set; } = []; [JsonPropertyName("total_on_hand")] - public required int TotalOnHand { get; set; } + public required int? TotalOnHand { get; set; } [JsonPropertyName("total_expected")] - public required int TotalExpected { get; set; } + public required int? TotalExpected { get; set; } [JsonPropertyName("total_ordered")] - public required int TotalOrdered { get; set; } + public required int? TotalOrdered { get; set; } [JsonPropertyName("total_allocated")] - public required int TotalAllocated { get; set; } + public required int? TotalAllocated { get; set; } [JsonPropertyName("total_available")] - public required int TotalAvailable { get; set; } + public required int? TotalAvailable { get; set; } } } diff --git a/CargoHub/Models/Item.cs b/CargoHub/Models/Item.cs index 0e687cd..8832dab 100644 --- a/CargoHub/Models/Item.cs +++ b/CargoHub/Models/Item.cs @@ -14,24 +14,24 @@ public class Item : BaseModel, IContainsClassification [Key] [JsonPropertyName("uid")] - public string Uid { get; set; } = string.Empty; + public string? Uid { get; set; } = string.Empty; [JsonPropertyName("code")] - public required string Code { get; set; } + public required string? Code { get; set; } [JsonPropertyName("description")] - public required string Description { get; set; } + public required string? Description { get; set; } [JsonPropertyName("short_description")] - public required string ShortDescription { get; set; } + public required string? ShortDescription { get; set; } [JsonPropertyName("upc_code")] - public required string UpcCode { get; set; } + public required string? UpcCode { get; set; } [JsonPropertyName("model_number")] - public required string ModelNumber { get; set; } + public required string? ModelNumber { get; set; } [JsonPropertyName("commodity_code")] - public required string CommodityCode { get; set; } + public required string? CommodityCode { get; set; } [JsonPropertyName("item_line")] public required int ItemLine { get; set; } @@ -55,10 +55,10 @@ public class Item : BaseModel, IContainsClassification public required int SupplierId { get; set; } [JsonPropertyName("supplier_code")] - public required string SupplierCode { get; set; } + public required string? SupplierCode { get; set; } [JsonPropertyName("supplier_part_number")] - public required string SupplierPartNumber { get; set; } + public required string? SupplierPartNumber { get; set; } [JsonIgnore] public List Classifications { get; set; } = []; diff --git a/CargoHub/Models/ItemGroup.cs b/CargoHub/Models/ItemGroup.cs index ea6041d..6c455db 100644 --- a/CargoHub/Models/ItemGroup.cs +++ b/CargoHub/Models/ItemGroup.cs @@ -5,7 +5,10 @@ namespace CargoHub.Models { public class ItemGroup : BaseModel { - public required string Name {get;set;} - public required string Description {get;set;} + [JsonPropertyName("name")] + public required string? Name {get;set;} + [JsonPropertyName("description")] + + public required string? Description {get;set;} } } diff --git a/CargoHub/Models/ItemLine.cs b/CargoHub/Models/ItemLine.cs index e29531b..68d4c9b 100644 --- a/CargoHub/Models/ItemLine.cs +++ b/CargoHub/Models/ItemLine.cs @@ -5,7 +5,11 @@ namespace CargoHub.Models { public class ItemLine : BaseModel { - public required string Name {get;set;} - public required string Description {get;set;} + [JsonPropertyName("name")] + + public required string? Name {get;set;} + [JsonPropertyName("description")] + + public required string? Description {get;set;} } } diff --git a/CargoHub/Models/ItemType.cs b/CargoHub/Models/ItemType.cs index 2dc8fa4..56e9460 100644 --- a/CargoHub/Models/ItemType.cs +++ b/CargoHub/Models/ItemType.cs @@ -5,8 +5,12 @@ namespace CargoHub.Models public class ItemType : BaseModel { - public required string Name {get;set;} - public required string Description {get;set;} + [JsonPropertyName("name")] + + public required string? Name {get;set;} + [JsonPropertyName("description")] + + public required string? Description {get;set;} } } diff --git a/CargoHub/Models/Location.cs b/CargoHub/Models/Location.cs index a8544b2..2a71a6d 100644 --- a/CargoHub/Models/Location.cs +++ b/CargoHub/Models/Location.cs @@ -10,8 +10,12 @@ public class Location : BaseModel, IContainsClassification public Warehouse? Warehouse { get; set; } [JsonIgnore] public ICollection Inventories { get; } = []; - public required string Code { get; set; } - public required string Name { get; set; } + [JsonPropertyName("code")] + + public required string? Code { get; set; } + [JsonPropertyName("name")] + + public required string? Name { get; set; } [JsonIgnore] public List Classifications { get; set; } = []; } diff --git a/CargoHub/Models/Supplier.cs b/CargoHub/Models/Supplier.cs index 55c7c07..f7e39f9 100644 --- a/CargoHub/Models/Supplier.cs +++ b/CargoHub/Models/Supplier.cs @@ -4,20 +4,35 @@ namespace CargoHub.Models { public class Supplier : BaseModel, IContainsClassification { - public required string Code { get; set; } - public required string Name { get; set; } - public required string Address { get; set; } + [JsonPropertyName("code")] + + public required string? Code { get; set; } + [JsonPropertyName("name")] + + public required string? Name { get; set; } + [JsonPropertyName("address")] + + public required string? Address { get; set; } [JsonPropertyName("address_extra")] - public required string AddressExtra { get; set; } - public required string City { get; set; } + public required string? AddressExtra { get; set; } + [JsonPropertyName("city")] + public required string? City { get; set; } [JsonPropertyName("zip_code")] - public required string ZipCode { get; set; } - public required string Province { get; set; } - public required string Country { get; set; } + public required string? ZipCode { get; set; } + [JsonPropertyName("province")] + + public required string? Province { get; set; } + [JsonPropertyName("country")] + + public required string? Country { get; set; } [JsonPropertyName("contact_name")] - public required string ContactName { get; set; } - public required string Phonenumber { get; set; } - public required string Reference { get; set; } + public required string? ContactName { get; set; } + [JsonPropertyName("phonenumber")] + + public required string? Phonenumber { get; set; } + [JsonPropertyName("reference")] + + public required string? Reference { get; set; } [JsonIgnore] public List Classifications { get; set; } = []; } diff --git a/CargoHub/Models/Transfer.cs b/CargoHub/Models/Transfer.cs index d40d899..f47dc32 100644 --- a/CargoHub/Models/Transfer.cs +++ b/CargoHub/Models/Transfer.cs @@ -7,13 +7,15 @@ namespace CargoHub.Models { public class Transfer : BaseModel, IContainsClassification { - public required string Reference { get; set; } + [JsonPropertyName("reference")] + + public required string? Reference { get; set; } [JsonPropertyName("transfer_from")] - public required int TransferFrom { get; set; } + public required int? TransferFrom { get; set; } [JsonPropertyName("transfer_to")] - public required int TransferTo { get; set; } + public required int? TransferTo { get; set; } [JsonPropertyName("transfer_status")] - public required string TransferStatus { get; set; } + public required string? TransferStatus { get; set; } // Items list for JSON serialization/deserialization [NotMapped] diff --git a/CargoHub/Models/TransferData.cs b/CargoHub/Models/TransferData.cs index 2453d6f..549f89a 100644 --- a/CargoHub/Models/TransferData.cs +++ b/CargoHub/Models/TransferData.cs @@ -3,11 +3,11 @@ namespace CargoHub.Models public class TransferData { - public string File { get; set; } - public string DateOfTransfer { get; set; } + public string? File { get; set; } + public string? DateOfTransfer { get; set; } public int RowsChanged { get; set; } - public string TransferTime { get; set; } - public string Error { get; set; } + public string? TransferTime { get; set; } + public string? Error { get; set; } public TransferData(string file, string dateOfTransfer, int rows, string transferTime, string error) { diff --git a/CargoHub/Models/Warehouse.cs b/CargoHub/Models/Warehouse.cs index 27cd952..3d0a22d 100644 --- a/CargoHub/Models/Warehouse.cs +++ b/CargoHub/Models/Warehouse.cs @@ -5,21 +5,36 @@ namespace CargoHub.Models { public class Warehouse : BaseModel, IContainsClassification { - public required string Code { get; set; } - public required string Name { get; set; } - public required string Address { get; set; } - public required string Zip { get; set; } - public required string City { get; set; } - public required string Province { get; set; } - public required string Country { get; set; } + [JsonPropertyName("code")] + + public required string? Code { get; set; } + [JsonPropertyName("name")] + + public required string? Name { get; set; } + [JsonPropertyName("address")] + + public required string? Address { get; set; } + [JsonPropertyName("zip")] + + public required string? Zip { get; set; } + [JsonPropertyName("city")] + + public required string? City { get; set; } + [JsonPropertyName("province")] + + public required string? Province { get; set; } + [JsonPropertyName("country")] + + public required string? Country { get; set; } + [JsonIgnore] - public string ContactName { get; set; } = string.Empty; + public string? ContactName { get; set; } = string.Empty; [JsonIgnore] - public string ContactPhone { get; set; } = string.Empty; + public string? ContactPhone { get; set; } = string.Empty; [JsonIgnore] - public string ContactEmail { get; set; } = string.Empty; + public string? ContactEmail { get; set; } = string.Empty; [NotMapped] // Contact dictionary for JSON serialization/deserialization diff --git a/CargoHub/Services/APIKeyService.cs b/CargoHub/Services/APIKeyService.cs index 30a3cf6..2855051 100644 --- a/CargoHub/Services/APIKeyService.cs +++ b/CargoHub/Services/APIKeyService.cs @@ -3,6 +3,8 @@ using System.Text; using CargoHub.Enums; using CargoHub.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace CargoHub.Services { @@ -39,5 +41,15 @@ public bool VerifyApiKey(string rawApiKey) return apiKey != null; // Return true if a match is found } + + public async Task GetRoleForApiKey(string ApiKey) + { + APIKey? key = await _context.APIKeys.FirstOrDefaultAsync(key => key.HashedApiKey == HashString(ApiKey)); + if (key != null) + { + return key.UserRole; + } + return null; + } } } diff --git a/CargoHub/Services/AuthorizationFilter.cs b/CargoHub/Services/AuthorizationFilter.cs new file mode 100644 index 0000000..88fd26b --- /dev/null +++ b/CargoHub/Services/AuthorizationFilter.cs @@ -0,0 +1,39 @@ + +// using CargoHub.Enums; +// using Microsoft.AspNetCore.Mvc.Filters; + +// namespace CargoHub.Services +// { +// public class AuthorizationFilter : Attribute, IAsyncActionFilter +// { +// private readonly Dictionary> _roles = new Dictionary>(){ +// {RolesEnum.Roles.WarehouseManager, new List(){"api/v2/ItemGroups","api/v2/ItemLines", "api/v2/Warehouses", "api/v2/Locations", "api/v2/ItemTypes", "api/v2/Transfer", "api/v2/Classifications"}}, +// {RolesEnum.Roles.FloorManager, new List(){ "api/v2/[Controller]", "", "",}} +// }; +// public async Task OnActionExecutionAsync(ActionExecutingContext _context, ActionExecutionDelegate next) +// { +// RolesEnum.Roles[] ApiRoles = [] +// var context = _context.HttpContext; +// string? ApiKey = context.Request.Headers["ApiKey"].FirstOrDefault(); +// if (ApiKey == null) +// { +// context.Response.StatusCode = 401; +// context.Response.ContentType = "text/plain"; +// await context.Response.WriteAsync("Unauthorized: API key is missing."); +// return; +// } +// var apiKeyService = context.RequestServices.GetService(); +// bool KeyExists = apiKeyService.VerifyApiKey(ApiKey); +// if (!KeyExists) +// { +// context.Response.StatusCode = 401; +// context.Response.ContentType = "text/plain"; +// await context.Response.WriteAsync("Unknown or inactive Api key"); +// } +// RolesEnum.Roles? UserRole = await apiKeyService.GetRoleForApiKey(ApiKey); +// UserRole. + + +// } +// } +// } \ No newline at end of file diff --git a/CargoHub/Services/InventoryStorageService.cs b/CargoHub/Services/InventoryStorageService.cs index 474a88b..0694a89 100644 --- a/CargoHub/Services/InventoryStorageService.cs +++ b/CargoHub/Services/InventoryStorageService.cs @@ -15,9 +15,9 @@ public async Task> GetInventoriesForItem(string itemId) .ToListAsync(); } - public async Task> GetInventoryTotalsForItem(string itemId) + public async Task> GetInventoryTotalsForItem(string itemId) { - Dictionary result = new() + Dictionary result = new() { {"total_expected", 0}, {"total_ordered", 0}, @@ -28,7 +28,7 @@ public async Task> GetInventoryTotalsForItem(string item var inventories = await appDbContext.Inventory .Where(inventory => inventory.ItemId == itemId) .ToListAsync(); - + foreach (var inventory in inventories) { result["total_expected"] += inventory.TotalExpected; @@ -42,7 +42,7 @@ public async Task> GetInventoryTotalsForItem(string item // Note: total_onhand is not included in models/inventories.py. Question for jurn. } - public async Task LocationsNotExist(List ids) + public async Task LocationsNotExist(List ids) { string error = "Error: No locations found for id(s): "; bool errorBool = false; @@ -57,7 +57,7 @@ public async Task> GetInventoryTotalsForItem(string item return errorBool ? error : null; } - public async Task AddLocationsToInventory(int iid, List ids) + public async Task AddLocationsToInventory(int iid, List ids) { var inventory = await base.GetRow(iid); From 4ba20ffe87225380e17d1cd1482668e01dcbdc9f Mon Sep 17 00:00:00 2001 From: mark-175 <152170112+mark-175@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:08:21 +0100 Subject: [PATCH 3/4] uni tests work --- UnitTest/ItemGroupServiceTest.cs | 284 ++++++++++++++++--------------- UnitTest/ItemLinesServiceTest.cs | 268 ++++++++++++++--------------- UnitTest/TestHelper.cs | 5 +- UnitTest/Test_OrdersU.cs | 24 +-- 4 files changed, 290 insertions(+), 291 deletions(-) diff --git a/UnitTest/ItemGroupServiceTest.cs b/UnitTest/ItemGroupServiceTest.cs index 45361aa..a7b10ec 100644 --- a/UnitTest/ItemGroupServiceTest.cs +++ b/UnitTest/ItemGroupServiceTest.cs @@ -1,139 +1,145 @@ -// using Microsoft.AspNetCore.Http.Features; -// namespace CargoHub.Test; - -// // note: in-memory database is used because it's faster than an actual database -// // TestSetup() : is used to setup the in-memory database before each test so the tests don't effect each other -// // TestCleanup() : is used to delete the in-memory database so - -// [TestClass] -// public class TestItemGroupsService -// { -// private AppDbContext _context; -// private BaseStorageService _service; -// [TestInitialize] -// public void Setup() -// { -// var options = new DbContextOptionsBuilder() -// .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) -// .Options; - -// _context = new AppDbContext(options); - -// _service = new BaseStorageService(_context); -// } -// [TestMethod] -// public async Task TestPostItemGroup() -// { -// // Try adding an item group with a value of null -// ItemGroup? NullItemGroup = null; -// int? NullResult = await _service.AddRow(NullItemGroup); -// Assert.IsNull(NullResult); - -// // Try to add a test item group -// ItemGroup Ig = TestHelper.TestItemGroup1; -// int? result = await _service.AddRow(Ig); - -// // Get the added Item Group and check the properties -// ItemGroup? FoundIg = await _context.ItemGroups.FindAsync(result); -// Assert.IsNotNull(FoundIg); -// Assert.IsNotNull(FoundIg.CreatedAt); -// Assert.IsNotNull(FoundIg.UpdatedAt); -// Assert.AreEqual(Ig.Name, FoundIg.Name); - - -// } -// [TestMethod] -// public async Task TesGetItemGroup() -// { -// // Add an Item Group using DBcontext -// ItemGroup Ig = TestHelper.TestItemGroup1; -// await _context.ItemGroups.AddAsync(Ig); -// await _context.SaveChangesAsync(); - -// // Check if the properties are returned correctly -// ItemGroup? result = await _service.GetRow(1); -// Assert.IsNotNull(result); -// Assert.AreEqual(Ig.Name, result.Name); -// Assert.AreEqual(Ig.Description, result.Description); - - -// } - -// [TestMethod] -// public async Task TestUpdateItemGroup() -// { -// // Add an item group object to the db -// ItemGroup Ig = TestHelper.TestItemGroup1; -// await _context.ItemGroups.AddAsync(Ig); -// await _context.SaveChangesAsync(); - -// // Update the inserted item group -// ItemGroup UpdatedIg = TestHelper.TestItemGroup2; -// bool result = await _service.UpdateRow(Ig.Id, UpdatedIg); -// Assert.IsTrue(result); -// Assert.IsTrue(Ig.UpdatedAt > Ig.CreatedAt); -// } - -// [TestMethod] -// public async Task TestUpdateInvalidItemGroup() -// { -// // try to update an ItemGroup that doesn't exist -// ItemGroup UpdatedIg = TestHelper.TestItemGroup2; -// bool Result1 = await _service.UpdateRow(999, UpdatedIg); -// Assert.IsFalse(Result1); - -// // Add an ItemGroup to the DB -// ItemGroup Ig = TestHelper.TestItemGroup1; -// await _context.ItemGroups.AddAsync(Ig); -// await _context.SaveChangesAsync(); - -// // Test Updating the item group -// bool result = await _service.UpdateRow(Ig.Id, UpdatedIg); -// Assert.IsTrue(result); - -// } - -// [TestMethod] -// public async Task TestDeleteItemGroup() -// { -// // try deleting an entity that doesn't exist -// bool Result1 = await _service.DeleteRow(1); -// Assert.IsFalse(Result1); - -// ItemGroup Ig = TestHelper.TestItemGroup1; -// await _context.ItemGroups.AddAsync(Ig); -// await _context.SaveChangesAsync(); -// bool Result2 = await _service.DeleteRow(1); -// Assert.IsTrue(Result2); -// } - -// [TestMethod] -// public async Task TestGetAll() -// { -// // Add a couple hundred pages to test the paganation -// for (int i = 0; i < 300; i++) -// { -// ItemGroup Random_IG = TestHelper.CreateRandomItemGroup(); -// await _context.ItemGroups.AddAsync(Random_IG); -// } -// await _context.SaveChangesAsync(); - -// // try to get the first page with size 100 (including 100 x ItemGroup) -// List ItemGroups = await _service.GetAllRows(1, 100); -// Assert.AreEqual(ItemGroups[0].Id, 1); -// Assert.AreEqual(ItemGroups.Last().Id, 100); -// Assert.IsTrue(ItemGroups.All(Ig => Ig.Id <= 100)); - -// // try to get the second Page with size 150 - - - - -// } -// [TestCleanup] -// public void Cleanup() -// { -// _context.Database.EnsureDeleted(); -// _context.Dispose(); -// } -// } \ No newline at end of file +using Microsoft.AspNetCore.Http.Features; +namespace CargoHub.Test; + +// note: in-memory database is used because it's faster than an actual database +// TestSetup() : is used to setup the in-memory database before each test so the tests don't effect each other +// TestCleanup() : is used to delete the in-memory database so + +[TestClass] +public class TestItemGroupsService +{ + private AppDbContext _context; + private BaseStorageService _service; + [TestInitialize] + public void Setup() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) + .Options; + + _context = new AppDbContext(options); + + _service = new BaseStorageService(_context); + } + [TestMethod] + public async Task TestPostItemGroup() + { + // Try adding an item group with a value of null + ItemGroup? NullItemGroup = null; + int? NullResult = await _service.AddRow(NullItemGroup); + Assert.IsNull(NullResult); + + // Try to add a test item group + ItemGroup Ig = TestHelper.TestItemGroup1; + int? result = await _service.AddRow(Ig); + + // Get the added Item Group and check the properties + ItemGroup? FoundIg = await _context.ItemGroups.FindAsync(result); + Assert.IsNotNull(FoundIg); + Assert.IsNotNull(FoundIg.CreatedAt); + Assert.IsNotNull(FoundIg.UpdatedAt); + Assert.AreEqual(Ig.Name, FoundIg.Name); + + + } + [TestMethod] + public async Task TesGetItemGroup() + { + // Add an Item Group using DBcontext + ItemGroup Ig = TestHelper.TestItemGroup1; + await _context.ItemGroups.AddAsync(Ig); + await _context.SaveChangesAsync(); + + // Check if the properties are returned correctly + ItemGroup? result = await _service.GetRow(1); + Assert.IsNotNull(result); + Assert.AreEqual(Ig.Name, result.Name); + Assert.AreEqual(Ig.Description, result.Description); + + + } + + [TestMethod] + public async Task TestUpdateItemGroup() + { + // Add an item group object to the db + ItemGroup Ig = TestHelper.TestItemGroup1; + await _context.ItemGroups.AddAsync(Ig); + await _context.SaveChangesAsync(); + + // Update the inserted item group + ItemGroup UpdatedIg = TestHelper.UpdatedItemGroup; + bool result = await _service.UpdateRow(Ig.Id, UpdatedIg); + Assert.IsTrue(result); + Assert.IsTrue(Ig.UpdatedAt > Ig.CreatedAt); + } + + [TestMethod] + public async Task TestUpdateInvalidItemGroup() + { + // try to update an ItemGroup that doesn't exist + ItemGroup UpdatedIg = TestHelper.UpdatedItemGroup; + bool Result1 = await _service.UpdateRow(999, UpdatedIg); + Assert.IsFalse(Result1); + + // Add an ItemGroup to the DB + ItemGroup Ig = TestHelper.TestItemGroup1; + await _context.ItemGroups.AddAsync(Ig); + await _context.SaveChangesAsync(); + + // Test Updating the item group + bool result = await _service.UpdateRow(Ig.Id, UpdatedIg); + Assert.IsTrue(result); + + } + + [TestMethod] + public async Task TestDeleteItemGroup() + { + // try deleting an entity that doesn't exist + bool Result1 = await _service.DeleteRow(1); + Assert.IsFalse(Result1); + + ItemGroup Ig = TestHelper.TestItemGroup1; + await _context.ItemGroups.AddAsync(Ig); + await _context.SaveChangesAsync(); + bool Result2 = await _service.DeleteRow(1); + Assert.IsTrue(Result2); + } + + [TestMethod] + public async Task TestGetAll() + { + // Add a couple hundred pages to test the paganation + for (int i = 0; i < 300; i++) + { + ItemGroup Random_IG = TestHelper.CreateRandomItemGroup(); + await _context.ItemGroups.AddAsync(Random_IG); + } + await _context.SaveChangesAsync(); + + // try to get the first page with size 100 (including 100 x ItemGroup) + List ItemGroups = await _service.GetAllRows(1, 100); + Assert.AreEqual(ItemGroups[0].Id, 1); + Assert.AreEqual(ItemGroups.Last().Id, 100); + Assert.IsTrue(ItemGroups.All(Ig => Ig.Id <= 100)); + + // try to get the second Page with size 150 + + + + + } + [TestCleanup] + public void Cleanup() + { + try + { + _context.Database.EnsureDeleted(); + } + finally + { + _context.Dispose(); + } + } +} \ No newline at end of file diff --git a/UnitTest/ItemLinesServiceTest.cs b/UnitTest/ItemLinesServiceTest.cs index d30e044..34630f4 100644 --- a/UnitTest/ItemLinesServiceTest.cs +++ b/UnitTest/ItemLinesServiceTest.cs @@ -1,139 +1,129 @@ -// using Microsoft.AspNetCore.Http.Features; -// namespace CargoHub.Test; - -// // note: in-memory database is used because it's faster than an actual database -// // TestSetup() : is used to setup the in-memory database before each test so the tests don't effect each other -// // TestCleanup() : is used to delete the in-memory database so - -// [TestClass] -// public class TestItemLinesService -// { -// private AppDbContext _context; -// private BaseStorageService _service; -// [TestInitialize] -// public void Setup() -// { -// var options = new DbContextOptionsBuilder() -// .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) -// .Options; - -// _context = new AppDbContext(options); - -// _service = new BaseStorageService(_context); -// } -// [TestMethod] -// public async Task TestPostItemLine() -// { -// // Try adding an item line with a value of null -// ItemLine? NullItemLine = null; -// int? NullResult = await _service.AddRow(NullItemLine); -// Assert.IsNull(NullResult); - -// // Try to add a test item line -// ItemLine IL = TestHelper.TestItemLine1; -// int? result = await _service.AddRow(IL); - -// // Get the added Item line and check the properties -// ItemLine? FoundIL = await _context.ItemLines.FindAsync(result); -// Assert.IsNotNull(FoundIL); -// Assert.IsNotNull(FoundIL.CreatedAt); -// Assert.IsNotNull(FoundIL.UpdatedAt); -// Assert.AreEqual(IL.Name, FoundIL.Name); - - -// } -// [TestMethod] -// public async Task TesGetItemLine() -// { -// // Add an Item line using DBcontext -// ItemLine IL = TestHelper.TestItemLine1; -// await _context.ItemLines.AddAsync(IL); -// await _context.SaveChangesAsync(); - -// // Check if the properties are returned correctly -// ItemLine? result = await _service.GetRow(1); -// Assert.IsNotNull(result); -// Assert.AreEqual(IL.Name, result.Name); -// Assert.AreEqual(IL.Description, result.Description); - - -// } - -// [TestMethod] -// public async Task TestUpdateItemLine() -// { -// // Add an item line object to the db -// ItemLine IL = TestHelper.TestItemLine1; -// await _context.ItemLines.AddAsync(IL); -// await _context.SaveChangesAsync(); - -// // Update the inserted item line -// ItemLine UpdatedIL = TestHelper.TestItemLine2; -// bool result = await _service.UpdateRow(IL.Id, UpdatedIL); -// Assert.IsTrue(result); -// Assert.IsTrue(IL.UpdatedAt > IL.CreatedAt); -// } - -// [TestMethod] -// public async Task TestUpdateInvalidItemLine() -// { -// // try to update an ItemLine that doesn't exist -// ItemLine UpdatedIL = TestHelper.TestItemLine2; -// bool Result1 = await _service.UpdateRow(999, UpdatedIL); -// Assert.IsFalse(Result1); - -// // Add an ItemLine to the DB -// ItemLine IL = TestHelper.TestItemLine1; -// await _context.ItemLines.AddAsync(IL); -// await _context.SaveChangesAsync(); - -// // Test Updating the item line -// bool result = await _service.UpdateRow(IL.Id, UpdatedIL); -// Assert.IsTrue(result); - -// } - -// [TestMethod] -// public async Task TestDeleteItemLine() -// { -// // try deleting an entity that doesn't exist -// bool Result1 = await _service.DeleteRow(1); -// Assert.IsFalse(Result1); - -// ItemLine IL = TestHelper.TestItemLine1; -// await _context.ItemLines.AddAsync(IL); -// await _context.SaveChangesAsync(); -// bool Result2 = await _service.DeleteRow(1); -// Assert.IsTrue(Result2); -// } - -// [TestMethod] -// public async Task TestGetAll() -// { -// // Add a couple hundred pages to test the paganation -// for (int i = 0; i < 300; i++) -// { -// ItemLine Random_IL = TestHelper.CreateRandomItemLine(); -// await _context.ItemLines.AddAsync(Random_IL); -// } -// await _context.SaveChangesAsync(); - -// // try to get the first page with size 100 (including 100 x ItemLine) -// List ItemLines = await _service.GetAllRows(1, 100); -// Assert.AreEqual(ItemLines[0].Id, 1); -// Assert.AreEqual(ItemLines.Last().Id, 100); -// Assert.IsTrue(ItemLines.All(IL => IL.Id <= 100)); - -// // try to get the second Page with size 150 - - - - -// } -// [TestCleanup] -// public void Cleanup() -// { -// _context.Database.EnsureDeleted(); -// _context.Dispose(); -// } -// } \ No newline at end of file +using Microsoft.AspNetCore.Http.Features; +namespace CargoHub.Test; + +// note: in-memory database is used because it's faster than an actual database +// TestSetup() : is used to setup the in-memory database before each test so the tests don't effect each other +// TestCleanup() : is used to delete the in-memory database so + +[TestClass] +public class TestItemLinesService +{ + private AppDbContext _context; + private BaseStorageService _service; + [TestInitialize] + public void Setup() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) + .Options; + + _context = new AppDbContext(options); + + _service = new BaseStorageService(_context); + } + [TestMethod] + public async Task TestPostItemLine() + { + // Try adding an item line with a value of null + ItemLine? NullItemLine = null; + int? NullResult = await _service.AddRow(NullItemLine); + Assert.IsNull(NullResult); + + // Try to add a test item line + ItemLine IL = TestHelper.TestItemLine1; + int? result = await _service.AddRow(IL); + + // Get the added Item line and check the properties + ItemLine? FoundIL = await _context.ItemLines.FindAsync(result); + Assert.IsNotNull(FoundIL); + Assert.IsNotNull(FoundIL.CreatedAt); + Assert.IsNotNull(FoundIL.UpdatedAt); + Assert.AreEqual(IL.Name, FoundIL.Name); + + + } + [TestMethod] + public async Task TesGetItemLine() + { + // Add an Item line using DBcontext + ItemLine IL = TestHelper.TestItemLine1; + await _context.ItemLines.AddAsync(IL); + await _context.SaveChangesAsync(); + + // Check if the properties are returned correctly + ItemLine? result = await _service.GetRow(1); + Assert.IsNotNull(result); + Assert.AreEqual(IL.Name, result.Name); + Assert.AreEqual(IL.Description, result.Description); + + + } + + [TestMethod] + public async Task TestUpdateItemLine() + { + // Add an item line object to the db + ItemLine IL = TestHelper.TestItemLine1; + await _context.ItemLines.AddAsync(IL); + await _context.SaveChangesAsync(); + + // Update the inserted item line + ItemLine UpdatedIL = TestHelper.TestItemLine2; + bool result = await _service.UpdateRow(IL.Id, UpdatedIL); + Assert.IsTrue(result); + Assert.IsTrue(IL.UpdatedAt > IL.CreatedAt); + } + + [TestMethod] + public async Task TestUpdateInvalidItemLine() + { + // try to update an ItemLine that doesn't exist + ItemLine UpdatedIL = TestHelper.TestItemLine2; + bool Result1 = await _service.UpdateRow(999, UpdatedIL); + Assert.IsFalse(Result1); + } + + [TestMethod] + public async Task TestDeleteItemLine() + { + // try deleting an entity that doesn't exist + bool Result1 = await _service.DeleteRow(1); + Assert.IsFalse(Result1); + + ItemLine IL = TestHelper.TestItemLine1; + await _context.ItemLines.AddAsync(IL); + await _context.SaveChangesAsync(); + bool Result2 = await _service.DeleteRow(1); + Assert.IsTrue(Result2); + } + + [TestMethod] + public async Task TestGetAll() + { + // Add a couple hundred pages to test the paganation + for (int i = 0; i < 300; i++) + { + ItemLine Random_IL = TestHelper.CreateRandomItemLine(); + await _context.ItemLines.AddAsync(Random_IL); + } + await _context.SaveChangesAsync(); + + // try to get the first page with size 100 (including 100 x ItemLine) + List ItemLines = await _service.GetAllRows(1, 100); + Assert.AreEqual(ItemLines[0].Id, 1); + Assert.AreEqual(ItemLines.Last().Id, 100); + Assert.IsTrue(ItemLines.All(IL => IL.Id <= 100)); + + // try to get the second Page with size 150 + + + + + } + [TestCleanup] + public void Cleanup() + { + _context.Database.EnsureDeleted(); + _context.Dispose(); + } +} \ No newline at end of file diff --git a/UnitTest/TestHelper.cs b/UnitTest/TestHelper.cs index 6ab54f9..5611d1e 100644 --- a/UnitTest/TestHelper.cs +++ b/UnitTest/TestHelper.cs @@ -32,8 +32,9 @@ public static ItemLine CreateRandomItemLine() Name = "Test Name", Description = "Test Description" }; - public static ItemGroup TestItemGroup2 = new ItemGroup + public static ItemGroup UpdatedItemGroup = new ItemGroup { + Id = 1, Name = "Updated Name", Description = "Updated Description" @@ -57,10 +58,12 @@ public static ItemLine CreateRandomItemLine() }; public static ItemLine TestItemLine2 = new ItemLine { + Id = 1, Name = "Updated Name", Description = "Updated Description" }; + public static ItemLine InvalidItemLine = new ItemLine { Name = null, diff --git a/UnitTest/Test_OrdersU.cs b/UnitTest/Test_OrdersU.cs index 846e2e8..a86393e 100644 --- a/UnitTest/Test_OrdersU.cs +++ b/UnitTest/Test_OrdersU.cs @@ -596,7 +596,7 @@ public async Task CreateOrder_ShouldAddOrderAndItemsToDatabase() TotalAllocated = 0, Description = "Test Inventory", ItemReference = "ITEMREF001", - LocationIds = new List { 1, 2 }, + LocationIds = new List { 1, 2 }, TotalOnHand = 10, TotalExpected = 5, TotalOrdered = 15 @@ -787,7 +787,7 @@ public async Task CreateOrder_ShouldThrowException_WhenInsufficientInventory() TotalAllocated = 0, Description = "Test Inventory", ItemReference = "ITEMREF001", - LocationIds = new List { 1, 2 }, + LocationIds = new List { 1, 2 }, TotalOnHand = 4, TotalExpected = 0, TotalOrdered = 4 @@ -889,9 +889,9 @@ public async Task UpdateOrder_ShouldUpdateOrderFieldsAndItems() _dbContext.Inventory.AddRange(new List { - new Inventory { ItemId = "ITEM001", TotalAvailable = 10, TotalAllocated = 2, Description = "Description 1", ItemReference = "Reference 1", LocationIds = new List { 1 }, TotalOnHand = 10, TotalExpected = 0, TotalOrdered = 10 }, - new Inventory { ItemId = "ITEM002", TotalAvailable = 7, TotalAllocated = 3, Description = "Description 2", ItemReference = "Reference 2", LocationIds = new List { 2 }, TotalOnHand = 7, TotalExpected = 0, TotalOrdered = 7 }, - new Inventory { ItemId = "ITEM003", TotalAvailable = 8, TotalAllocated = 0, Description = "Description 3", ItemReference = "Reference 3", LocationIds = new List { 3 }, TotalOnHand = 8, TotalExpected = 0, TotalOrdered = 8 } + new Inventory { ItemId = "ITEM001", TotalAvailable = 10, TotalAllocated = 2, Description = "Description 1", ItemReference = "Reference 1", LocationIds = new List { 1 }, TotalOnHand = 10, TotalExpected = 0, TotalOrdered = 10 }, + new Inventory { ItemId = "ITEM002", TotalAvailable = 7, TotalAllocated = 3, Description = "Description 2", ItemReference = "Reference 2", LocationIds = new List { 2 }, TotalOnHand = 7, TotalExpected = 0, TotalOrdered = 7 }, + new Inventory { ItemId = "ITEM003", TotalAvailable = 8, TotalAllocated = 0, Description = "Description 3", ItemReference = "Reference 3", LocationIds = new List { 3 }, TotalOnHand = 8, TotalExpected = 0, TotalOrdered = 8 } }); await _dbContext.SaveChangesAsync(); @@ -1034,8 +1034,8 @@ public async Task UpdateItemsInOrder_ShouldAddNewItemAndAdjustInventory() _dbContext.Inventory.AddRange(new List { - new Inventory { ItemId = "ITEM001", TotalAvailable = 8, TotalAllocated = 2, Description = "Description 1", ItemReference = "Reference 1", LocationIds = new List { 1 }, TotalOnHand = 10, TotalExpected = 0, TotalOrdered = 10 }, - new Inventory { ItemId = "ITEM003", TotalAvailable = 5, TotalAllocated = 0, Description = "Description 3", ItemReference = "Reference 3", LocationIds = new List { 3 }, TotalOnHand = 8, TotalExpected = 0, TotalOrdered = 8 } + new Inventory { ItemId = "ITEM001", TotalAvailable = 8, TotalAllocated = 2, Description = "Description 1", ItemReference = "Reference 1", LocationIds = new List { 1 }, TotalOnHand = 10, TotalExpected = 0, TotalOrdered = 10 }, + new Inventory { ItemId = "ITEM003", TotalAvailable = 5, TotalAllocated = 0, Description = "Description 3", ItemReference = "Reference 3", LocationIds = new List { 3 }, TotalOnHand = 8, TotalExpected = 0, TotalOrdered = 8 } }); await _dbContext.SaveChangesAsync(); @@ -1083,7 +1083,7 @@ public async Task UpdateItemsInOrder_ShouldRemoveItemAndRestoreInventory() TotalAllocated = 5, Description = "Description", ItemReference = "Reference", - LocationIds = new List { 1 }, + LocationIds = new List { 1 }, TotalOnHand = 10, TotalExpected = 0, TotalOrdered = 10 @@ -1158,7 +1158,7 @@ public async Task DeleteOrder_ShouldRemoveOrderAndRestoreInventory() TotalAllocated = 5, Description = "Description for ITEM001", ItemReference = "Reference for ITEM001", - LocationIds = new List { 1 }, + LocationIds = new List { 1 }, TotalOnHand = 10, TotalExpected = 0, TotalOrdered = 10 @@ -1170,7 +1170,7 @@ public async Task DeleteOrder_ShouldRemoveOrderAndRestoreInventory() TotalAllocated = 3, Description = "Description for ITEM002", ItemReference = "Reference for ITEM002", - LocationIds = new List { 2 }, + LocationIds = new List { 2 }, TotalOnHand = 5, TotalExpected = 0, TotalOrdered = 5 @@ -1277,7 +1277,7 @@ public async Task DeleteOrder_ShouldHandlePartialInventoryRestoration() TotalAllocated = 5, Description = "Description for ITEM001", ItemReference = "Reference for ITEM001", - LocationIds = new List { 1 }, + LocationIds = new List { 1 }, TotalOnHand = 10, TotalExpected = 0, TotalOrdered = 10 @@ -1340,7 +1340,7 @@ public async Task DeleteOrder_ShouldHandleNegativeAllocatedInventorySafely() TotalAllocated = 1, Description = "Description for ITEM001", ItemReference = "Reference for ITEM001", - LocationIds = new List { 1 }, + LocationIds = new List { 1 }, TotalOnHand = 10, TotalExpected = 0, TotalOrdered = 10 From 0a34cc7a19d2c5a049eb9446f333bc05b52b7d0a Mon Sep 17 00:00:00 2001 From: mark-175 <152170112+mark-175@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:15:57 +0100 Subject: [PATCH 4/4] integratie tests maken --- Tests/test_item_groups.py | 6 ++++-- Tests/test_item_lines.py | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Tests/test_item_groups.py b/Tests/test_item_groups.py index fc44369..9c320ed 100644 --- a/Tests/test_item_groups.py +++ b/Tests/test_item_groups.py @@ -13,6 +13,7 @@ HEADERS = {"Content-Type": "application/json"} UPDATED_ITEM_GROUP = { + "id": 1, "Name": "Updated test name", "Description": "Updated test description" } @@ -62,9 +63,11 @@ 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 + requests.delete(BASE_URL + f"/{generated_id}") def test_put_Item_group_that_does_not_exist(): @@ -81,9 +84,8 @@ def test_delete(): delete_response = requests.delete( BASE_URL+f"/{generated_id}") - + assert delete_response.status_code == 200 get_response = requests.get(BASE_URL + str(generated_id)) assert get_response.status_code == 404 - diff --git a/Tests/test_item_lines.py b/Tests/test_item_lines.py index f4ef689..3e7e546 100644 --- a/Tests/test_item_lines.py +++ b/Tests/test_item_lines.py @@ -13,6 +13,7 @@ HEADERS = {"Content-Type": "application/json"} UPDATED_ITEM_LINE = { + "id": 0, "Name": "Updated test name", "Description": "Updated test description" } @@ -61,6 +62,7 @@ def test_put(): # look here for an integer (digit) generated_id = test_helper.get_integer_from_json_string(json) assert generated_id != 0 + UPDATED_ITEM_LINE["id"] = generated_id # modify the added item line put_response = requests.put( BASE_URL + f"/{generated_id}", headers=HEADERS, json=UPDATED_ITEM_LINE) @@ -81,9 +83,8 @@ def test_delete(): delete_response = requests.delete( BASE_URL+f"/{generated_id}") - + assert delete_response.status_code == 200 get_response = requests.get(BASE_URL + str(generated_id)) assert get_response.status_code == 404 -