Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test gfg files #1020

Merged
merged 5 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dev-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/scrape_up/geeksforgeeks/geeksforgeeks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from bs4 import BeautifulSoup
import json

from scrape_up.config.request_config import RequestConfig, get


Expand All @@ -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:
Expand Down Expand Up @@ -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
44 changes: 44 additions & 0 deletions src/test/geeksforgeeks_test.py
Original file line number Diff line number Diff line change
@@ -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()