def test_run(self):
        # Given
        shop = Shop(name="Sneak-a-venue Shop unit test",
                    url=str(self.shopHtmlResponsePath))
        product = Product(url=str(self.productHtmlResponsePath))
        shop.addProduct(product)

        # Results will be written to a temp DB file which path is defined in TempShopRepoHelper.
        repoHelper = TempShopRepoHelper(shops=[shop])

        async def runner():
            # Given
            requestMock = RequestMock()
            messengerMock = MessengerMock(request=requestMock)

            sut = SneakAvenueShopScraper(scrapee=shop,
                                         scrapeeRepo=repoHelper.shopRepo,
                                         request=requestMock,
                                         messenger=messengerMock)

            # When / Then
            try:
                await sut.run()

            except Exception as e:
                self.fail(
                    f"Expected test to run without Exception, but raised: {e}")

            else:
                self.assertEqual(
                    0, sut._failCount,
                    f"Expected fail count to be 0, but is {sut._failCount}")

        asyncio.run(runner())
    def test_addProduct_shouldRaiseTypeErrorOnInvalidType(self):
        # Given
        sut = Shop()
        prodA = mock.Mock()
        prodA.mockVal = "Some product mock"

        # When / Then
        with self.assertRaises(TypeError):
            sut.addProduct(prodA)
    def test_addProduct(self):
        # Given
        sut = Shop()
        prodA = mock.Mock(spec=Product)
        prodB = mock.Mock(spec=Product)
        prodC = mock.Mock(spec=Product)
        prodA.url = "Some product mock A"
        prodB.url = "Some product mock B"
        prodC.url = "Some product mock C"
        expectedProducts = [prodA, prodB, prodC]

        # When
        sut.addProduct(prodA)
        sut.addProduct(prodB)
        sut.addProduct(prodC)

        # Then
        self.assertListEqual(expectedProducts, sut.products)
    def test_addProduct_shouldNotAddProductWithSameUrlAgain(self):
        # Given
        sut = Shop()
        prodA = mock.Mock(spec=Product)
        prodB = mock.Mock(spec=Product)
        prodC = mock.Mock(spec=Product)
        prodA.url = "http://url-value-A.com/"
        prodB.url = "https://some-other-url.io"
        prodC.url = "http://url-value-A.com/"
        expectedProducts = [prodA, prodB]  # NOT prodC !

        # When
        sut.addProduct(prodA)
        sut.addProduct(prodB)
        sut.addProduct(prodC)

        # Then
        self.assertEqual(2, len(sut.products))
        self.assertListEqual(expectedProducts, sut.products)