From c33b1894fbf20689b7649667766ac198d953f610 Mon Sep 17 00:00:00 2001 From: wiidu Date: Wed, 2 Jul 2025 16:54:07 -0500 Subject: [PATCH 1/7] Added test cases --- .github/workflows/tests.yaml | 20 ++++++ json_parsing.py | 1 + test_JSON/sample2.txt | 129 +++++++++++++++++++++++++++++++++++ test_JSON/sampleJSON.txt | 123 +++++++++++++++++++++++++++++++++ test_parse.py | 38 +++++++++++ 5 files changed, 311 insertions(+) create mode 100644 .github/workflows/tests.yaml create mode 100644 test_JSON/sample2.txt create mode 100644 test_JSON/sampleJSON.txt create mode 100644 test_parse.py diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..83329e7 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,20 @@ +name: Tests +on: push + +jobs: + unit-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup python + uses: actions/setup-python@v2 + with: + python-version: 3.11.3 + + - name: Install tools + run: python -m pip install --upgrade pip pytest + + - name: Test with unittest + working-directory: ./Project1-PairProgramming + run: python3 -m unittest test_parse.py \ No newline at end of file diff --git a/json_parsing.py b/json_parsing.py index 2b0a05d..a85d7fb 100644 --- a/json_parsing.py +++ b/json_parsing.py @@ -31,6 +31,7 @@ def write_to_database(self, tb_name): GROUP BY Name );""" connection.execute(db.text(remove_dupes)) + connection.commit() def pull_list(self, table_name, city): query = (f"SELECT * FROM {table_name} " diff --git a/test_JSON/sample2.txt b/test_JSON/sample2.txt new file mode 100644 index 0000000..9ca6362 --- /dev/null +++ b/test_JSON/sample2.txt @@ -0,0 +1,129 @@ +{ + "data": [ + { + "location_id": "13483637", + "name": "Bulla Gastrobar Plano", + "address_obj": { + "street1": "6007 Legacy Dr", + "street2": "Suite 180", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75024", + "address_string": "6007 Legacy Dr Suite 180, Plano, TX 75024" + } + }, + { + "location_id": "3186629", + "name": "Half Shells - Plano", + "address_obj": { + "street1": "7201 Bishop Rd.", + "street2": "Suite E-4", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75024-3641", + "address_string": "7201 Bishop Rd. Suite E-4, Plano, TX 75024-3641" + } + }, + { + "location_id": "10793449", + "name": "Sixty Vines - Plano", + "address_obj": { + "street1": "3701 Dallas Pkwy", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75093-7777", + "address_string": "3701 Dallas Pkwy, Plano, TX 75093-7777" + } + }, + { + "location_id": "464998", + "name": "Bob's Steak & Chop House - Plano", + "address_obj": { + "street1": "5760 Legacy Dr Suite B-1", + "street2": "Ste B1", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75024-7102", + "address_string": "5760 Legacy Dr Suite B-1 Ste B1, Plano, TX 75024-7102" + } + }, + { + "location_id": "24112709", + "name": "Ford's Garage Plano", + "address_obj": { + "street1": "3904 North Dallas Pkwy", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75093", + "address_string": "3904 North Dallas Pkwy, Plano, TX 75093" + } + }, + { + "location_id": "1580730", + "name": "Urban Crust", + "address_obj": { + "street1": "1006 E 15th Street", + "street2": "Old Downtown Plano", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75074-6222", + "address_string": "1006 E 15th Street Old Downtown Plano, Plano, TX 75074-6222" + } + }, + { + "location_id": "18454855", + "name": "Plano Restaurante", + "address_obj": { + "street1": "Rua da Bela Vista a Graca 126", + "city": "Lisbon", + "country": "Portugal", + "postalcode": "1170-059", + "address_string": "Rua da Bela Vista a Graca 126, Lisbon 1170-059 Portugal" + } + }, + { + "location_id": "15321599", + "name": "Knife Steakhouse Plano", + "address_obj": { + "street1": "6121 W Park Blvd", + "street2": "The District at Willow Bend", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75093", + "address_string": "6121 W Park Blvd The District at Willow Bend, Plano, TX 75093" + } + }, + { + "location_id": "2259652", + "name": "Whiskey Cake Kitchen & Bar", + "address_obj": { + "street1": "3601 Dallas Parkway", + "street2": "", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75093", + "address_string": "3601 Dallas Parkway, Plano, TX 75093" + } + }, + { + "location_id": "8097563", + "name": "Kona Grill - Plano", + "address_obj": { + "street1": "5973 W. Parker Rd", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75093", + "address_string": "5973 W. Parker Rd, Plano, TX 75093" + } + } + ] +} \ No newline at end of file diff --git a/test_JSON/sampleJSON.txt b/test_JSON/sampleJSON.txt new file mode 100644 index 0000000..9a5fe19 --- /dev/null +++ b/test_JSON/sampleJSON.txt @@ -0,0 +1,123 @@ +{ + "data": [ + { + "location_id": "20117197", + "name": "Self-Guided Scavenger Hunt: The Best of Plano, Texas", + "address_obj": { + "city": "Plano", + "state": "Texas", + "country": "United States", + "address_string": "Plano, TX" + } + }, + { + "location_id": "560646", + "name": "Historic Downtown Plano", + "address_obj": { + "street1": "998 E. 15th Street", + "street2": "", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75074-5808", + "address_string": "998 E. 15th Street, Plano, TX 75074-5808" + } + }, + { + "location_id": "56463", + "name": "Plano", + "address_obj": { + "state": "Texas", + "country": "United States", + "address_string": "Plano, TX" + } + }, + { + "location_id": "15087565", + "name": "Sandman Signature Plano-Frisco Hotel", + "address_obj": { + "street1": "8451 Parkwood Boulevard", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75024-5983", + "address_string": "8451 Parkwood Boulevard, Plano, TX 75024-5983" + } + }, + { + "location_id": "6468516", + "name": "Hilton Dallas/plano Granite Park", + "address_obj": { + "street1": "5805 Granite Parkway", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75024", + "address_string": "5805 Granite Parkway, Plano, TX 75024" + } + }, + { + "location_id": "5951655", + "name": "Cambria Hotel Plano Frisco", + "address_obj": { + "street1": "7500 Parkwood Blvd", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75024-5964", + "address_string": "7500 Parkwood Blvd, Plano, TX 75024-5964" + } + }, + { + "location_id": "1097444", + "name": "The Interurban Railway Museum", + "address_obj": { + "street1": "901 E 15th St", + "street2": "", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75074-5807", + "address_string": "901 E 15th St, Plano, TX 75074-5807" + } + }, + { + "location_id": "10793449", + "name": "Sixty Vines - Plano", + "address_obj": { + "street1": "3701 Dallas Pkwy", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75093-7777", + "address_string": "3701 Dallas Pkwy, Plano, TX 75093-7777" + } + }, + { + "location_id": "465130", + "name": "Love & War In Texas", + "address_obj": { + "street1": "601 E Plano Pkwy", + "street2": "", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75074-6733", + "address_string": "601 E Plano Pkwy, Plano, TX 75074-6733" + } + }, + { + "location_id": "560644", + "name": "Arbor Hills Nature Preserve", + "address_obj": { + "street1": "6701 West Parker Road", + "street2": "", + "city": "Plano", + "state": "Texas", + "country": "United States", + "postalcode": "75093", + "address_string": "6701 West Parker Road, Plano, TX 75093" + } + } + ] +} \ No newline at end of file diff --git a/test_parse.py b/test_parse.py new file mode 100644 index 0000000..c2a37df --- /dev/null +++ b/test_parse.py @@ -0,0 +1,38 @@ +import unittest +import sqlalchemy as db +import json + +from json_parsing import Parser + +class TestParse(unittest.TestCase): + + def setUp(self): + data = '' + with open('test_JSON/sampleJSON.txt', 'r') as file: + data = file.read() + self.parser = Parser(json.loads(data)) + self.engine = db.create_engine('sqlite:///tripadv.db') + self.parser.write_to_database("testing") + + def test_write_to_database(self): + # Run to make sure it only keeps unique values + self.parser.write_to_database("testing") + with self.engine.connect() as connection: + result = connection.execute\ + (db.text("SELECT COUNT(*) FROM testing;")).fetchall() + value = result[0][0] + self.assertEqual(value, 10) + + def test_pull_list(self): + db_list = self.parser.pull_list("testing", "Plano") + self.assertEqual(len(db_list), 9) + for entry in db_list: + self.assertIsInstance(entry, db.Row) + + def test_drop(self): + self.assertIn("testing", db.inspect(self.engine).get_table_names()) + query = "DROP TABLE IF EXISTS testing;" + with self.engine.connect() as connection: + connection.execute(db.text(query)) + connection.commit() + self.assertNotIn("testing", db.inspect(self.engine).get_table_names()) From 9f60c4db6dda010fe5fe165d0b96828469e7c01e Mon Sep 17 00:00:00 2001 From: wiidu Date: Wed, 2 Jul 2025 18:14:12 -0500 Subject: [PATCH 2/7] Trying to fix yaml --- .github/workflows/tests.yaml | 2 +- combined.py | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 83329e7..434f4b7 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -16,5 +16,5 @@ jobs: run: python -m pip install --upgrade pip pytest - name: Test with unittest - working-directory: ./Project1-PairProgramming + working-directory: . run: python3 -m unittest test_parse.py \ No newline at end of file diff --git a/combined.py b/combined.py index 0504607..3a93169 100644 --- a/combined.py +++ b/combined.py @@ -29,8 +29,20 @@ response = requests.get(url, params=data) data_of_trip = response.json() +# results = data_of_trip.get('data', []) + +'''top_five = [] + +for given in results[:5]: + name = given.get('name') + if name: + top_five.append(name) + + +combined = ','.join(top_five)''' + parser = Parser(data_of_trip) -parser.write_to_database("cate") +parser.write_to_database(cate) # Pull stored results db_results = parser.pull_list(cate, cy) @@ -56,7 +68,7 @@ print(ai_response.text) - sugg = input("Want another suggestion? (Yes/No): ").lower().strip() - if sugg != "yes": + another_sugg = input("Do you want another suggestion? (Yes/No): ").lower().strip() + if another_sugg != "yes": print("Enjoy!") - break + break \ No newline at end of file From 5330e52c44312b3e136b1789eecd256a3934e6cd Mon Sep 17 00:00:00 2001 From: wiidu Date: Wed, 2 Jul 2025 18:19:40 -0500 Subject: [PATCH 3/7] Added extra installs to yaml --- .github/workflows/tests.yaml | 1 + combined.py | 16 ++-------------- test_parse.py | 12 ++++++------ 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 434f4b7..023c798 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -14,6 +14,7 @@ jobs: - name: Install tools run: python -m pip install --upgrade pip pytest + run: python -m pip install --upgrade pip sqlalchemy - name: Test with unittest working-directory: . diff --git a/combined.py b/combined.py index 3a93169..2b29365 100644 --- a/combined.py +++ b/combined.py @@ -29,18 +29,6 @@ response = requests.get(url, params=data) data_of_trip = response.json() -# results = data_of_trip.get('data', []) - -'''top_five = [] - -for given in results[:5]: - name = given.get('name') - if name: - top_five.append(name) - - -combined = ','.join(top_five)''' - parser = Parser(data_of_trip) parser.write_to_database(cate) @@ -68,7 +56,7 @@ print(ai_response.text) - another_sugg = input("Do you want another suggestion? (Yes/No): ").lower().strip() - if another_sugg != "yes": + sugg = input("Want another suggestion? (Yes/No): ").lower().strip() + if sugg != "yes": print("Enjoy!") break \ No newline at end of file diff --git a/test_parse.py b/test_parse.py index c2a37df..d4ba2fb 100644 --- a/test_parse.py +++ b/test_parse.py @@ -1,11 +1,11 @@ import unittest import sqlalchemy as db import json - from json_parsing import Parser + class TestParse(unittest.TestCase): - + def setUp(self): data = '' with open('test_JSON/sampleJSON.txt', 'r') as file: @@ -13,13 +13,13 @@ def setUp(self): self.parser = Parser(json.loads(data)) self.engine = db.create_engine('sqlite:///tripadv.db') self.parser.write_to_database("testing") - + def test_write_to_database(self): # Run to make sure it only keeps unique values self.parser.write_to_database("testing") with self.engine.connect() as connection: - result = connection.execute\ - (db.text("SELECT COUNT(*) FROM testing;")).fetchall() + result = connection.\ + execute(db.text("SELECT COUNT(*) FROM testing;")).fetchall() value = result[0][0] self.assertEqual(value, 10) @@ -28,7 +28,7 @@ def test_pull_list(self): self.assertEqual(len(db_list), 9) for entry in db_list: self.assertIsInstance(entry, db.Row) - + def test_drop(self): self.assertIn("testing", db.inspect(self.engine).get_table_names()) query = "DROP TABLE IF EXISTS testing;" From 3c3ba75e58c7c39ef5824ce18ea23fcc5efc3893 Mon Sep 17 00:00:00 2001 From: wiidu Date: Wed, 2 Jul 2025 18:22:07 -0500 Subject: [PATCH 4/7] Fixed run --- .github/workflows/tests.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 023c798..3189b4a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -13,8 +13,7 @@ jobs: python-version: 3.11.3 - name: Install tools - run: python -m pip install --upgrade pip pytest - run: python -m pip install --upgrade pip sqlalchemy + run: python -m pip install --upgrade pip pytest sqlalchemy json - name: Test with unittest working-directory: . From 36d5cacb1e0ec0ea9e8f2b4181cfb98868615e37 Mon Sep 17 00:00:00 2001 From: wiidu Date: Wed, 2 Jul 2025 18:23:31 -0500 Subject: [PATCH 5/7] Troubleshooting --- .github/workflows/tests.yaml | 2 +- combined.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 3189b4a..237b0b6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -13,7 +13,7 @@ jobs: python-version: 3.11.3 - name: Install tools - run: python -m pip install --upgrade pip pytest sqlalchemy json + run: python -m pip install --upgrade pip pytest sqlalchemy - name: Test with unittest working-directory: . diff --git a/combined.py b/combined.py index 2b29365..43f1175 100644 --- a/combined.py +++ b/combined.py @@ -59,4 +59,4 @@ sugg = input("Want another suggestion? (Yes/No): ").lower().strip() if sugg != "yes": print("Enjoy!") - break \ No newline at end of file + break From 0558d868661ed21554831f5527693de342bc29a5 Mon Sep 17 00:00:00 2001 From: wiidu Date: Wed, 2 Jul 2025 18:24:37 -0500 Subject: [PATCH 6/7] I forgot pandas --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 237b0b6..07a2fc3 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -13,7 +13,7 @@ jobs: python-version: 3.11.3 - name: Install tools - run: python -m pip install --upgrade pip pytest sqlalchemy + run: python -m pip install --upgrade pip pytest sqlalchemy pandas - name: Test with unittest working-directory: . From dec8d3166f876a3f517c012b1a0c05efe58bbbe8 Mon Sep 17 00:00:00 2001 From: wiidu Date: Wed, 2 Jul 2025 18:27:04 -0500 Subject: [PATCH 7/7] Removing unecessary imports --- .github/workflows/tests.yaml | 2 +- json_parsing.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 07a2fc3..5f78e07 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -13,7 +13,7 @@ jobs: python-version: 3.11.3 - name: Install tools - run: python -m pip install --upgrade pip pytest sqlalchemy pandas + run: python -m pip install --upgrade pip pytest sqlalchemy pandas python-dotenv - name: Test with unittest working-directory: . diff --git a/json_parsing.py b/json_parsing.py index 5c8ee9f..c907ee3 100644 --- a/json_parsing.py +++ b/json_parsing.py @@ -1,8 +1,6 @@ -import json import sqlalchemy as db import pandas as pd import os -import requests from dotenv import load_dotenv