From d05cc4666095869556fb4e6182c0b504c836c87f Mon Sep 17 00:00:00 2001 From: Anson Date: Fri, 23 May 2025 14:28:17 -0600 Subject: [PATCH] Add tests --- data.toml | 44 +++++++++---------- src/test/test_api.py | 38 ----------------- src/test/test_two_chainz.py | 85 +++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 60 deletions(-) delete mode 100644 src/test/test_api.py create mode 100644 src/test/test_two_chainz.py diff --git a/data.toml b/data.toml index b4a9884..f36c375 100644 --- a/data.toml +++ b/data.toml @@ -1,50 +1,50 @@ quotes = [ - "My side chick got pregnant by her main dude and i'm offended.", - "I kiss your lady, eat her pussy, then kiss the baby.", + "My side chick got pregnant by her main dude and i'm offended", + "I kiss your lady, eat her pussy, then kiss the baby", "Left hand on that steering wheel, right hand on that pussy!", "For my birthday I threw me a surprise party!", "She got a big booty so I call her big booty", "My girl got a big purse with a purse in it, and her pussy so clean, I can go to church in it!", - "Beat the pussy up, I need riot gear.", - "Gas in a Ziplock, now thats loud and clear.", + "Beat the pussy up, I need riot gear", + "Gas in a Ziplock, now thats loud and clear", "My wrist deserve a shout out, 'I'm like what up wrist?'\nMy stove deserve a shout out, 'I'm like what up stove?'", - "I'm in the kitchen. Yams errrrrwhere.", - "I encourage everyone to pay attention to the issues that matter to you, from jobs and the economy, to education and our schools, to criminal justice reform. Whatever it is that you care about, make sure you use your voice.", + "I'm in the kitchen. Yams errrrrwhere", + "I encourage everyone to pay attention to the issues that matter to you, from jobs and the economy, to education and our schools, to criminal justice reform. Whatever it is that you care about, make sure you use your voice", "If you a chicken head, go somewhere and lay some eggs", "Chain hang to my ding-a-ling, chain hang, chain hang to my ding-a-ling", - "I tried to get a tan but I'm black already.", + "I tried to get a tan but I'm black already", "Then I put a fat rabbit on a Craftmatic!", "Yeah, I love them strippers", - "If I wasn't rapping I'd be trapping.", + "If I wasn't rapping I'd be trapping", "Started from the trap, now I rap", - "I'm so high I can sing to a chandelier\nMy flow a glass of Ace of Spade and yours a can of beer.", + "I'm so high I can sing to a chandelier\nMy flow a glass of Ace of Spade and yours a can of beer", "I look you right in your face, sing to your bitch like I'm Drake!", "Ass so big, I told her to look back at it!", "Drunk and high at the same time.\nDrinking champagne on an airplane!", "Wood grain, chestnut\nTitty fuck, chest nut", "Horsepower, horsepower, all this Polo on, I got horsepower", "If I die, bury me inside the Louis store", - "GI-VEN-CHY, nigga God Bless you.", - "My favorite dish is turkey lasagna\nEven my pajamas designer.", + "GI-VEN-CHY, nigga God Bless you", + "My favorite dish is turkey lasagna\nEven my pajamas designer", "Walked in, ill nigga alert! ill nigga alert!", "Like fuck your baby daddy, his daddy should've worn a condom", - "I'm the type of nigga thats built to last.\nYou fuck with me, Ill put my foot in your ass.", - "I wish a nigga would like a kitchen cabinet.", - "Louie V is my kryptonite.", + "I'm the type of nigga thats built to last.\nYou fuck with me, Ill put my foot in your ass", + "I wish a nigga would like a kitchen cabinet", + "Louie V is my kryptonite", "If you woke up this morning, Nigga you winnin!", - "I use good pussy like its lotion.", - "Big shit like a dinosaur did it.", - "#making bands, yes I am.", + "I use good pussy like its lotion", + "Big shit like a dinosaur did it", + "#making bands, yes I am", "I wear versace like its nike, you don't like it do you?", - "I bet you feel this bank roll if I bump into you.", - "Like fuck your baby daddy, his daddy should've wore a condom.", + "I bet you feel this bank roll if I bump into you", + "Like fuck your baby daddy, his daddy should've wore a condom", "Sprinter van on me, I got them xans on me,\nDriveway so damn long by the time I leave I'm damn asleep", - "Bitches round my pool, I made them hoes look like my landscape.", - "Everything Proper, no propaganda.", + "Bitches round my pool, I made them hoes look like my landscape", + "Everything Proper, no propaganda", "Big sack, a lotta hoes like Santa", "Attitude on some 'Fuck you too!'\nBankroll on 'What it do, boo?'", "I got a pocket full of money, it got me walking all slew-foot", - "I'm on my wave like a cruise ship.", + "I'm on my wave like a cruise ship", "In that hoe mouth like a toothpick", "My new bitch gon' pull me a new bitch,\nThen pull me a new bitch\nSee that is a snowball effect", "I got a mansion full of marble floors,\nIt look like I could go bowl in this bitch", diff --git a/src/test/test_api.py b/src/test/test_api.py deleted file mode 100644 index 6eed839..0000000 --- a/src/test/test_api.py +++ /dev/null @@ -1,38 +0,0 @@ -from fastapi.testclient import TestClient -from datetime import datetime -import time -import pytest -from unittest.mock import patch - -from two_chainz import app - -client = TestClient(app) - - -class TestApi: - def test_api_endpoint(self): - response = client.get("/api/") - assert response.status_code == 200 - - data = response.json() - - assert "status" in data - assert data["status"] == "ok" - assert "timestamp" in data - assert "uptime_seconds" in data - - # Validate timestamp format (ISO format) - assert datetime.fromisoformat(data["timestamp"]) - - @pytest.mark.parametrize( - "mocked_time,start_time,expected", - [ - (100, 50, 50), # 100 - 50 = 50 seconds uptime - (200, 100, 100), # 200 - 100 = 100 seconds uptime - ], - ) - def test_api_uptime_calculation(self, mocked_time, start_time, expected): - with patch("time.time", return_value=mocked_time): - with patch("two_chainz.start_time", start_time): - response = client.get("/api/") - assert response.json()["uptime_seconds"] == expected diff --git a/src/test/test_two_chainz.py b/src/test/test_two_chainz.py new file mode 100644 index 0000000..d74818e --- /dev/null +++ b/src/test/test_two_chainz.py @@ -0,0 +1,85 @@ +from fastapi.testclient import TestClient +from datetime import datetime +import pytest +from unittest.mock import patch + +from two_chainz import app +import two_chainz + +client = TestClient(app) + + +class TestApi: + def test_api_endpoint(self): + response = client.get("/api/") + assert response.status_code == 200 + + data = response.json() + + assert "status" in data + assert data["status"] == "ok" + assert "timestamp" in data + assert "uptime_seconds" in data + + # Validate timestamp format (ISO format) + assert datetime.fromisoformat(data["timestamp"]) + + @pytest.mark.parametrize( + "mocked_time,start_time,expected", + [ + (100, 50, 50), # 100 - 50 = 50 seconds uptime + (200, 100, 100), # 200 - 100 = 100 seconds uptime + ], + ) + def test_api_uptime_calculation(self, mocked_time, start_time, expected): + with patch("time.time", return_value=mocked_time): + with patch("two_chainz.start_time", start_time): + response = client.get("/api/") + assert response.json()["uptime_seconds"] == expected + +@pytest.mark.parametrize("endpoint", ["/api/quote", "/api/alias"]) +class TestDataEndpoints: + + def test_endpoint_nonempty(self, endpoint): + for _ in range(1000): # Data is random so run the test a ton + + # Given we have an endpoint + + # When we do a get request + response = client.get(endpoint) + + # Then we should get a 200 status code + assert response.status_code == 200 + + data = response.json() + + # Then there should be a single entry in the dict + assert len(data) == 1 + + # Then the values should not be empty + key, value = next(iter(data.items())) + assert key + assert value + + +class TestData: + def test_data_exists(self): + assert two_chainz.data + assert two_chainz.data['quotes'] + assert two_chainz.data['aliases'] + + @pytest.mark.parametrize("quote", two_chainz.data['quotes']) + class TestQuotes: + def test_no_empty(self, quote): + assert quote + def test_no_ending_period(self, quote): + assert quote[-1] != "." + def test_no_ending_newline(self, quote): + assert quote[-1] != "\n" + + @pytest.mark.parametrize("alias", two_chainz.data['quotes']) + class TestAlias: + def test_no_empty(self, alias): + assert alias + def test_no_ending_newline(self, alias): + assert alias[-1] != "\n" \ No newline at end of file