diff --git a/dev-documentation.md b/dev-documentation.md index f1fc181d..84d16c22 100644 --- a/dev-documentation.md +++ b/dev-documentation.md @@ -1635,12 +1635,13 @@ olympics = Olympics() ## Codeforces -Create an instance of `Codeforces` class +Create an instance of `Users` class ```python from scrape_up import codeforces -codeforces = Codeforces() +codeforces_user = codeforces.Users(username="tourist") +codeforces_user.get_user_data() ``` Methods diff --git a/src/scrape_up/geeksforgeeks/geeksforgeeks.py b/src/scrape_up/geeksforgeeks/geeksforgeeks.py index 3fdec1f4..e1548f2d 100644 --- a/src/scrape_up/geeksforgeeks/geeksforgeeks.py +++ b/src/scrape_up/geeksforgeeks/geeksforgeeks.py @@ -1,6 +1,4 @@ from bs4 import BeautifulSoup -import json - from scrape_up.config.request_config import RequestConfig, get @@ -14,7 +12,7 @@ class Geeksforgeeks: | Methods | Details | | ----------------- | ---------------------------------------------------------------------------------- | - | `.get_profile()` | Returns the user data in json format. | + | `.get_profile()` | Returns the user data in python dict format. | Response: @@ -87,6 +85,6 @@ def get_profile(self): "campus_ambassader": campus_ambaasder, } - return json.dumps(user_data) + return user_data except Exception as e: return None diff --git a/src/test/geeksforgeeks_test.py b/src/test/geeksforgeeks_test.py new file mode 100644 index 00000000..a660c8fe --- /dev/null +++ b/src/test/geeksforgeeks_test.py @@ -0,0 +1,44 @@ +import unittest +from scrape_up.geeksforgeeks import Geeksforgeeks +import json + + +class GeeksforgeeksTest(unittest.TestCase): + """ + Geeksforgeeks module test. + | Methods | Details | + | ----------------- | ---------------------------------------------------------------------------------- | + | `.get_profile()` | Returns the user data in json format. | + """ + + def test_get_profile(self): + instance = Geeksforgeeks(user="nikhil25803") + method_response = instance.get_profile() + + if isinstance(method_response, str): + try: + method_response = json.loads(method_response) + except json.JSONDecodeError: + self.fail("get_profile should return a dictionary or a JSON string") + + expected_keys = [ + "username", + "collage_name", + "collage_rank", + "overall_coding_score", + "monthly_coding_score", + "languages_used", + "current_potd_streak", + "total_problem_solved", + "campus_ambassader", + ] + + self.assertEqual( + list(method_response.keys()), + expected_keys, + "Geeksforgeeks:get_profile - keys mismatch", + ) + + +if __name__ == "__main__": + unittest.main()