diff --git a/tests/old_tests.rar b/tests/old_tests.rar new file mode 100644 index 000000000..26b1c5a16 Binary files /dev/null and b/tests/old_tests.rar differ 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