Esempio n. 1
0
    def test_serve_file(self, Publisher, Heart, Holder, Cleaner, FileWatcher,
                          MirrorWatcher, RequestManager, ScheduleReader, sleep):
        """Test serving from a file
        """
        server.ConfigParser.return_value.read.reset_mock()
        server.Context.return_value.term.reset_mock()
        server.time.sleep = MagicMock(side_effect=KeyboardInterrupt())
        server.NoOptionError = Exception
        filecfg = ["this_computer", "neverwhere", "360 180 100",
                   "/some/where/",  "/tmp/sched.txt",
                   "schedformat", "amore_mio",
                   "/tmp", "*.hmf",
                   server.NoOptionError("boom")]
        server.ConfigParser.return_value.get = MagicMock(side_effect=filecfg)
        filecfg = [666, 667, 668, 669]
        server.ConfigParser.return_value.getint = MagicMock(side_effect=filecfg)
        server.serve("test_config.cfg")

        # Config reading
        server.ConfigParser.return_value.read.assert_called_once_with("test_config.cfg")

        # publisher
        Publisher.assert_called_once_with(666)

        # heart
        Heart.assert_called_once_with(Publisher.return_value,
                                      "amore_mio:666",
                                      30,
                                      ScheduleReader.return_value)

        # holder
        Holder.assert_called_once_with(Publisher.return_value,
                                       "amore_mio:666")

        # cleaner
        Cleaner.assert_called_once_with(Holder.return_value, 1)

        # watcher
        self.assertEquals(MirrorWatcher.call_count, 0)

        FileWatcher.assert_called_once_with(Holder.return_value,
                                            "/tmp/*.hmf",
                                            ScheduleReader.return_value)
        # request manager

        RequestManager.assert_called_once_with(Holder.return_value,
                                               667, "neverwhere")

        # closing apps...
        for app in [RequestManager.return_value,
                    FileWatcher.return_value,
                    Cleaner.return_value,
                    Heart.return_value,
                    Publisher.return_value]:
            self.assertEquals(app.stop.call_count, 1)
        self.assertEquals(server.Context.return_value.term.call_count, 1)
        server.NoOptionError = MagicMock()
Esempio n. 2
0
    def test_serve_mirror(self, Publisher, Heart, Holder, Cleaner, FileWatcher,
                          MirrorWatcher, RequestManager, ScheduleReader,
                          sleep):
        """Test serving from a mirror
        """
        server.RawConfigParser.return_value.read.reset_mock()
        server.Context.return_value.term.reset_mock()
        server.time.sleep = MagicMock(side_effect=KeyboardInterrupt())
        mirrorcfg = [
            "this_computer", "neverwhere", "360 180 100", "/some/where/",
            server.NoOptionError("boom"),
            server.NoOptionError("boom"), "amore_mio", "/under/the/rainbow/",
            "wtf?", "bluebird", "mirror", "the_other_place"
        ]
        server.RawConfigParser.return_value.get = MagicMock(
            side_effect=mirrorcfg)
        mirrorcfg = [666, 667, 668, 669]
        server.RawConfigParser.return_value.getint = MagicMock(
            side_effect=mirrorcfg)
        server.serve("test_config.cfg")

        # Config reading

        server.RawConfigParser.return_value.read.assert_called_once_with(
            "test_config.cfg")

        # publisher
        Publisher.assert_called_once_with(666)

        # heart
        Heart.assert_called_once_with(Publisher.return_value, "amore_mio:666",
                                      30, ScheduleReader.return_value)

        # holder
        Holder.assert_called_once_with(Publisher.return_value, "amore_mio:666")

        # cleaner
        Cleaner.assert_called_once_with(Holder.return_value, 1)

        # watcher
        self.assertEquals(FileWatcher.call_count, 0)

        MirrorWatcher.assert_called_once_with(Holder.return_value, "bluebird",
                                              667, 668,
                                              ScheduleReader.return_value)
        # request manager

        RequestManager.assert_called_once_with(Holder.return_value, 669,
                                               "neverwhere")

        # closing apps...
        for app in [
                RequestManager.return_value, MirrorWatcher.return_value,
                Cleaner.return_value, Heart.return_value,
                Publisher.return_value
        ]:
            self.assertEquals(app.stop.call_count, 1)
Esempio n. 3
0
    def test_serve_mirror(self, Publisher, Heart, Holder, Cleaner, FileWatcher,
                          MirrorWatcher, RequestManager, ScheduleReader, sleep):
        """Test serving from a mirror
        """
        server.ConfigParser.return_value.read.reset_mock()
        server.Context.return_value.term.reset_mock()
        server.time.sleep = MagicMock(side_effect=KeyboardInterrupt())
        mirrorcfg = ["this_computer", "neverwhere", "360 180 100",
                     "/some/where/",
                     server.NoOptionError("boom"),
                     server.NoOptionError("boom"),
                     "amore_mio",
                     "/under/the/rainbow/", "wtf?", "bluebird", "mirror", "the_other_place"]
        server.ConfigParser.return_value.get = MagicMock(side_effect=mirrorcfg)
        mirrorcfg = [666, 667, 668, 669]
        server.ConfigParser.return_value.getint = MagicMock(side_effect=mirrorcfg)
        server.serve("test_config.cfg")

        # Config reading

        server.ConfigParser.return_value.read.assert_called_once_with("test_config.cfg")

        # publisher
        Publisher.assert_called_once_with(666)

        # heart
        Heart.assert_called_once_with(Publisher.return_value,
                                      "amore_mio:666",
                                      30,
                                      ScheduleReader.return_value)

        # holder
        Holder.assert_called_once_with(Publisher.return_value,
                                       "amore_mio:666")

        # cleaner
        Cleaner.assert_called_once_with(Holder.return_value, 1)

        # watcher
        self.assertEquals(FileWatcher.call_count, 0)

        MirrorWatcher.assert_called_once_with(Holder.return_value,
                                              "bluebird", 667, 668,
                                              ScheduleReader.return_value)
        # request manager

        RequestManager.assert_called_once_with(Holder.return_value,
                                               669, "neverwhere")

        # closing apps...
        for app in [RequestManager.return_value,
                    MirrorWatcher.return_value,
                    Cleaner.return_value,
                    Heart.return_value,
                    Publisher.return_value]:
            self.assertEquals(app.stop.call_count, 1)