Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VinciGit00 committed Nov 1, 2024
1 parent 34591b2 commit 4921a4f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
22 changes: 21 additions & 1 deletion tests/test_credits.py
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@

import unittest
from unittest.mock import patch
from scrapegraphaiapisdk.credits import credits

class TestCredits(unittest.TestCase):

@patch('scrapegraphaiapisdk.credits.requests.get')
def test_credits_success(self, mock_get):
mock_get.return_value.status_code = 200
mock_get.return_value.text = '{"credits": 100}'
response = credits("test_api_key")
self.assertEqual(response, '{"credits": 100}')

@patch('scrapegraphaiapisdk.credits.requests.get')
def test_credits_http_error(self, mock_get):
mock_get.side_effect = requests.exceptions.HTTPError
response = credits("test_api_key")
self.assertIn("HTTP error occurred", response)

if __name__ == '__main__':
unittest.main()
1 change: 0 additions & 1 deletion tests/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def test_feedback_http_error(self, mock_post):
response = feedback("test_api_key", "Great service!")
self.assertIn("HTTP error occurred", response)

# ... additional tests can be added here ...

if __name__ == '__main__':
unittest.main()
1 change: 0 additions & 1 deletion tests/test_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def test_scrape_http_error(self, mock_post):
response = scrape("test_api_key", "http://example.com", "Extract data")
self.assertIn("HTTP error occurred", response)

# ... additional tests can be added here ...

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

0 comments on commit 4921a4f

Please sign in to comment.