def delete(self, pk: int) -> Response: # pylint: disable=C0103, R0201 """A delete method is used to send a specific DELETE request to delete Stock Data by id :param pk: Stock Data primary key :return: a Response object with specific data and status code """ stock_data_deleted = StockData.delete_by_id(pk=pk) if stock_data_deleted: return make_response("Stock data deleted", 200) message = "Stock data not deleted" logger.info(message) return make_response(message, 400)
def test_delete_error(self, get_by_id, pool_manager): get_by_id.return_value = True pool_manager.return_value.__enter__.return_value.cursor.execute.side_effect = psycopg2.DataError self.assertEqual(StockData.delete_by_id(1), False)
def test_delete_true(self, get_by_id, pool_manager): get_by_id.return_value = True pool_manager.return_value.__enter__.return_value.cursor.execute.return_value = True self.assertEqual(StockData.delete_by_id(1), True)