{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from zapy.requests import ZapyRequest, KeyValueItem\n",
    "from zapy.utils import module\n",
    "if __name__ == '__main__':\n",
    "    setup_store = module.load_module('./setup')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GET: https://echo.hoppscotch.io/ None get: test_2\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "F\n",
      "======================================================================\n",
      "FAIL: test_error (zapy.request.requester.Requester._run_test.<locals>.DecoratedClass.test_error)\n",
      "----------------------------------------------------------------------\n",
      "Traceback (most recent call last):\n",
      "  File \"<string>\", line 5, in test_error\n",
      "AssertionError: 'FOO' != 'will raise an error'\n",
      "- FOO\n",
      "+ will raise an error\n",
      "\n",
      "\n",
      "----------------------------------------------------------------------\n",
      "Ran 1 test in 0.001s\n",
      "\n",
      "FAILED (failures=1)\n"
     ]
    },
    {
     "ename": "AssertionError",
     "evalue": "Method: test_error\nTraceback (most recent call last):\n  File \"<string>\", line 5, in test_error\nAssertionError: 'FOO' != 'will raise an error'\n- FOO\n+ will raise an error\n\n\n",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAssertionError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[2], line 16\u001b[0m\n\u001b[1;32m      1\u001b[0m request \u001b[39m=\u001b[39m ZapyRequest(\n\u001b[1;32m      2\u001b[0m     endpoint\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mhttps://echo.hoppscotch.io/\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m      3\u001b[0m     method\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mGET\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m     14\u001b[0m     ]\n\u001b[1;32m     15\u001b[0m )\n\u001b[0;32m---> 16\u001b[0m response \u001b[39m=\u001b[39m \u001b[39mawait\u001b[39;00m request\u001b[39m.\u001b[39msend()\n\u001b[1;32m     17\u001b[0m response\u001b[39m.\u001b[39mjson()\n",
      "File \u001b[0;32m~/projects/vsapp_ex1/.env/lib/python3.11/site-packages/zapy/request/models.py:50\u001b[0m, in \u001b[0;36mZapyRequest.send\u001b[0;34m(self, store, logger, raise_assert)\u001b[0m\n\u001b[1;32m     48\u001b[0m \u001b[39mif\u001b[39;00m request_wrapper\u001b[39m.\u001b[39mtest_result:\n\u001b[1;32m     49\u001b[0m     \u001b[39mif\u001b[39;00m raise_assert \u001b[39mis\u001b[39;00m \u001b[39mTrue\u001b[39;00m:\n\u001b[0;32m---> 50\u001b[0m         assert_test_result_dict(request_wrapper\u001b[39m.\u001b[39;49mtest_result)\n\u001b[1;32m     51\u001b[0m     \u001b[39melif\u001b[39;00m \u001b[39misinstance\u001b[39m(raise_assert, AssertTestResultMixin):\n\u001b[1;32m     52\u001b[0m         raise_assert\u001b[39m.\u001b[39massertZapyTestResultDict(request_wrapper\u001b[39m.\u001b[39mtest_result)\n",
      "File \u001b[0;32m~/projects/vsapp_ex1/.env/lib/python3.11/site-packages/zapy/test/assertion.py:13\u001b[0m, in \u001b[0;36massert_test_result_dict\u001b[0;34m(test_result)\u001b[0m\n\u001b[1;32m     11\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39massert_test_result_dict\u001b[39m(test_result: TestResultDict):\n\u001b[1;32m     12\u001b[0m     \u001b[39massert\u001b[39;00m [] \u001b[39m==\u001b[39m test_result[\u001b[39m'\u001b[39m\u001b[39merrors\u001b[39m\u001b[39m'\u001b[39m], stringify_error(test_result[\u001b[39m'\u001b[39m\u001b[39merrors\u001b[39m\u001b[39m'\u001b[39m])\n\u001b[0;32m---> 13\u001b[0m     \u001b[39massert\u001b[39;00m [] \u001b[39m==\u001b[39m test_result[\u001b[39m'\u001b[39m\u001b[39mfailures\u001b[39m\u001b[39m'\u001b[39m], stringify_error(test_result[\u001b[39m'\u001b[39m\u001b[39mfailures\u001b[39m\u001b[39m'\u001b[39m])\n",
      "\u001b[0;31mAssertionError\u001b[0m: Method: test_error\nTraceback (most recent call last):\n  File \"<string>\", line 5, in test_error\nAssertionError: 'FOO' != 'will raise an error'\n- FOO\n+ will raise an error\n\n\n"
     ]
    }
   ],
   "source": [
    "request = ZapyRequest(\n",
    "    endpoint=\"https://echo.hoppscotch.io/\",\n",
    "    method=\"GET\",\n",
    "    params=[\n",
    "        KeyValueItem(key='param1', value='{{ ctx.store.test_2 }}', active=True),\n",
    "    ],\n",
    "    script=[\n",
    "        'import unittest',\n",
    "\n",
    "        '@ctx.hooks.test',\n",
    "        'class TestStringMethods(unittest.TestCase):',\n",
    "        '    def test_error(self):',\n",
    "        '        self.assertEqual(\"foo\".upper(), \"will raise an error\")',\n",
    "    ]\n",
    ")\n",
    "response = await request.send()\n",
    "response.json()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "my_kernel",
   "language": "python",
   "name": "my_kernel"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
