aws_rest/test.ipynb

116 lines
3.3 KiB
Plaintext
Raw Permalink Normal View History

2024-12-22 21:11:54 +01:00
{
"cells": [
{
"cell_type": "code",
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
2024-12-22 21:14:13 +01:00
"end_time": "2024-12-22T20:14:09.028753Z",
"start_time": "2024-12-22T20:14:01.993435Z"
2024-12-22 21:11:54 +01:00
}
},
"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"
]
}
],
2024-12-22 21:14:13 +01:00
"execution_count": 16
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "",
"id": "3a13524f5ffbdf8a"
2024-12-22 21:11:54 +01:00
}
],
"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
}