aws_rest/test.ipynb
dzikafoczka 71dd0a607a rest
2024-12-22 21:11:54 +01:00

108 lines
3.1 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-12-22T20:11:38.991267Z",
"start_time": "2024-12-22T20:11:31.288506Z"
}
},
"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": 15
}
],
"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
}