Skip to content

Commit 498bf51

Browse files
committed
Avoid network in API exception test
1 parent 58dcd43 commit 498bf51

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎tests/substack/test_api.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import unittest
3+
from unittest.mock import Mock, patch
34

45
from dotenv import load_dotenv
56

@@ -34,8 +35,10 @@ def _api_from_env() -> Api:
3435

3536
class ApiTest(unittest.TestCase):
3637
def test_api_exception(self):
38+
response = Mock(status_code=401, text="Unauthorized")
3739
with self.assertRaises(SubstackAPIException):
38-
Api(email="", password="")
40+
with patch("requests.Session.post", return_value=response):
41+
Api(email="", password="")
3942

4043
@_e2e
4144
def test_get_posts(self):

0 commit comments

Comments
 (0)