From 14867b39760b77d61007d578b2df15c721f95b50 Mon Sep 17 00:00:00 2001 From: JoeySh1 Date: Thu, 29 Feb 2024 22:14:41 +0100 Subject: [PATCH] delete useless files --- __pycache__/main.cpython-311.pyc | Bin 0 -> 16626 bytes read_from.csv | 8 -- test_1_marking_mk2.py | 221 ------------------------------- 3 files changed, 229 deletions(-) create mode 100644 __pycache__/main.cpython-311.pyc delete mode 100644 read_from.csv delete mode 100644 test_1_marking_mk2.py diff --git a/__pycache__/main.cpython-311.pyc b/__pycache__/main.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..53beb694be0d030673634cbf990b428753efa5b4 GIT binary patch literal 16626 zcmeG@TWlNGl{1_nhcA(oC|R~-Te9_}WJ{JU$B+6^`TeTeteqxSoCvgLWKot#WrmV1 znRFO8ZRkL5=&S;>-LxeZt=HZ(-R=X}?4!Wi*aEx2esF{VObph5fL$$MU_Vr(T?GEx zbM8>X8In@$CTRQ7EAepV-gED{_s)6G>wuMf+Xigpn;YQBw|&4)z8wP&^6eaOl5f|5 zi+sBW+&uF(HBiB`06i8;@Z1HmA1%*;x&X8XyaT?0N@%l=RxLLO6@pjr36*zQz=n@j zXbP}s!GD*ATKH&XpqjVB=rz0z;2NF-Sj*c1uH_v7*9p~`x@BDBH}B+Km*}6m?^<9q z_-KW%c$+fMaiD&c5jdMZczGQ?Zem(G2GjBOd1vWfE zwh6GR_1IWYx~y`d@W!MdMOAK8iiAVM(`v3>38JEZ{$Zm0M*wsY!P!fB^a+NtxU7=~}JVnEw zi8AvXl<6;(GW#5qEze4sr_NI4SB)(JYyVTnq&OyZ;R93YD^H!1k|1igPb*Hnd~Prl z9*&UK0Hd;z2_dYq1efI}$0zQyDvRA!E9s`%mwTx6u!Nec5z5n}-7n#w-7_PR@TKWV zX(ZG=Ax1`pp=kHZXAd7b+ubKgp-bU$Asp?&nzMsJy<)JZdpsBlcTG&I4kb5`BG4R5AC?`BilY$`)@S-Onl0%{*

M>$CQHq`9875`Z+< zBTY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d&%&zN_J>80@`&mTR*z>uB zU9&cB&DwO2MJ|QH?Vs-RzVbtsxD}UiRCe-1B!%tMNwd5?B|L?(NCQ~ z!ww-r;d34}(Rzc)6A!|eKFOn}Jc;$tR$QPb0EktOVIWq{E!JLs; zZ57$FFQ3s7{|d%Dje_-Xb-^k&amBJSGS9VUxz@Z@s{`5cG%KEFkd4x}!=G>AzL>a} z-m&20#m}cd0{{X7Yh5meV-3aZXF8K=z$@c;tzct{4hu>(Z~&>ikQ8CUu_MSH@hrIT z*8Z89*W24iqR|N{hA=h^A2BLT#Kz$$*1^3Ox-WDG+S_04+d2^3I<8~(B0L6UkAxo6T;@1Z@&KORu~orhmpU!x20?F zLg)3S{jXi?*#hUU;}^PK)mz&GSPOL*+YjzF^lA@4Kj_wVz3E`IL$>~^?3-46(}|Ng&iBrnH{MK1GFPu~@XI#FT9cms z(VO3Y^PVI(>`)qZkScKElF3&6$$c}qpGvz{&SQgLH-Pwt_1lr)OZu*Z;7?h z@XI)1Gk;7UZQlc2F@(Lv+l;a z~xfZdZf4)Xv=7G$y%x=WicHD>901#W-aja?P@KKin!t?(RN<+#j literal 0 HcmV?d00001 diff --git a/read_from.csv b/read_from.csv deleted file mode 100644 index fb1b20c..0000000 --- a/read_from.csv +++ /dev/null @@ -1,8 +0,0 @@ -url_to_shorten_1,url_to_shorten_2,url_after_update,not_existing_id,invalid_url - -https://en.wikipedia.org/wiki/Dijkstra's_algorithm,https://en.wikipedia.org/wiki/Ducati,https://en.wikipedia.org/wiki/Caproni,1,htInvalid_url/ -https://en.wikipedia.org/wiki/Shortest_path_problem,https://en.wikipedia.org/wiki/Cagiva,https://en.wikipedia.org/wiki/Leonardo_S.p.A.,2,htInvalid_url/ -https://en.wikipedia.org/wiki/Bellman–Ford_algorithm,https://en.wikipedia.org/wiki/Desmodromic_valve,https://en.wikipedia.org/wiki/AgustaWestland,1,htInvalid_url/ -https://en.wikipedia.org/wiki/Network_topology,https://en.wikipedia.org/wiki/Clutch#Dry_clutch,https://en.wikipedia.org/wiki/Alenia_Aermacchi,2,htInvalid_url/ -https://en.wikipedia.org/wiki/Physical_layer,https://en.wikipedia.org/wiki/Manual_transmission,https://en.wikipedia.org/wiki/OTO_Melara,1,htInvalid_url/ -https://en.wikipedia.org/wiki/Bitstream,https://en.wikipedia.org/wiki/Torque_converter,https://en.wikipedia.org/wiki/Saab_AB,2,htInvalid_url/ diff --git a/test_1_marking_mk2.py b/test_1_marking_mk2.py deleted file mode 100644 index 458d9ff..0000000 --- a/test_1_marking_mk2.py +++ /dev/null @@ -1,221 +0,0 @@ -import unittest -import requests -import json -import csv -import random - - -class TestApi(unittest.TestCase): - #with fastapi default port is 8000 with flask is 5000 - base_url = "http://127.0.0.1:5000" - - - def populate_variables_from_csv(self): - with open('read_from.csv', 'r') as f: - reader = csv.reader(f) - next(reader, None) - data = [row for row in reader if len(row) >= 5] - random_row = random.choice(data) - return random_row - - def setUp(self): - # populate data before each test by doing two POST - self.id_shortened_url_1="" - self.id_shortened_url_2="" - - self.url_to_shorten_1,self.url_to_shorten_2,self.url_after_update,self.not_existing_id,self.invalid_url=self.populate_variables_from_csv() - - def do_post(url_to_shorten): - endpoint = "/" - print(url_to_shorten) - url = f"{self.base_url}{endpoint}" - print(url+str(url_to_shorten)) - response = requests.post(url, json={'value': str(url_to_shorten)}) - self.assertEqual(response.status_code, 201, f"Expected status code 201, but got {response.status_code}") - self.assertIsNotNone(response.text, "Response text should not be None.") - response_extracted=response.json() - id_returned=response_extracted["id"]#TODO add try catch / handle in case no id key was returned - return id_returned - - self.id_shortened_url_1=do_post(self.url_to_shorten_1) - print("id 1 obtained "+str(self.id_shortened_url_1)) - self.id_shortened_url_2=do_post(self.url_to_shorten_2) - print("id 2 obtained "+str(self.id_shortened_url_2)) - - - def tearDown(self): #OK - #erase everything - endpoint = "/" - url = f"{self.base_url}{endpoint}" - response = requests.delete(url) - #self.assertEqual(response.status_code, 404, f"Expected status code 404 to confirm correct erase, but got {response.status_code}") - - - """ - /:id GET - Given an ID to the service, redirects the user to the matching long URL by returning 301 with the URL. - If the ID does not exist, 404 should be returned. - """ - def test_get_request_with_id_expect_301(self): - - id = self.id_shortened_url_1 - expected_value = self.url_to_shorten_1 - - endpoint = "/" - url = f"{self.base_url}{endpoint}{id}" - response = requests.get(url) - - self.assertEqual(response.status_code, 301, f"Expected status code 301, but got {response.status_code}") - - self.assertEqual(response.json().get("value"), expected_value, "Expected response body to be " +expected_value+" , but got "+response.json().get("value")) - - def test_get_request_with_id_expect_404(self): - - id = "Unseen_id" - - endpoint = "/" - url = f"{self.base_url}{endpoint}{id}" - response = requests.get(url) - - self.assertEqual(response.status_code, 404, f"Expected status code 404, but got {response.status_code}") - - """ - /:id PUT - Updates the URL behind the given ID. To do so, in addition to the parameter in the URL, - the service requires additional information in the body of the request (e.g., encoded as JSON) - that contains the new version of the URL. Then, the function returns 200 if the update was successful, 400 with an error - if the update failed (e.g., the URL was invalid) or 404 if the ID does not exist. - """ - def test_put_id(self): - - id = self.id_shortened_url_1 - url_to_update = self.id_shortened_url_1 - url_after_update = self.url_after_update - not_existing_id = self.not_existing_id - invalid_url = self.invalid_url - - - endpoint = "/" - url = f"{self.base_url}{endpoint}{id}" - response = requests.put(url, data=json.dumps({'url': url_after_update})) - self.assertEqual(response.status_code, 200, f"Expected status code 200, but got {response.status_code}") - - #check value has been rally changed by doing a get - url = f"{self.base_url}{endpoint}{id}" - response = requests.get(url) - self.assertEqual(response.json().get("value"), url_after_update, "Expected response body to be " +url_after_update+" , but got "+response.json().get("value")) - - - #check 400 by passing invalid url - url = f"{self.base_url}{endpoint}{id}" - response = requests.put(url, data=json.dumps({'url': invalid_url})) - self.assertEqual(response.status_code, 400, f"Expected status code 400, but got {response.status_code}") - - #check 404 aka if id exists - url = f"{self.base_url}{endpoint}{not_existing_id}" - response = requests.put(url, data=json.dumps({'url': not_existing_id})) - self.assertEqual(response.status_code, 404, f"Expected status code 404, but got {response.status_code}") - - - """ - /:id DELETE - Deletes the given short URL / ID and then returns 204. If the ID does not exist, returns 404 - """ - def test_deletion_id(self): - #Erase ID - endpoint = "/" - id = self.id_shortened_url_1 - #url = f"{self.base_url}{endpoint}?value={id}" - url = f"{self.base_url}{endpoint}{id}" - response = requests.delete(url) - self.assertEqual(response.status_code, 204, f"Expected status code 204, but got {response.status_code}") - response = requests.delete(url) - self.assertEqual(response.status_code, 404, f"Expected status code 404, but got {response.status_code}") - - - """ - / GET - Should return a list of something at the global level. Can either be a list of all keys (IDs), all long URLs, - or some combination of the two. Should return 200 on success, but the students can choose what to do on failure - (if applicable) - """ - def test_get_all(self): - endpoint = "/" - url = f"{self.base_url}{endpoint}" - response = requests.get(url) - self.assertEqual(response.status_code, 200, f"Expected status code 200, but got {response.status_code}") - self.assertIsNotNone(response.text, "Response text should not be None.") - - - """ - / POST - Should create a new short URL / ID for the given long URL (which must be given in the body). Returns a 201 with - the new ID on success, or a 400 if there was some failure (e.g., missing URL in body or URL was invalid). - """ - def test_post(self): - #add link - url_to_shorten="https://en.wikipedia.org/wiki/Docker_(software)" - endpoint = "/" - - - url = f"{self.base_url}{endpoint}" - response = requests.post(url, json={'value': str(url_to_shorten)}) - - - self.assertEqual(response.status_code, 201, f"Expected status code 201, but got {response.status_code}") - self.assertIsNotNone(response.json().get("id"), "Response text should not be None.") - - - #check if id returned is correct - temp=response.json().get("id") - url = f"{self.base_url}{endpoint}{temp}" - response = requests.get(url) - self.assertEqual(response.status_code, 301, f"Expected status code 301, but got {response.status_code}") - self.assertEqual(response.json().get("value"), url_to_shorten, "Expected response body to be " +url_to_shorten+" , but got "+response.json().get("value")) - - - #try error by passing an empty link - url_to_shorten="" - endpoint = "/" - url = f"{self.base_url}{endpoint}{url_to_shorten}" - response = requests.post(url, json={'value': str(url_to_shorten)}) - self.assertEqual(response.status_code, 400, f"Expected status code 400, but got {response.status_code}") - - - """ - / DELETE - Deletes all ID/URL pairs in the service. - """ - def test_deletion_all(self): - #delete all - endpoint = "/" - url = f"{self.base_url}{endpoint}" - response = requests.delete(url) - self.assertEqual(response.status_code, 404, f"Expected status code 404 to confirm correct erase, but got {response.status_code}") - - #make a getall to check that stuff is erased - endpoint = "/" - url = f"{self.base_url}{endpoint}" - response = requests.get(url) - self.assertIsNone(response.json().get("value"), "The value should be None since should be empty.") - - -if __name__ == '__main__': - unittest.main() - - - -# update the url of the identifier -@app.route("/", methods=["PUT"]) -def update_item(identifier): - data = request.data - url = json.loads(data.decode())['url'] - if urls.get(identifier): - if check_url_validity(url) == False: - return "Invalid URL", 400 - else: - urls[identifier] = url - print("1") - return "Updated", 200 - else: - return "Not Found", 404 \ No newline at end of file