CSCI-GA-2820-FA24-001 / inventory

NYU DevOps Inventory Service Fall 2024
Apache License 2.0
1 stars 0 forks source link

Fix failing tests #26

Open haardikdharma10 opened 6 days ago

haardikdharma10 commented 6 days ago

Two test cases are failing:

TestInventoryService.test_get_inventory_by_condition and TestInventoryService.test_get_inventory_by_stock_level.

Description of the failing test:

The test logic is flawed. It wrongly assumes that creating multiple random inventory items will not produce a duplicate condition or stock level and then checks that only 1 was returned from the query. This is incorrect whenever there is a duplicate condition or stock level in the data. To fix this, we must calculate the actual number and test for it after the query. For example:

        inventory_items = self._create_inventory(3)
        test_condition = inventory_items[0].condition.value
        condition_count = len(
            [item for item in inventory_items if item.condition.value == test_condition]
        )

This counts the number of conditions that match the first condition which will be one or more and saves it in a variable called condition_count. Then the assertion should test that the number returned from the query matches the actual number in the dataset:

self.assertEqual(len(data), condition_count)

This will always test for the correct number.