def test_sonarr_snatch(self):
        release = Release(
            messages=["son snatch  -  /dog/ ¤/(- #sad#  -  pasta"],
            channel=channel,
            title="son snatch",
            url="animal: dog &mood=sad f1: first_fixed f2: fixed_second",
            indexer="Single",
            backends=config.backends.keys(),
            snatches=["my_sonarr"],
        )

        backends.send_approved("my_sonarr", True)

        misc.announce_await_push(self, release)

        backends.check_first_rx(
            self,
            config.backends["my_sonarr"],
            release,
        )

        backends.max_announcements(self, "my_radarr", 1)
        backends.max_announcements(self, "my_lidarr", 1)
        self.assertEqual(db.nr_announcements(), 1)
        self.assertEqual(db.nr_snatches(), 1)

        misc.check_announced(
            self,
            config,
            release,
        )
    def test_radarr1_snatch(self):
        release = Release(
            messages=["two title : another stuff"],
            channel=channel,
            title="two title",
            url="smth: another stuff",
            indexer="Simple1",
            backends=config.backends.keys(),
            snatches=["Radarr1"],
        )

        backends.send_approved("Radarr1", True)

        misc.announce_await_push(self, release)

        backends.check_first_rx(
            self,
            config.backends["Radarr1"],
            release,
        )
        backends.max_announcements(self, "Sonarr1", 1)
        backends.max_announcements(self, "Sonarr2", 1)
        backends.max_announcements(self, "Radarr2", 1)
        backends.max_announcements(self, "Lidarr1", 1)
        backends.max_announcements(self, "Lidarr2", 1)

        self.assertEqual(db.nr_announcements(), 1)
        self.assertEqual(db.nr_snatches(), 1)

        misc.check_announced(
            self,
            config,
            release,
        )
    def test_sonarr_snatch(self):
        release = Release(
            messages=[
                "Old: second multi ",
                "Category: color;",
                "PATH: https://example/a?id=54321",
            ],
            channel=channel,
            title="second multi",
            url="http://example/dl.php/54321/config_string/second+multi.jpg",
            indexer="Multi",
            backends=["my_sonarr"],
            snatches=["my_sonarr"],
        )

        backends.send_approved("my_sonarr", True)

        irc.announce(release)
        irc.announce(release)
        misc.announce_await_push(self, release)

        backends.check_first_rx(
            self,
            config.backends["my_sonarr"],
            release,
        )
        backends.max_announcements(self, "my_radarr", 0)
        backends.max_announcements(self, "my_lidarr", 0)

        self.assertEqual(db.nr_announcements(), 1)
        self.assertEqual(db.nr_snatches(), 1)

        misc.check_announced(
            self,
            config,
            release,
        )
    def test_snatches(self):

        releases = []
        snatches = []
        for i in range(90):
            tracker = trackers[i % 3]
            release = Release(
                messages=[f"title {i} yes : else {i}"],
                channel=tracker["channel"],
                title=f"title {i} yes",
                url=f"{tracker['url']}: else {i}",
                indexer=tracker["name"],
                backends=config.backends.keys(),
            )

            if i % 3 == 0:
                backends.send_approved("MySonarr", True)
                release.snatches.append("MySonarr")
                snatches.append(release)
            elif i % 5 == 0:
                backends.send_approved("MyRadarr", True)
                release.snatches.append("MyRadarr")
                snatches.append(release)
            elif i % 7 == 0:
                backends.send_approved("MyLidarr", True)
                release.snatches.append("MyLidarr")
                snatches.append(release)
            misc.announce_await_push(self, release, wait=0)
            releases.append(release)

        # Wait for all to complete
        time.sleep(1)

        backends.max_announcements(self, "MySonarr", 90)
        backends.max_announcements(self, "MyRadarr", 90)
        backends.max_announcements(self, "MyLidarr", 90)

        misc.check_announcements(self, config, releases, snatches)
    def test_renotify_radarr(self):
        release = Release(
            messages=["son snatch2  -  /horsie/ ¤/(- #calm#  -  pasta"],
            channel=channel,
            title="son snatch2",
            url="animal: horsie &mood=calm f1: first_fixed f2: fixed_second",
            indexer="Single",
            backends=config.backends.keys(),
            snatches=["my_sonarr"],
        )

        backends.send_approved("my_sonarr", True)

        misc.announce_await_push(self, release)

        backends.check_first_rx(
            self,
            config.backends["my_sonarr"],
            release,
        )

        backends.max_announcements(self, "my_radarr", 1)
        backends.max_announcements(self, "my_lidarr", 1)
        self.assertEqual(db.nr_announcements(), 1)
        self.assertEqual(db.nr_snatches(), 1)

        misc.check_announced(
            self,
            config,
            release,
        )

        backends.send_approved("my_radarr", True)

        browser.renotify(self,
                         config,
                         table_row=1,
                         backend="my_sonarr",
                         success=False)
        browser.renotify(self,
                         config,
                         table_row=1,
                         backend="my_lidarr",
                         success=False)
        browser.renotify(self,
                         config,
                         table_row=1,
                         backend="my_radarr",
                         success=True)

        release.snatches.append("my_radarr")

        backends.check_first_rx(
            self,
            config.backends["my_radarr"],
            release,
        )

        self.assertEqual(db.nr_announcements(), 1)
        self.assertEqual(db.nr_snatches(), 2)

        misc.check_announced(
            self,
            config,
            release,
        )
    def test_renotify_lidarr(self):
        release = Release(
            messages=[
                "Old: third ", "Category: fruit;", "PATH: https://ex/a?id=99"
            ],
            channel=channel,
            title="third",
            url="http://ex/dl.php/99/config_string/third.jpg",
            indexer="Multi",
            backends=["my_radarr"],
            snatches=["my_radarr"],
        )

        backends.send_approved("my_radarr", True)

        irc.announce(release)
        irc.announce(release)
        misc.announce_await_push(self, release)

        backends.check_first_rx(
            self,
            config.backends["my_radarr"],
            release,
        )
        backends.max_announcements(self, "my_sonarr", 0)
        backends.max_announcements(self, "my_lidarr", 0)

        self.assertEqual(db.nr_announcements(), 1)
        self.assertEqual(db.nr_snatches(), 1)

        misc.check_announced(
            self,
            config,
            release,
        )

        backends.send_approved("my_lidarr", True)
        browser.renotify(self,
                         config,
                         table_row=1,
                         backend="my_sonarr",
                         success=False)
        browser.renotify(self,
                         config,
                         table_row=1,
                         backend="my_radarr",
                         success=False)
        browser.renotify(self,
                         config,
                         table_row=1,
                         backend="my_lidarr",
                         success=True)

        release.snatches.append("my_lidarr")

        backends.check_first_rx(
            self,
            config.backends["my_lidarr"],
            release,
        )
        backends.max_announcements(self, "my_sonarr", 1)
        backends.max_announcements(self, "my_radarr", 1)

        self.assertEqual(db.nr_announcements(), 1)
        self.assertEqual(db.nr_snatches(), 2)

        misc.check_announced(
            self,
            config,
            release,
        )