From 46838c3bd07bbe88cb94a09e5226065e965e1605 Mon Sep 17 00:00:00 2001 From: Qulu Date: Sat, 12 Jan 2019 03:05:55 +0400 Subject: [PATCH] Move old tests which are incompatible with current code to an archive & make a sample test file Although those old tests are deprecated and incompatible with today's code, they are very decent and written by a tester professional. So that, it's best to fix the incompatibilities in them and serve them as strong tests to be run by pytest. --- tests/old_tests.rar | Bin 0 -> 2135 bytes tests/test_instapy.py | 59 ------------------------------------ tests/test_like_util.py | 18 ----------- tests/test_settings.py | 6 ++++ tests/test_unfollow_util.py | 55 --------------------------------- tests/test_util.py | 16 ---------- 6 files changed, 6 insertions(+), 148 deletions(-) create mode 100644 tests/old_tests.rar delete mode 100644 tests/test_instapy.py delete mode 100644 tests/test_like_util.py create mode 100644 tests/test_settings.py delete mode 100644 tests/test_unfollow_util.py delete mode 100644 tests/test_util.py diff --git a/tests/old_tests.rar b/tests/old_tests.rar new file mode 100644 index 0000000000000000000000000000000000000000..26b1c5a163db129fe2afc6e5f50a4e96008cd455 GIT binary patch literal 2135 zcmV-d2&nf`VR9iF2LS-s&^eb20R;yT1_1$pfPet_0Q)H`0s{-O1qA;QAYRNjNTG{|r7#6>7tyA~2cXsY@FAw&I z*GLUZ55w4x8;o|!6b&gfAqY1Xp!casc8H&0W}dyX8c+cq?FvpW%p1W1CaO;0=5u^o zUW$V}fQG|O5Qs#u)(&ggsjd+kqgDo^gAIbOJhoXDN#Qhw8e8NANS{xyTSznCTRPy5 z^K^Xv)4>xudh6FE$TDZk=XA803rMn$wX?g*55uSrVIeq`+?zVT0^2eqP81zG@8_xLn|BXK^mB0JX?#=x5lSGr6BF8*~ zU8NWuP;p^jQ{5AgVQ8?(Va*wlZR>Dbco7BqN#>JWn>LS(rYiDd^yJT|$Sros=0fwN zK!YG|4Q^XPw@`8q#plVmqFD~pD|2()|3sBLVr7Z#j3;O~D zxdkBB+tOKp1ppCrWpi|2Y-wv{Uv+e8Y%Xwl3IhT~>^X2_I@AHl<#z!$bVDOQRs>%0 zDd6o}!I2>yF9?-NrBb}Cyr(&0XrRj-fWZxxN~%5L${DN`juBrIYC(qXZhRPd5s!Bs z{Bv3R{w(pytEPikwKb_@VxpNhnN(FxZ8oU=)h42$395~m?H>N@_lgM`cXLb7=rT2B5k> zC}aUQIEqxQ5|86|Wx&MGFm&OWqfajFc5-kFi#JYq7!-{_GQl7>P;jj+vbCmC3GA<6 zH-I;+-Te3_4IOu)43QeJni(KFsiEmX;Q{S1sM5;V@cr7^_Hd?9z6ru^Wez^W zeTwbDH5&oBIdk>w4-kG=3;YvvVKKsCZ?`Rv|HC1lK(0)TdcF(X+#ebWTapf5uWPQv zfIzs{{HZYl0}J#71b`DD(9;BbfCT^*bY*jNUv+L~Z)|LDcVBgMX>2ZVc?tspi*V_{ z|ESaf$>DGUHv~g7GxT;v?*N_-MZ6MpFoSaQfFLNKM>$J)TX`VC36@f5M43Snqi*}; zR^cTi(s8FB2qbBrdpe%;4-9v0k2lFd(#a?--qfHA!0FUpXAoq?5=z<24owK02Hy3E7TAm3| zs10I><`EC!P}_yU&WL78#KCqWIX;BTmhe!tVE-bIJH0QAJ=SM^Y$r(C2_a|Btg8_p z1(`5r=CoZl=O)~NJRL{p^e{)a%{J5de4&<+7krH%6}wdXnH;m}u5q!za??=0(a%t&B4x^+ zWym7WJ)&*06^~hCg^?v{7{Xw5XRaZ~TI|2e(emvM-cz7A*q=>;@b7b2tAmEXvED!5 z?9Xx@Z7adgQ??)n$1@}Iqq2tvoVf?cGw_|}hENv!JG>IQoV+lry)E1j)G*|DjrDnh z2qdM3h{WcRDuXU~GBe-B*Gm8M6&l9OAi8vywP8lVfj^ zHki{G{|N#>zWa-v3QF2VdTE&1WR^@;lo0v|3InTFpEpRMh;jCu95BT8$|ilVR=zfZ!OK`*`( NK}a2UR#5{51ON~s>&gHC literal 0 HcmV?d00001 diff --git a/tests/test_instapy.py b/tests/test_instapy.py deleted file mode 100644 index ec765d8f1..000000000 --- a/tests/test_instapy.py +++ /dev/null @@ -1,59 +0,0 @@ -from unittest.mock import patch, PropertyMock - -import pytest -from selenium.common.exceptions import WebDriverException - -from instapy.instapy import InstaPy, InstaPyError - - -def test_interact_by_users_with_no_usernames(): - """ensure no usernames input is handled""" - instapy = InstaPy(selenium_local_session=False) - res = instapy.interact_by_users(None) - assert isinstance(res, InstaPy) - assert instapy.liked_img == 0 - assert instapy.already_liked == 0 - assert instapy.inap_img == 0 - assert instapy.commented == 0 - - -def test_like_by_users_with_no_usernames(): - """test no inputs returns instance without errors""" - instapy = InstaPy(selenium_local_session=False) - res = instapy.like_by_users([]) - assert isinstance(res, InstaPy) - - -@patch('instapy.instapy.webdriver') -def test_set_selenium_local_session_raises_missing_chromedriver(webdriver): - """Ensure chromedriver is installed""" - webdriver.Chrome.side_effect = WebDriverException() - with pytest.raises(InstaPyError): - InstaPy() - - -@patch('instapy.instapy.webdriver') -def test_set_selenium_local_session_raises_chromedriver_version(webdriver): - """Ensure chromedriver version is supported""" - webdriver.Chrome.return_value.capabilities = {'chrome': { - 'chromedriverVersion': '2.35.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91)'}} - with pytest.raises(InstaPyError): - InstaPy() - - -@patch('instapy.instapy.webdriver') -def test_set_selenium_local_session_supports_chromedriver_version(webdriver): - """Ensure chromedriver version is supported""" - webdriver.Chrome.return_value.capabilities = {'chrome': { - 'chromedriverVersion': '2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91)'}} - InstaPy() - - -@patch('instapy.instapy.load_follow_restriction') -def test_set_use_clarifai_raises_on_windows(load_follow_restriction): - """windows not supported""" - instapy = InstaPy(selenium_local_session=False) - with patch('instapy.instapy.os') as os: - type(os).name = PropertyMock(return_value='nt') - with pytest.raises(InstaPyError): - instapy.set_use_clarifai() diff --git a/tests/test_like_util.py b/tests/test_like_util.py deleted file mode 100644 index 10432e547..000000000 --- a/tests/test_like_util.py +++ /dev/null @@ -1,18 +0,0 @@ -from unittest.mock import MagicMock, patch - -from instapy.like_util import check_link - - -class TestCheckLink: - - @patch('instapy.like_util.sleep') - def test_inappropriate_text_on_dont_like(self, sleep): - """when inappropriate the message is returned""" - browser = MagicMock() - browser.execute_script.side_effect = [ - [{'media': {'is_video': False, 'owner': {'username': 'john'}, 'caption': '#f\xf6o'}}], - ''] - inappropriate, user_name, is_video, reason = check_link( - browser, MagicMock(), ['#f'], [], MagicMock(), MagicMock(), MagicMock(), - None, None, MagicMock()) - assert inappropriate is True diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 000000000..b50ba0582 --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,6 @@ +from instapy import Settings + + +def test_settings(): + assert Settings.log_location == None + diff --git a/tests/test_unfollow_util.py b/tests/test_unfollow_util.py deleted file mode 100644 index a204e0dff..000000000 --- a/tests/test_unfollow_util.py +++ /dev/null @@ -1,55 +0,0 @@ -from unittest.mock import MagicMock, Mock, patch - -from selenium.common.exceptions import NoSuchElementException - -from instapy.unfollow_util import follow_given_user_followers, get_given_user_followers - - -class TestFollowGivenUserFollowers: - - def test_with_missing_count(): - """ensure follower count error returns empty""" - webdriver = MagicMock() - webdriver.find_element_by_xpath.side_effect = NoSuchElementException - params = [MagicMock()] * 11 - res = follow_given_user_followers(webdriver, *params) - assert len(res) == 0 - - def test_with_no_followers(): - """ensure follower count is not zero""" - webdriver = MagicMock() - webdriver.find_element_by_xpath.return_value = Mock(text='0') - params = [MagicMock()] * 11 - res = follow_given_user_followers(webdriver, *params) - assert len(res) == 0 - - def test_with_missing_link(): - """ensure follower link error returns empty""" - webdriver = MagicMock() - webdriver.find_element_by_xpath.return_value = Mock(text='123') - webdriver.find_elements_by_xpath.side_effect = BaseException - params = [MagicMock()] * 11 - res = follow_given_user_followers(webdriver, *params) - assert len(res) == 0 - - -class TestGetGivenUserFollowers: - - @patch('instapy.unfollow_util.scroll_bottom') - @patch('instapy.unfollow_util.sleep') - def test_following_link_is_lowercase(self, sleep, scroll_bottom): - browser = MagicMock() - browser.find_element_by_xpath.side_effect = [Mock(text='123'), MagicMock(), MagicMock()] - res = get_given_user_followers(browser, 'FoOb2r', 10, [], MagicMock(), False, MagicMock()) - assert not res - assert 'foob2r' in browser.find_element_by_xpath.call_args_list[1][0][0] - - @patch('instapy.unfollow_util.scroll_bottom') - @patch('instapy.unfollow_util.sleep') - def test_following_link_returns_on_fail(self, sleep, scroll_bottom): - browser = MagicMock() - browser.find_element_by_xpath.side_effect = [Mock(text='123'), NoSuchElementException()] - logger = MagicMock() - res = get_given_user_followers(browser, 'FoOb2r', 10, [], MagicMock(), False, logger) - assert not res - assert logger.error.call_count == 1 diff --git a/tests/test_util.py b/tests/test_util.py deleted file mode 100644 index 3d61221cf..000000000 --- a/tests/test_util.py +++ /dev/null @@ -1,16 +0,0 @@ -import pytest - -from instapy.util import format_number - - -@pytest.mark.parametrize('val,exp', [ - ('123', 123), - ('1,234', 1234), - ('12.3k', 12300), - ('123k', 123000), - ('12.3m', 12300000), - ('123m', 123000000), -]) -def test_format_number(val, exp): - """parse representations to int""" - assert format_number(val) == exp