Skip to content

Commit

Permalink
adding integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
prajjwalyd committed Jul 12, 2024
1 parent 69a2bbb commit ea566ef
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
services:
docker:
image: docker:latest
options: --privileged
ports:
- 5432:5432
- 27017:27017
- 5000:5000
- 5001:5001
- 5002:5002
- 5003:5003
# options: --privileged
# ports:
# - 5432:5432
# - 27017:27017
# - 5000:5000
# - 5001:5001
# - 5002:5002
# - 5003:5003

steps:
- name: Checkout code
Expand All @@ -42,7 +42,7 @@ jobs:
docker build -t docker.io/prajjwalyd/analytics:latest ./analytics
- name: Start services
run: docker-compose up -d
run: docker-compose up --build

- name: Run integration tests
run: |
Expand Down
65 changes: 65 additions & 0 deletions test_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import unittest
import requests
import time

BASE_URL = "http://localhost:5000"
SHORTENER_URL = "http://localhost:5001"
QR_CODE_URL = "http://localhost:5002"
ANALYTICS_URL = "http://localhost:5003"

class TestLinkLoom(unittest.TestCase):

@classmethod
def setUpClass(cls):
# Wait for services to start up
time.sleep(10)

def test_url_shortening(self):
response = requests.post(f"{BASE_URL}/create", json={"long_url": "http://example.com"})
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertIn("short_url", data)
self.assertEqual(data["long_url"], "http://example.com")

# Test redirect
short_url = data["short_url"]
redirect_response = requests.get(f"{BASE_URL}/{short_url}", allow_redirects=False)
self.assertEqual(redirect_response.status_code, 302)
self.assertEqual(redirect_response.headers["Location"], "http://example.com")

def test_custom_url_shortening(self):
response = requests.post(f"{BASE_URL}/create", json={"long_url": "http://example.com", "custom_url": "custom123"})
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertEqual(data["short_url"], "custom123")
self.assertEqual(data["long_url"], "http://example.com")

def test_qr_code_generation(self):
response = requests.post(f"{BASE_URL}/create", json={"long_url": "http://example.com", "generate_qr": True})
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertIn("short_url", data)

# Test QR code retrieval
short_url = data["short_url"]
qr_response = requests.get(f"{BASE_URL}/qr/{short_url}")
self.assertEqual(qr_response.status_code, 200)
self.assertEqual(qr_response.headers["Content-Type"], "image/png")

def test_analytics_logging(self):
response = requests.post(f"{BASE_URL}/create", json={"long_url": "http://example.com"})
self.assertEqual(response.status_code, 200)
data = response.json()
short_url = data["short_url"]

# Access the short URL to generate analytics
requests.get(f"{BASE_URL}/{short_url}")

# Test analytics retrieval
analytics_response = requests.get(f"{BASE_URL}/{short_url}/analytics")
self.assertEqual(analytics_response.status_code, 200)
analytics_data = analytics_response.json()
self.assertGreater(len(analytics_data), 0)

if __name__ == "__main__":
unittest.main()

0 comments on commit ea566ef

Please sign in to comment.