Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Adding unit test cases for AuthCodeReceiver
  • Loading branch information
rayluo committed Oct 26, 2021
commit 0322ac704a7abf6447d4d740ba8771588b75b57a
23 changes: 23 additions & 0 deletions tests/test_authcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest

from oauth2cli.authcode import AuthCodeReceiver


class TestAuthCodeReceiver(unittest.TestCase):
def test_setup_at_a_given_port_and_teardown(self):
port = 12345 # Assuming this port is available
with AuthCodeReceiver(port=port) as receiver:
self.assertEqual(port, receiver.get_port())

def test_setup_at_a_ephemeral_port_and_teardown(self):
port = 0
with AuthCodeReceiver(port=port) as receiver:
self.assertNotEqual(port, receiver.get_port())

def test_no_two_concurrent_receivers_can_listen_on_same_port(self):
port = 12345 # Assuming this port is available
with AuthCodeReceiver(port=port) as receiver:
with self.assertRaises(OSError):
with AuthCodeReceiver(port=port) as receiver2:
pass