
import unittest

from secretstorage import dbus_init, get_any_collection
from secretstorage.util import BUS_NAME
from secretstorage.exceptions import LockedException


@unittest.skipIf(BUS_NAME == "org.freedesktop.secrets",
                 "This test should only be run with the mocked server.")
class LockingUnlockingTest(unittest.TestCase):
	def setUp(self) -> None:
		self.connection = dbus_init()
		self.collection = get_any_collection(self.connection)

	def test_lock_unlock(self) -> None:
		self.collection.lock()
		self.assertTrue(self.collection.is_locked())
		self.assertRaises(LockedException, self.collection.ensure_not_locked)
		self.assertIs(self.collection.unlock(), False)
		self.assertFalse(self.collection.is_locked())
		self.collection.ensure_not_locked()


import unittest

from secretstorage import dbus_init, Collection
from secretstorage.util import BUS_NAME
from secretstorage.exceptions import LockedException


@unittest.skipIf(BUS_NAME == "org.freedesktop.secrets",
                 "This test should only be run with the mocked server.")
class LockingUnlockingTest(unittest.TestCase):
	def setUp(self) -> None:
		self.connection = dbus_init()
		collection_path = "/org/freedesktop/secrets/collection/english"
		self.collection = Collection(self.connection, collection_path)

	def test_lock_unlock(self) -> None:
		self.assertFalse(self.collection.is_locked())
		self.collection.lock()
		self.assertTrue(self.collection.is_locked())
		self.assertRaises(LockedException, self.collection.ensure_not_locked)
		item, = self.collection.search_items({"number": "1"})
		self.assertRaises(LockedException, item.ensure_not_locked)
		self.assertIs(self.collection.unlock(), False)
		self.assertFalse(self.collection.is_locked())
		self.collection.ensure_not_locked()

Add test coverage for Item.ensure_not_locked() method
Add test coverage for Item.ensure_not_locked() method

  
  import unittest
  
- from secretstorage import dbus_init, get_any_collection
+ from secretstorage import dbus_init, Collection
  from secretstorage.util import BUS_NAME
  from secretstorage.exceptions import LockedException
  
  
  @unittest.skipIf(BUS_NAME == "org.freedesktop.secrets",
                   "This test should only be run with the mocked server.")
  class LockingUnlockingTest(unittest.TestCase):
  	def setUp(self) -> None:
  		self.connection = dbus_init()
+ 		collection_path = "/org/freedesktop/secrets/collection/english"
- 		self.collection = get_any_collection(self.connection)
+ 		self.collection = Collection(self.connection, collection_path)
  
  	def test_lock_unlock(self) -> None:
+ 		self.assertFalse(self.collection.is_locked())
  		self.collection.lock()
  		self.assertTrue(self.collection.is_locked())
  		self.assertRaises(LockedException, self.collection.ensure_not_locked)
+ 		item, = self.collection.search_items({"number": "1"})
+ 		self.assertRaises(LockedException, item.ensure_not_locked)
  		self.assertIs(self.collection.unlock(), False)
  		self.assertFalse(self.collection.is_locked())
  		self.collection.ensure_not_locked()
  
Add test coverage for Item.ensure_not_locked() method
## Code Before:

import unittest

from secretstorage import dbus_init, get_any_collection
from secretstorage.util import BUS_NAME
from secretstorage.exceptions import LockedException


@unittest.skipIf(BUS_NAME == "org.freedesktop.secrets",
                 "This test should only be run with the mocked server.")
class LockingUnlockingTest(unittest.TestCase):
	def setUp(self) -> None:
		self.connection = dbus_init()
		self.collection = get_any_collection(self.connection)

	def test_lock_unlock(self) -> None:
		self.collection.lock()
		self.assertTrue(self.collection.is_locked())
		self.assertRaises(LockedException, self.collection.ensure_not_locked)
		self.assertIs(self.collection.unlock(), False)
		self.assertFalse(self.collection.is_locked())
		self.collection.ensure_not_locked()

## Instruction:
Add test coverage for Item.ensure_not_locked() method
## Code After:

import unittest

from secretstorage import dbus_init, Collection
from secretstorage.util import BUS_NAME
from secretstorage.exceptions import LockedException


@unittest.skipIf(BUS_NAME == "org.freedesktop.secrets",
                 "This test should only be run with the mocked server.")
class LockingUnlockingTest(unittest.TestCase):
	def setUp(self) -> None:
		self.connection = dbus_init()
		collection_path = "/org/freedesktop/secrets/collection/english"
		self.collection = Collection(self.connection, collection_path)

	def test_lock_unlock(self) -> None:
		self.assertFalse(self.collection.is_locked())
		self.collection.lock()
		self.assertTrue(self.collection.is_locked())
		self.assertRaises(LockedException, self.collection.ensure_not_locked)
		item, = self.collection.search_items({"number": "1"})
		self.assertRaises(LockedException, item.ensure_not_locked)
		self.assertIs(self.collection.unlock(), False)
		self.assertFalse(self.collection.is_locked())
		self.collection.ensure_not_locked()
