Пример #1
0
    def test_getConverted_toString_shouldReturnNoneOnEmptyProxy(self):
        # Given
        proxy = Proxy()
        sut = StringProxyConverter(source=proxy, target=str)

        # When
        proxyStr = sut.getConverted()

        # Then
        self.assertEqual(None, proxyStr)
Пример #2
0
    def insert(self, data: Proxy) -> None:
        """ Add a Proxy to the database.

        :param data: A single Proxy object
        :return: None
        :raises:
        """
        converter = StringProxyConverter(source=data, target=str)
        proxyStr = converter.getConverted()
        super().insert(data=proxyStr)  # raises
Пример #3
0
    def test_getConverted_toString_shouldReturnValidSimpleProxy(self):
        # Given
        proxy = Proxy.make(endpoint="foo.bar.baz", port=9031)
        expectedString = "foo.bar.baz:9031"
        sut = StringProxyConverter(source=proxy, target=str)

        # When
        proxyStr = sut.getConverted()

        # Then
        self.assertEqual(expectedString, proxyStr)
Пример #4
0
    def test_getConverted_toProxy_shouldReturnValidSimpleProxy(self):
        # Given
        proxyStr = "197.236.15.203:9345"
        sut = StringProxyConverter(proxyStr, Proxy)

        # When
        proxy = sut.getConverted()

        # Then
        self.assertEqual("197.236.15.203", proxy.endpoint)
        self.assertEqual(9345, proxy.port)
        self.assertEqual("", proxy.username)
        self.assertEqual("", proxy.pw)
Пример #5
0
    def test_getConverted_toProxy_shouldReturnValidAuthProxy(self):
        # Given
        proxyStr = "one.proxy.com:8080:myusername:mypassword-Germany_session-jazeoenx"
        sut = StringProxyConverter(proxyStr, Proxy)

        # When
        proxy = sut.getConverted()

        # Then
        self.assertEqual("one.proxy.com", proxy.endpoint)
        self.assertEqual(8080, proxy.port)
        self.assertEqual("myusername", proxy.username)
        self.assertEqual("mypassword-Germany_session-jazeoenx", proxy.pw)
Пример #6
0
    def test_getConverted_toString_shouldCallValidProxyCheck(self):
        # We won't test for invalid proxy strings here because there is a dedicated function
        # for this check which gets unit tested itself. Just test if this func is called.

        # Given
        proxy = Proxy.make(endpoint="foo.bar.baz", port=9031)
        sut = StringProxyConverter(source=proxy, target=str)

        # When
        with mock.patch("network.proxy.StringProxyConverter.isValidProxyString"
                        ) as check:
            sut.getConverted()

            # Then
            check.assert_called_once()
Пример #7
0
    def test_getConverted_toString_shouldReturnValidAuthProxy(self):
        # Given
        proxy = Proxy.make(endpoint="abc.bar.de",
                           port=8021,
                           username="******",
                           pw="TestPW")

        expectedString = "abc.bar.de:8021:Tester:TestPW"
        sut = StringProxyConverter(source=proxy, target=str)

        # When
        proxyStr = sut.getConverted()

        # Then
        self.assertEqual(expectedString, proxyStr)
Пример #8
0
    def test_getConverted_toProxy_shouldCallValidProxyCheck(self):
        # We won't test for invalid proxy strings here because there is a dedicated function
        # for this check which gets unit tested itself. Just test if this func is called.

        # Given
        proxyStr = "some.endpoint.de:3487"
        sut = StringProxyConverter(proxyStr, Proxy)

        # When
        with mock.patch("network.proxy.StringProxyConverter.isValidProxyString"
                        ) as check:
            sut.getConverted()

            # Then
            check.assert_called_once_with(proxyStr)
Пример #9
0
 def _filterRecord(self, record: str) -> Optional[str]:
     """ Called by superclass.
     :param record: A single proxy string
     :return: The same string if no filter was applied, else None
     """
     if not StringProxyConverter.isValidProxyString(record):
         logger.debug("Record sorted out by filter: %s", record)
         return None
     return record
Пример #10
0
 def test_isInstanceOfBaseConverter(self):
     sut = StringProxyConverter("", Proxy)
     self.assertIsInstance(sut, BaseConverter)