Esempio n. 1
0
 def test_countImages(self):
     rightContainer = testlib.mockContainer(name="asdf")
     # 0 images
     oldClient = lib.docker.from_env
     lib.docker.from_env = lambda: testlib.mockEngine(containers=[])
     self.assertEqual(lib.countImages("asdf"), 0)
     # 2 images
     lib.docker.from_env = lambda: testlib.mockEngine(
         containers=[rightContainer, rightContainer])
     self.assertEqual(lib.countImages("asdf"), 2)
     # restore old client
     lib.docker.from_env = oldClient
Esempio n. 2
0
 def setUp(self):
     self.credentials = {
         "User": 12345,
         "Password": 678910,
         "rtmp-URL": "rtmp://i.amagood.server",
         "playpath": "dclive_0_1@2345",
     }
     self.engine = testlib.mockEngine()
     self.mockframe = testlib.mockFrame()
     self.mockframe.credentials = self.credentials
Esempio n. 3
0
 def test_checkDocker(self):
     # save all functions that will be monkey patched here
     oldWhich = lib.shutil.which
     oldClient = lib.docker.from_env
     oldCountImages = lib.countImages
     oldShowerror = lib.showerror
     # check if everything passes
     lib.showerror = testlib.raiseAssertion
     self.makeGood()
     lib.checkDocker("ffmpeg:1.0")
     # simulate docker not installed
     lib.shutil.which = lambda x: None
     badCall = partial(lib.checkDocker, "asdf")
     self.assertRaises(AssertionError, badCall)
     # reset to good version
     self.makeGood()
     # simulate version is not ok
     lib.docker.from_env = lambda: testlib.mockEngine(testlib.mockImages(),
                                                      version="Bad")
     badCall = partial(lib.checkDocker, "asdf")
     self.assertRaises(AssertionError, badCall)
     # reset to good version
     self.makeGood()
     # simulate image is not installed
     lib.docker.from_env = lambda: testlib.mockEngine(
         testlib.mockImages(good=False))
     badCall = partial(lib.checkDocker, "asdf")
     self.assertRaises(AssertionError, badCall)
     # simulate count of image is not right
     self.makeGood()
     lib.countImages = lambda x: 1
     badCall = partial(lib.checkDocker, "asdf")
     self.assertRaises(AssertionError, badCall)
     # restore old funcitons
     lib.countImages = oldCountImages
     lib.docker.from_env = oldClient
     lib.shutil.which = oldWhich
     lib.showerror = oldShowerror
Esempio n. 4
0
 def test_checkStream_containerCreated_finished(self):
     """Check whether reaction to a container that has been created and
     finished succesfully is correct."""
     mockframe = testlib.mockFrame()
     mockframe.container = testlib.mockContainer(status="created",
                                                 log=b"asdf")
     # monkey patch onupdate
     oldOnUpdate = lib.onUpdate
     lib.onUpdate = lambda x: 1
     # monkeypatch client
     oldClient = lib.docker.from_env
     lib.docker.from_env = lambda: testlib.mockEngine(testlib.mockImages())
     lib.createStatusWidget(mockframe)
     lib.checkStream(mockframe)
     self.assertEqual(mockframe.status.get(), "yellow")
     self.assertEqual(mockframe.streamActive, False)
     self.assertEqual(mockframe.lbl_StreamSpeed["text"], "Inactive")
     self.assertEqual(mockframe.container, None)
     # undo monkeypatch
     lib.onUpdate = oldOnUpdate
     lib.docker.from_env = oldClient
Esempio n. 5
0
 def test_checkStream_containerCreated_inList(self):
     """Tests whether the reaction to a created container that
     is then the client.containers.list is correct"""
     mockframe = testlib.mockFrame()
     mockframe.container = testlib.mockContainer(status="created",
                                                 log=b"asdf")
     # monkey patch onupdate
     oldOnUpdate = lib.onUpdate
     lib.onUpdate = lambda x: 1
     # monkeypatch client
     oldClient = lib.docker.from_env
     lib.docker.from_env = lambda: testlib.mockEngine(
         testlib.mockImages(), containers=[mockframe.container])
     lib.createStatusWidget(mockframe)
     lib.checkStream(mockframe)
     self.assertEqual(mockframe.status.get(), "green")
     self.assertEqual(mockframe.streamActive, False)
     self.assertEqual(mockframe.lbl_StreamSpeed["text"], "-/-")
     # undo monkeypatch
     lib.onUpdate = oldOnUpdate
     lib.docker.from_env = oldClient
Esempio n. 6
0
 def tearDown(self) -> None:
     self.engine = testlib.mockEngine()
Esempio n. 7
0
 def makeGood(self):
     # setup things in a way that all tests of checkDocker will pass
     lib.shutil.which = lambda x: "asdf"  # this will make the call return something
     lib.docker.from_env = lambda: testlib.mockEngine(testlib.mockImages())
     lib.countImages = lambda x: 0