{ "cells": [ { "cell_type": "code", "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2024-12-22T20:14:09.028753Z", "start_time": "2024-12-22T20:14:01.993435Z" } }, "source": [ "WEBSERVICE_URL = \"https://z309w7i8t3.execute-api.us-east-1.amazonaws.com/posts\"\n", "\n", "import requests\n", "from faker import Faker\n", "fake = Faker()\n", "\n", "n = 3\n", "\n", "outs = []\n", "outs2 = []\n", "\n", "OK = True\n", "\n", "for i in range(n):\n", " try:\n", " outs.append(requests.post(WEBSERVICE_URL, json={'userId': 1, 'title': fake.catch_phrase(), 'body': fake.text()}).json())\n", " except:\n", " print(\"Nie udało się dodać nowego zasobu\")\n", " OK = False\n", "\n", "for i in range(n):\n", " try:\n", " tmp = requests.get(WEBSERVICE_URL+'/'+str(outs[i]['id'])).json()\n", " if tmp != outs[i]:\n", " print(\"Pobrany zasób nie jest zgodny ze wzrocem\")\n", " OK = False\n", " except:\n", " print(\"Nie udało się pobrać zasobu: \"+WEBSERVICE_URL+'/'+str(outs[i]['id']))\n", " OK = False\n", "\n", "for i in range(n):\n", " try:\n", " outs2.append(requests.put(WEBSERVICE_URL+'/'+str(outs[i]['id']), json={'userId': 1, 'title': fake.catch_phrase(), 'body': fake.text()}).json())\n", " except:\n", " OK = False\n", " print(\"Nie udało się zmodyfikować zasobu: \"+WEBSERVICE_URL+'/'+str(outs[i]['id']))\n", "\n", "for i in range(n):\n", " try:\n", " tmp = requests.get(WEBSERVICE_URL+'/'+str(outs[i]['id'])).json()\n", " if tmp != outs2[i]:\n", " print(\"Pobrany zasób nie jest zgodny ze zaktualizowanym wzrocem\")\n", " OK = False\n", " except:\n", " print(\"Nie udało się pobrać zasobu: \"+WEBSERVICE_URL+'/'+str(outs[i]['id']))\n", " OK = False\n", "\n", "for i in range(n):\n", " try:\n", " requests.delete(WEBSERVICE_URL+'/'+str(outs[i]['id']), data={'userId': 1, 'title': fake.catch_phrase(), 'body': fake.text()}).json()\n", " except:\n", " print(\"Nie udało się usunąć zasobu: \"+WEBSERVICE_URL+'/'+str(outs[i]['id']))\n", " OK = False\n", "\n", "if OK:\n", " print(\"==================\\nOK zaliczone\")\n", "else:\n", " print(\"==================\\nNie zaliczone\")" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "==================\n", "OK zaliczone\n" ] } ], "execution_count": 16 }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "", "id": "3a13524f5ffbdf8a" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }