Example #1
0
    def test_acquire_exhausted(self):
        self.pool.pool_size = 1
        self.pool._pool_used.add("a Connection")

        self.pool._lock = Mock()

        self.assertRaises(pyredis.connection.PyRedisError, self.pool.acquire)

        self.pool._lock.assert_has_calls([call.acquire(), call.release()])
Example #2
0
    def test_acquire_exhausted(self):
        self.pool.pool_size = 1
        self.pool._pool_used.add('a Connection')

        self.pool._lock = Mock()

        self.assertRaises(pyredis.exceptions.PyRedisError, self.pool.acquire)

        self.pool._lock.assert_has_calls([call.acquire(), call.release()])
Example #3
0
    def test_acquire_free(self):
        client_orig = Mock()
        self.pool._pool_free.add(client_orig)
        self.pool._lock = Mock()

        client = self.pool.acquire()
        self.assertEqual(client_orig, client)
        self.pool._lock.assert_has_calls([call.acquire(), call.release()])
        self.assertNotIn(client_orig, self.pool._pool_free)
        self.assertIn(client_orig, self.pool._pool_used)
Example #4
0
    def test_acquire_free(self):
        client_orig = Mock()
        self.pool._pool_free.add(client_orig)
        self.pool._lock = Mock()

        client = self.pool.acquire()
        self.assertEqual(client_orig, client)
        self.pool._lock.assert_has_calls([call.acquire(), call.release()])
        self.assertNotIn(client_orig, self.pool._pool_free)
        self.assertIn(client_orig, self.pool._pool_used)
Example #5
0
    def test_acquire_nonfree(self):
        client_orig = Mock()
        self.pool._connect = Mock()
        self.pool._connect.side_effect = [client_orig]

        self.pool._lock = Mock()

        client = self.pool.acquire()
        self.assertEqual(client_orig, client)
        self.pool._lock.assert_has_calls([call.acquire(), call.release()])
        self.assertIn(client_orig, self.pool._pool_used)
Example #6
0
    def test_acquire_nonfree(self):
        client_orig = Mock()
        self.pool._connect = Mock()
        self.pool._connect.side_effect = [client_orig]

        self.pool._lock = Mock()

        client = self.pool.acquire()
        self.assertEqual(client_orig, client)
        self.pool._lock.assert_has_calls([call.acquire(), call.release()])
        self.assertIn(client_orig, self.pool._pool_used)
Example #7
0
    def test_press_and_release_must_release_device_keys_in_reverse_order(self):
        ignored_calls = [ANY for arg in self.expected_calls_args]
        expected_release_calls = [
            call.release(arg) for arg in reversed(self.expected_calls_args)
        ]

        keyboard = self.get_keyboard_with_mocked_backend()
        keyboard.press_and_release(self.keys)

        self.assertEqual(ignored_calls + expected_release_calls,
                         keyboard._device.mock_calls)
Example #8
0
    def test_release_must_release_device_keys(self):
        keyboard = self.get_keyboard_with_mocked_backend()
        keyboard.press(self.keys)
        keyboard._device.reset_mock()

        expected_calls = [
            call.release(arg) for arg in reversed(self.expected_calls_args)
        ]
        keyboard.release(self.keys)

        self.assertEqual(expected_calls, keyboard._device.mock_calls)
Example #9
0
def test_release_name_guessing_ok(caplog, store_mock):
    """Release after guessing the charm's name correctly."""
    caplog.set_level(logging.INFO, logger="charmcraft.commands")

    args = Namespace(name=None, revision=7, channels=['somechannel'])
    with patch('charmcraft.commands.store.get_name_from_metadata') as mock:
        mock.return_value = 'guessed-name'
        ReleaseCommand('group').run(args)

    assert store_mock.mock_calls == [
        call.release('guessed-name', 7, ['somechannel']),
    ]
    expected = "Revision 7 of charm 'guessed-name' released to somechannel"
    assert [expected] == [rec.message for rec in caplog.records]
Example #10
0
def test_release_simple_ok(caplog, store_mock):
    """Simple case of releasing a revision ok."""
    caplog.set_level(logging.INFO, logger="charmcraft.commands")

    channels = ['somechannel']
    args = Namespace(name='testcharm', revision=7, channels=channels)
    ReleaseCommand('group').run(args)

    assert store_mock.mock_calls == [
        call.release('testcharm', 7, channels),
    ]

    expected = "Revision 7 of charm 'testcharm' released to somechannel"
    assert [expected] == [rec.message for rec in caplog.records]
Example #11
0
def test_release_revision_guessing_ok(caplog, store_mock):
    """Release after guessing the revision."""
    caplog.set_level(logging.INFO, logger="charmcraft.commands")

    # make the store to return some revisions badly ordered so we're sure we're getting the max
    tstamp = datetime.datetime(2020, 7, 3, 20, 30, 40)
    store_response = [
        Revision(revision=1, version='v1', created_at=tstamp, status='accepted', errors=[]),
        Revision(revision=3, version='v1', created_at=tstamp, status='accepted', errors=[]),
        Revision(revision=2, version='v1', created_at=tstamp, status='accepted', errors=[]),
    ]
    store_mock.list_revisions.return_value = store_response

    channels = ['somechannel']
    args = Namespace(name='testcharm', revision=None, channels=channels)
    ReleaseCommand('group').run(args)

    assert store_mock.mock_calls == [
        call.list_revisions('testcharm'),
        call.release('testcharm', 3, channels),
    ]

    expected = "Revision 3 of charm 'testcharm' released to somechannel"
    assert [expected] == [rec.message for rec in caplog.records]