Skip to content

Commit

Permalink
Merge pull request #1112 from Santhosh-Siddhardha/main
Browse files Browse the repository at this point in the history
Added test file for devpost module
  • Loading branch information
nikhil25803 authored Jun 10, 2024
2 parents 273c92d + 662ef8b commit 5a92d9b
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/scrape_up/devpost/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .devpost import Devpost

__all__ = ["Devpost"]
102 changes: 102 additions & 0 deletions src/test/devpost_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import unittest
from src.scrape_up.devpost import Devpost


class TestDevpost(unittest.TestCase):
"""
| Methods | Details |
| ------------------ | -------------------------------------------------------------------------------------------------------------------- |
| `.get_projects()` | Returns the latest projects along with their decription, like and commment count, image and member details. |
| `.search(topic)` | Returns the searched projects along with their decription, like and commment count, image and member details. |
| `.get_hackathons()` | Returns the latest hackathons along with their title, participants, prizes, deadlines. |
| `.get_featured()` | Returns the latest featured projects along with their decription, like and commment count, image and member details. |
| `.get_winner()` | Returns the latest winning projects along with their decription, like and commment count, image and member details. |
"""

def setUp(self):
"""
Initialize a Devpost instance before each test method.
"""
self.devpost = Devpost()

def test_get_projects(self):
"""
Test the get_projects() method.
"""
try:
projects = self.devpost.get_projects()
self.assertIsInstance(projects, list, "Expected a list of projects")
if projects: # Check if there are projects returned
project = projects[0]
self.assertIn("title", project, "Project should have a 'title' field")
self.assertIn("description", project, "Project should have a 'description' field")
self.assertIn("like_count", project, "Project should have a 'like_count' field")
self.assertIn("comment_count", project, "Project should have a 'comment_count' field")
self.assertIn("img_url", project, "Project should have a 'img_url' field")
self.assertIn("members", project, "Project should have a 'members' field")
self.assertIsInstance(project["members"], list, "Members should be a list")
except:
return None

def test_search(self):
"""
Test the search() method.
"""
try:
topic = "AI"
projects = self.devpost.search(topic)
self.assertIsInstance(projects, list, "Expected a list of projects")
if projects: # Check if there are projects returned
project = projects[0]
self.assertIn("name", project, "Project should have a 'name' field")
self.assertIn("tagline", project, "Project should have a 'tagline' field")
self.assertIn("like_count", project, "Project should have a 'like_count' field")
self.assertIn("comment_count", project, "Project should have a 'comment_count' field")
self.assertIn("photo", project, "Project should have a 'photo' field")
self.assertIn("members", project, "Project should have a 'members' field")
self.assertIsInstance(project["members"], list, "Members should be a list")

except:
return None


def test_get_featured(self):
"""
Test the get_featured() method.
"""
try:
featured_projects = self.devpost.get_featured()
self.assertIsInstance(featured_projects, list, "Expected a list of featured projects")
if featured_projects: # Check if there are featured projects returned
project = featured_projects[0]
self.assertIn("name", project, "Project should have a 'name' field")
self.assertIn("tagline", project, "Project should have a 'tagline' field")
self.assertIn("like_count", project, "Project should have a 'like_count' field")
self.assertIn("comment_count", project, "Project should have a 'comment_count' field")
self.assertIn("photo", project, "Project should have a 'photo' field")
self.assertIn("members", project, "Project should have a 'members' field")
self.assertIsInstance(project["members"], list, "Members should be a list")
except:
return None

def test_get_winner(self):
"""
Test the get_winner() method.
"""
try:
winner_projects = self.devpost.get_winner()
self.assertIsInstance(winner_projects, list, "Expected a list of winning projects")
if winner_projects: # Check if there are winning projects returned
project = winner_projects[0]
self.assertIn("name", project, "Project should have a 'name' field")
self.assertIn("tagline", project, "Project should have a 'tagline' field")
self.assertIn("like_count", project, "Project should have a 'like_count' field")
self.assertIn("comment_count", project, "Project should have a 'comment_count' field")
self.assertIn("photo", project, "Project should have a 'photo' field")
self.assertIn("members", project, "Project should have a 'members' field")
self.assertIsInstance(project["members"], list, "Members should be a list")
except:
return None

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

0 comments on commit 5a92d9b

Please sign in to comment.