From e1eb7ecb99d55ae5971b376240d6da820466d722 Mon Sep 17 00:00:00 2001 From: subzeroid <143403577+subzeroid@users.noreply.github.com> Date: Sun, 17 Dec 2023 01:30:28 +0300 Subject: [PATCH] tests fixed --- .github/workflows/python-package.yml | 19 +- README.md | 4 +- docs/index.md | 10 +- instagrapi/mixins/media.py | 4 +- instagrapi/mixins/private.py | 1 - instagrapi/mixins/public.py | 1 - requirements-test.txt | 2 + setup.py | 6 +- tests.py | 399 ++++++++++++++------------- 9 files changed, 234 insertions(+), 212 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 87ecef54..743ff6c8 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -68,7 +68,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ 3.8, 3.9 ] + python-version: [ 3.10 ] steps: - name: Check out code uses: actions/checkout@v3 @@ -80,9 +80,20 @@ jobs: with: requirements: "true" test-requirements: "true" - - - name: Run test - run: python -m unittest tests.FakeClientTestCase + - name: Run user test + run: pytest -sv tests.py::ClientUserTestCase + - name: Run media test + run: pytest -sv tests.py::ClientMediaTestCase + # - name: Run comment test + # run: pytest -sv tests.py::ClientCommentTestCase + # - name: Run location test + # run: pytest -sv tests.py::ClientLocationTestCase + # - name: Run hashtag test + # run: pytest -sv tests.py::ClientHashtagTestCase + - name: Run share test + run: pytest -sv tests.py::ClientShareTestCase + - name: Run highlight test + run: pytest -sv tests.py::ClientHighlightTestCase build-docs: runs-on: ubuntu-latest diff --git a/README.md b/README.md index c188f70d..2dc999f3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The instagrapi more suits for testing or research than a working business! * [LamaTok](https://lamatok.com/p/B9ScEYIQ) for TikTok API ๐Ÿ”ฅ * [HikerAPI](https://hikerapi.com/p/bkXQlaVe) for Instagram API โšกโšกโšก -* [DataLikers](https://datalikers.com/) for Instagram Datasets ๐Ÿš€ +* [DataLikers](https://datalikers.com/p/S9Lv5vBy) for Instagram Datasets ๐Ÿš€ [![Package](https://github.com/subzeroid/instagrapi/actions/workflows/python-package.yml/badge.svg?branch=master)](https://github.com/subzeroid/instagrapi/actions/workflows/python-package.yml) [![PyPI](https://img.shields.io/pypi/v/instagrapi)](https://pypi.org/project/instagrapi/) @@ -37,7 +37,7 @@ Features: Fast and effective Instagram Private API wrapper (public+private requests and challenge resolver) without selenium. Use the most recent version of the API from Instagram, which was obtained using reverse-engineering with Charles Proxy and [Proxyman](https://proxyman.io/). -*Instagram API valid for **28 June 2023** (last reverse-engineering check)* +*Instagram API valid for **16 Dec 2023** (last reverse-engineering check)* Support **Python >= 3.9** diff --git a/docs/index.md b/docs/index.md index 85b4231f..dc33e95d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,14 +1,20 @@ # instagrapi +### We recommend using our services: + +* [LamaTok](https://lamatok.com/p/B9ScEYIQ) for TikTok API ๐Ÿ”ฅ +* [HikerAPI](https://hikerapi.com/p/bkXQlaVe) for Instagram API โšกโšกโšก +* [DataLikers](https://datalikers.com/p/S9Lv5vBy) for Instagram Datasets ๐Ÿš€ + [![Package](https://github.com/subzeroid/instagrapi/actions/workflows/python-package.yml/badge.svg?branch=master)](https://github.com/subzeroid/instagrapi/actions/workflows/python-package.yml) [![PyPI](https://img.shields.io/pypi/v/instagrapi)][pypi] [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/instagrapi)][pypi] Fast and effective Instagram Private API wrapper (public+private requests and challenge resolver). Use the most recent version of the API from Instagram, which was obtained using [reverse-engineering with Charles Proxy](https://github.com/subzeroid/instagrapi/discussions/1182) and [Proxyman](https://proxyman.io/). -*Instagram API valid for **13 February 2023** (last reverse-engineering check)* +*Instagram API valid for **16 Dec 2023** (last reverse-engineering check)* -Support **Python >= 3.8** +Support **Python >= 3.9** For any other languages (e.g. C++, C#, F#, D, [Golang](https://github.com/subzeroid/instagrapi-rest/tree/main/golang), Erlang, Elixir, Nim, Haskell, Lisp, Closure, Julia, R, Java, Kotlin, Scala, OCaml, JavaScript, Crystal, Ruby, Rust, [Swift](https://github.com/subzeroid/instagrapi-rest/tree/main/swift), Objective-C, Visual Basic, .NET, Pascal, Perl, Lua, PHP and others), I suggest using [instagrapi-rest](https://github.com/subzeroid/instagrapi-rest) diff --git a/instagrapi/mixins/media.py b/instagrapi/mixins/media.py index 48ec4a7c..9b3c7192 100644 --- a/instagrapi/mixins/media.py +++ b/instagrapi/mixins/media.py @@ -369,7 +369,7 @@ def media_user(self, media_pk: str) -> UserShort: UserShort An object of UserShort """ - return self.media_info(media_pk).user + return self.media_info_v1(media_pk).user def media_oembed(self, url: str) -> Dict: """ @@ -767,7 +767,7 @@ def user_pinned_medias(self, user_id) -> List[Media]: ) pinned_medias = [] for media in medias["items"]: - if media.get("timeline_pinned_user_ids") != None: + if media.get("timeline_pinned_user_ids") is not None: pinned_medias.append(extract_media_v1(media)) self.base_headers["X-IG-Nav-Chain"] = default_nav return pinned_medias diff --git a/instagrapi/mixins/private.py b/instagrapi/mixins/private.py index f0cc9b21..ac44af86 100644 --- a/instagrapi/mixins/private.py +++ b/instagrapi/mixins/private.py @@ -105,7 +105,6 @@ def __init__(self, *args, **kwargs): session.mount("https://", adapter) session.mount("http://", adapter) self.private = session - self.private.verify = False # fix SSLError/HTTPSConnectionPool self.email = kwargs.pop("email", None) self.phone_number = kwargs.pop("phone_number", None) diff --git a/instagrapi/mixins/public.py b/instagrapi/mixins/public.py index d163c911..e1b10e21 100644 --- a/instagrapi/mixins/public.py +++ b/instagrapi/mixins/public.py @@ -58,7 +58,6 @@ def __init__(self, *args, **kwargs): session.mount("https://", adapter) session.mount("http://", adapter) self.public = session - self.public.verify = False # fix SSLError/HTTPSConnectionPool self.public.headers.update( { diff --git a/requirements-test.txt b/requirements-test.txt index daf99151..895fe48a 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -9,3 +9,5 @@ mkdocs-minify-plugin==0.7.2 mkdocstrings==0.24.0 ./util/mkdocs-redirects ./util/mkdocstrings_patch_type_aliases +pytest-xdist==3.3.1 +pytest~=7.4.3 diff --git a/setup.py b/setup.py index 43477f26..420b035f 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ setup( name="instagrapi", - version="2.0.1", + version="2.0.2", author="Mark Subzeroid", author_email="143403577+subzeroid@users.noreply.github.com", license="MIT", @@ -69,14 +69,14 @@ long_description=long_description, long_description_content_type="text/markdown", packages=find_packages(), - python_requires=">=3.8", + python_requires=">=3.9", include_package_data=True, classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Topic :: Software Development :: Libraries :: Python Modules", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", ], ) diff --git a/tests.py b/tests.py index 840141fe..93ebb842 100644 --- a/tests.py +++ b/tests.py @@ -1,7 +1,9 @@ -import json import os +import json import os.path import random +import logging +import requests import unittest from datetime import datetime, timedelta from json.decoder import JSONDecodeError @@ -39,9 +41,11 @@ from instagrapi.utils import generate_jazoest from instagrapi.zones import UTC -ACCOUNT_USERNAME = os.environ.get("IG_USERNAME", "username") -ACCOUNT_PASSWORD = os.environ.get("IG_PASSWORD", "password*") -ACCOUNT_SESSIONID = os.environ.get("IG_SESSIONID", "") +logger = logging.getLogger("instagrapi.tests") +ACCOUNT_USERNAME = os.getenv("IG_USERNAME", "username") +ACCOUNT_PASSWORD = os.getenv("IG_PASSWORD", "password*") +ACCOUNT_SESSIONID = os.getenv("IG_SESSIONID", "") +TEST_ACCOUNTS_URL = os.getenv("TEST_ACCOUNTS_URL") REQUIRED_MEDIA_FIELDS = [ "pk", @@ -99,40 +103,53 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def set_proxy_if_exists(self): - proxy = os.environ.get("IG_PROXY", "") + proxy = os.getenv("IG_PROXY", "") if proxy: self.cl.set_proxy(proxy) # "socks5://127.0.0.1:30235" return True -class FakeClientTestCase(BaseClientMixin, unittest.TestCase): - cl = None - - def test_login(self): - try: - self.cl.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD) - except (ProxyAddressIsBlocked, BadPassword) as e: - self.assertEqual( - str(e), - "The password you entered is incorrect. Please try again. If you are sure that the password is correct, then change your IP address, because it is added to the blacklist of the Instagram Server", - ) - - try: - is_auth = self.cl.login() - self.assertEqual(is_auth, True) - except BadCredentials as e: - self.assertEqual(str(e), "Both username and password must be provided.") - except ProxyAddressIsBlocked as e: - self.assertEqual( - str(e), - "Instagram has blocked your IP address, use a quality proxy provider (not free, not shared)", - ) - - class ClientPrivateTestCase(BaseClientMixin, unittest.TestCase): cl = None + _username_cache = {} + + def user_info_by_username(self, username): + return self.cl.user_info_by_username_v1(username) + + def user_id_from_username(self, username): + info = self._username_cache.get(username) + if not info: + info = self.user_info_by_username(username) + self._username_cache[username] = info + return str(info.pk) + + def setup_method(self, *args, **kwargs): + if TEST_ACCOUNTS_URL: + self.cl = self.fresh_account() + + def fresh_account(self): + acc = requests.get(TEST_ACCOUNTS_URL).json()[0] + print("New fresh account %r" % acc["username"]) + settings = acc["client_settings"] + totp_seed = settings.pop("totp_seed", None) + cl = Client(settings=settings, proxy=acc["proxy"]) + if totp_seed: + totp_code = cl.totp_generate_code(totp_seed) + cl.login( + acc["username"], + acc["password"], + verification_code=totp_code, + relogin=True, + ) + cl.totp_seed = totp_seed + cl.totp_code = totp_code + cl._user_id = acc.get("user_id") + return cl def __init__(self, *args, **kwargs): + if TEST_ACCOUNTS_URL: + self.cl = self.fresh_account() + return super().__init__(*args, **kwargs) filename = f"/tmp/instagrapi_tests_client_settings_{ACCOUNT_USERNAME}.json" self.cl = Client() settings = {} @@ -146,10 +163,10 @@ def __init__(self, *args, **kwargs): except FileNotFoundError: pass except JSONDecodeError as e: - print( + logger.info( "JSONDecodeError when read stored client settings. Use empty settings" ) - print(str(e)) + logger.exception(e) self.cl.set_settings(settings) # self.cl.set_locale('ru_RU') # self.cl.set_timezone_offset(10800) @@ -181,7 +198,7 @@ def test_media_info_gql(self): self.assertIsInstance(m, Media) media = { "pk": 1532130876531694688, - "id": "1532130876531694688_1903424587", + "id": "1532130876531694688_25025320", "code": "BVDOOolFFxg", "taken_at": datetime(2017, 6, 7, 19, 37, 35, tzinfo=UTC()), "media_type": 1, @@ -201,7 +218,7 @@ def test_media_info_gql(self): } self.assertDict(m.dict(), media) user = { - "pk": 1903424587, + "pk": "25025320", "username": "example", "full_name": "Example Example", "profile_pic_url": "https://...", @@ -347,7 +364,7 @@ def test_set_device(self): settings = self.cl.get_settings() self.assertDictEqual(device, settings["device_settings"]) self.assertEqual(user_agent, settings["user_agent"]) - self.cl.user_info_by_username_v1("example") + self.user_info_by_username("example") request_user_agent = self.cl.last_response.request.headers.get("User-Agent") self.assertEqual(user_agent, request_user_agent) @@ -376,75 +393,39 @@ def test_set_device_agent(self): class ClientUserTestCase(ClientPrivateTestCase): - def test_username_from_user_id(self): - self.assertEqual(self.cl.username_from_user_id(1903424587), "example") - - def test_user_medias(self): - user_id = self.cl.user_id_from_username("example") - medias = self.cl.user_medias(user_id) - self.assertGreater(len(medias), 100) - media = medias[0] - self.assertIsInstance(media, Media) - for field in REQUIRED_MEDIA_FIELDS: - self.assertTrue(hasattr(media, field)) - - def test_usertag_medias(self): - user_id = self.cl.user_id_from_username("example") - medias = self.cl.usertag_medias(user_id) - self.assertGreater(len(medias), 50) - media = medias[0] - self.assertIsInstance(media, Media) - for field in REQUIRED_MEDIA_FIELDS: - self.assertTrue(hasattr(media, field)) - def test_user_followers(self): - user_id = self.cl.user_id_from_username("asphalt_kings_lb") - followers = self.cl.user_followers(self.cl.user_id) - self.assertIn(user_id, followers) - self.assertEqual(followers[user_id].username, "asphalt_kings_lb") - - def test_user_followers_amount(self): - user_id = self.cl.user_id_from_username("certified.nil") - print(user_id) + user_id = self.user_id_from_username("instagram") followers = self.cl.user_followers(user_id, amount=10) - print(followers) self.assertTrue(len(followers) == 10) self.assertIsInstance(list(followers.values())[0], UserShort) - def test_user_following(self): - user_id = self.cl.user_id_from_username("asphalt_kings_lb") - following = self.cl.user_following(self.cl.user_id) - self.assertIn(user_id, following) - self.assertEqual(following[user_id].username, "asphalt_kings_lb") - def test_user_following_amount(self): - user_id = self.cl.user_id_from_username("example") - following = self.cl.user_following(user_id, amount=10) - self.assertTrue(len(following) == 10) - self.assertIsInstance(list(following.values())[0], UserShort) +class ClientUserExtendTestCase(ClientPrivateTestCase): + def test_username_from_user_id(self): + self.assertEqual(self.cl.username_from_user_id(25025320), "instagram") - def test_user_follow_unfollow(self): - user_id = self.cl.user_id_from_username("certified.nil") + def test_user_following(self): + user_id = self.user_id_from_username("instagram") self.cl.user_follow(user_id) - following = self.cl.user_following(self.cl.user_id) + following = self.cl.user_following(self.cl.user_id, amount=1) self.assertIn(user_id, following) - self.cl.user_unfollow(user_id) - following = self.cl.user_following(self.cl.user_id) - self.assertNotIn(user_id, following) + self.assertEqual(following[user_id].username, "instagram") + self.assertTrue(len(following) == 1) + self.assertIsInstance(list(following.values())[0], UserShort) def test_user_info(self): - user_id = self.cl.user_id_from_username("example") + user_id = self.user_id_from_username("instagram") user = self.cl.user_info(user_id) self.assertIsInstance(user, User) for key, value in { - "biography": "Engineer: Python, JavaScript, Erlang...", - "external_url": "https://example.org/", - "full_name": "Example Example", - "pk": 1903424587, + "biography": "...Instagram...", + "external_url": "https://...", + "full_name": "Instagram", + "pk": "25025320", "is_private": False, - "is_verified": False, + "is_verified": True, "profile_pic_url": "https://...", - "username": "example", + "username": "instagram", }.items(): if isinstance(value, str) and "..." in value: self.assertTrue(value.replace("...", "") in getattr(user, key)) @@ -452,32 +433,52 @@ def test_user_info(self): self.assertEqual(value, getattr(user, key)) def test_user_info_by_username(self): - user = self.cl.user_info_by_username("example") + user = self.user_info_by_username("instagram") self.assertIsInstance(user, User) - self.assertEqual(user.pk, 1903424587) - self.assertEqual(user.full_name, "Example Example") + self.assertEqual(user.pk, "25025320") + self.assertEqual(user.full_name, "Instagram") self.assertFalse(user.is_private) - def test_age_restricted_user_info_by_username(self): - user = self.cl.user_info_by_username("philippe_jury_") - self.assertIsInstance(user, User) - self.assertEqual(user.pk, 5802433335) - self.assertEqual(user.full_name, "Philippe Jury") - self.assertFalse(user.is_private) + def test_user_medias(self): + user_id = self.user_id_from_username("instagram") + medias = self.cl.user_medias(user_id, amount=10) + self.assertGreater(len(medias), 5) + media = medias[0] + self.assertIsInstance(media, Media) + for field in REQUIRED_MEDIA_FIELDS: + self.assertTrue(hasattr(media, field)) - def test_send_new_note(self): - self._cl.create_note("Hello from Instagrapi !", 0) + def test_usertag_medias(self): + user_id = self.user_id_from_username("instagram") + medias = self.cl.usertag_medias(user_id, amount=10) + self.assertGreater(len(medias), 5) + media = medias[0] + self.assertIsInstance(media, Media) + for field in REQUIRED_MEDIA_FIELDS: + self.assertTrue(hasattr(media, field)) + + def test_user_follow_unfollow(self): + user_id = self.user_id_from_username("instagram") + self.cl.user_follow(user_id) + following = self.cl.user_following(self.cl.user_id) + self.assertIn(user_id, following) + self.cl.user_unfollow(user_id) + following = self.cl.user_following(self.cl.user_id) + self.assertNotIn(user_id, following) + + # def test_send_new_note(self): + # self.cl.create_note("Hello from Instagrapi!", 0) class ClientMediaTestCase(ClientPrivateTestCase): def test_media_id(self): self.assertEqual( - self.cl.media_id(2154602296692269830), "2154602296692269830_1903424587" + self.cl.media_id(3258619191829745894), "3258619191829745894_25025320" ) def test_media_pk(self): self.assertEqual( - self.cl.media_pk("2154602296692269830_1903424587"), 2154602296692269830 + self.cl.media_pk("2154602296692269830_25025320"), "2154602296692269830" ) def test_media_pk_from_code(self): @@ -503,6 +504,49 @@ def test_media_pk_from_url(self): 2278584739065882267, ) + +class ClientMediaExtendTestCase(ClientPrivateTestCase): + def test_media_user(self): + user = self.cl.media_user(2154602296692269830) + self.assertIsInstance(user, UserShort) + for key, val in { + "pk": "25025320", + "username": "instagram", + "full_name": "Instagram", + "is_private": False, + }.items(): + self.assertEqual(getattr(user, key), val) + self.assertTrue(user.profile_pic_url.startswith("https://")) + + def test_media_oembed(self): + media_oembed = self.cl.media_oembed("https://www.instagram.com/p/B3mr1-OlWMG/") + self.assertIsInstance(media_oembed, MediaOembed) + for key, val in { + "title": "ะ’ ะณะพัั‚ัั… ัƒ ะ”ะš @delai_krasivo_kaifui", + "author_name": "instagram", + "author_url": "https://www.instagram.com/instagram", + "author_id": "25025320", + "media_id": "2154602296692269830_25025320", + "width": 658, + "height": None, + "thumbnail_width": 640, + "thumbnail_height": 480, + "can_view": True, + }.items(): + self.assertEqual(getattr(media_oembed, key), val) + self.assertTrue(media_oembed.thumbnail_url.startswith("http")) + + def test_media_likers(self): + media = self.cl.user_medias(self.cl.user_id, amount=3)[-1] + self.assertIsInstance(media, Media) + likers = self.cl.media_likers(media.pk) + self.assertTrue(len(likers) > 0) + self.assertIsInstance(likers[0], UserShort) + + def test_media_like_by_pk(self): + media_pk = self.cl.media_pk_from_url("https://www.instagram.com/p/ByU3LAslgWY/") + self.assertTrue(self.cl.media_like(media_pk)) + def test_media_edit(self): # Upload photo media_pk = self.cl.media_pk_from_url("https://www.instagram.com/p/BVDOOolFFxg/") @@ -559,40 +603,6 @@ def test_media_edit_igtv(self): finally: cleanup(path) - def test_media_user(self): - user = self.cl.media_user(2154602296692269830) - self.assertIsInstance(user, UserShort) - for key, val in { - "pk": 1903424587, - "username": "example", - "full_name": "Example Example", - "is_private": False, - }.items(): - self.assertEqual(getattr(user, key), val) - self.assertTrue(user.profile_pic_url.startswith("https://")) - - def test_media_oembed(self): - media_oembed = self.cl.media_oembed("https://www.instagram.com/p/B3mr1-OlWMG/") - self.assertIsInstance(media_oembed, MediaOembed) - for key, val in { - "title": "ะ’ ะณะพัั‚ัั… ัƒ ะ”ะš @delai_krasivo_kaifui", - "author_name": "example", - "author_url": "https://www.instagram.com/example", - "author_id": 1903424587, - "media_id": "2154602296692269830_1903424587", - "width": 658, - "height": None, - "thumbnail_width": 640, - "thumbnail_height": 480, - "can_view": True, - }.items(): - self.assertEqual(getattr(media_oembed, key), val) - self.assertTrue(media_oembed.thumbnail_url.startswith("http")) - - def test_media_like_by_pk(self): - media_pk = self.cl.media_pk_from_url("https://www.instagram.com/p/ByU3LAslgWY/") - self.assertTrue(self.cl.media_like(media_pk)) - def test_media_like_and_unlike(self): media_pk = self.cl.media_pk_from_url("https://www.instagram.com/p/B3mr1-OlWMG/") self.assertTrue(self.cl.media_unlike(media_pk)) @@ -608,23 +618,16 @@ def test_media_like_and_unlike(self): media = self.cl.media_info_v1(media_pk) # refresh after unlike self.assertEqual(media.like_count, like_count) - def test_media_likers(self): - media = self.cl.user_medias(self.cl.user_id, amount=3)[-1] - self.assertIsInstance(media, Media) - likers = self.cl.media_likers(media.pk) - self.assertTrue(len(likers) > 0) - self.assertIsInstance(likers[0], UserShort) - class ClientCommentTestCase(ClientPrivateTestCase): def test_media_comments_amount(self): - comments = self.cl.media_comments(2154602296692269830, amount=2) + comments = self.cl.media_comments_v1(2154602296692269830, amount=2) self.assertTrue(len(comments) == 2) - comments = self.cl.media_comments(2154602296692269830, amount=0) + comments = self.cl.media_comments_v1(2154602296692269830, amount=0) self.assertTrue(len(comments) > 2) def test_media_comments(self): - comments = self.cl.media_comments(2154602296692269830) + comments = self.cl.media_comments_v1(2154602296692269830) self.assertTrue(len(comments) > 5) comment = comments[0] self.assertIsInstance(comment, Comment) @@ -640,10 +643,12 @@ def test_media_comments(self): ]: self.assertIn(field, user_fields) + +class ClientCommentExtendTestCase(ClientPrivateTestCase): def test_media_comment(self): text = "Test text [%s]" % datetime.now().strftime("%s") now = datetime.now(tz=UTC()) - comment = self.cl.media_comment(2276404890775267248, text) + comment = self.cl.media_comment_v1(2276404890775267248, text) self.assertIsInstance(comment, Comment) comment = comment.dict() for key, val in { @@ -661,7 +666,7 @@ def test_media_comment(self): def test_comment_like_and_unlike(self): media_pk = self.cl.media_pk_from_url("https://www.instagram.com/p/B3mr1-OlWMG/") - comment = self.cl.media_comments(media_pk)[0] + comment = self.cl.media_comments_v1(media_pk)[0] if comment.has_liked: self.assertTrue(self.cl.comment_unlike(comment.pk)) like_count = int(comment.like_count) @@ -737,8 +742,8 @@ def test_two_extract_media_igtv(self): self.assertMedia(media_v1, media_gql) def test_two_extract_user(self): - user_v1 = self.cl.user_info_v1(1903424587) - user_gql = self.cl.user_info_gql(1903424587) + user_v1 = self.cl.user_info_v1(25025320) + user_gql = self.cl.user_info_gql(25025320) self.assertIsInstance(user_v1, User) self.assertIsInstance(user_gql, User) user_v1, user_gql = user_v1.dict(), user_gql.dict() @@ -758,7 +763,7 @@ def test_extract_media_photo(self): for key, val in { "caption_text": "ะ’ ะณะพัั‚ัั… ัƒ ะ”ะš @delai_krasivo_kaifui", "thumbnail_url": "https://", - "pk": 2154602296692269830, + "pk": "2154602296692269830", "code": "B3mr1-OlWMG", "media_type": 1, "taken_at": datetime(2019, 10, 14, 15, 57, 10, tzinfo=UTC()), @@ -767,7 +772,7 @@ def test_extract_media_photo(self): self.assertTrue(getattr(media, key).startswith(val)) else: self.assertEqual(getattr(media, key), val) - for key, val in {"pk": 1903424587, "username": "example"}.items(): + for key, val in {"pk": "25025320", "username": "instagram"}.items(): self.assertEqual(getattr(media.user, key), val) def test_extract_media_video(self): @@ -791,7 +796,7 @@ def test_extract_media_video(self): self.assertTrue(getattr(media, key).startswith(val)) else: self.assertEqual(getattr(media, key), val) - for key, val in {"pk": 1903424587, "username": "example"}.items(): + for key, val in {"pk": "25025320", "username": "instagram"}.items(): self.assertEqual(getattr(media.user, key), val) def test_extract_media_album(self): @@ -814,7 +819,7 @@ def test_extract_media_album(self): "product_type": "", }.items(): self.assertEqual(getattr(media, key), val) - for key, val in {"pk": 1903424587, "username": "example"}.items(): + for key, val in {"pk": "25025320", "username": "instagram"}.items(): self.assertEqual(getattr(media.user, key), val) for key, val in { "video_url": "https://", @@ -862,7 +867,7 @@ def test_extract_media_igtv(self): self.assertTrue(getattr(media, key).startswith(val)) else: self.assertEqual(getattr(media, key), val) - for key, val in {"pk": 1903424587, "username": "example"}.items(): + for key, val in {"pk": "25025320", "username": "instagram"}.items(): self.assertEqual(getattr(media.user, key), val) @@ -949,8 +954,8 @@ def test_album_upload(self): paths = self.cl.album_download(media_pk) [self.assertIsInstance(path, Path) for path in paths] try: - example = self.cl.user_info_by_username("example") - usertag = Usertag(user=example, x=0.5, y=0.5) + instagram = self.user_info_by_username("instagram") + usertag = Usertag(user=instagram, x=0.5, y=0.5) location = self.get_location() media = self.cl.album_upload( paths, "Test caption for album", usertags=[usertag], location=location @@ -1073,15 +1078,15 @@ def test_direct_thread(self): # self.assertTrue(thread.is_seen(self.cl.user_id)) message = messages[0] self.assertIsInstance(message, DirectMessage) - example = self.cl.user_id_from_username("example") - ping = self.cl.direct_send("Ping", user_ids=[example]) + instagram = self.user_id_from_username("instagram") + ping = self.cl.direct_send("Ping", user_ids=[instagram]) self.assertIsInstance(ping, DirectMessage) pong = self.cl.direct_answer(ping.thread_id, "Pong") self.assertIsInstance(pong, DirectMessage) self.assertEqual(ping.thread_id, pong.thread_id) # send direct photo photo = self.cl.direct_send_photo( - path="examples/kanada.jpg", user_ids=[example] + path="examples/kanada.jpg", user_ids=[instagram] ) self.assertIsInstance(photo, DirectMessage) self.assertEqual(photo.thread_id, pong.thread_id) @@ -1096,16 +1101,16 @@ def test_direct_thread(self): self.assertTrue(self.cl.direct_thread_unmute_video_call(thread.id)) def test_direct_send_photo(self): - example = self.cl.user_id_from_username("example") - dm = self.cl.direct_send_photo(path="examples/kanada.jpg", user_ids=[example]) + instagram = self.user_id_from_username("instagram") + dm = self.cl.direct_send_photo(path="examples/kanada.jpg", user_ids=[instagram]) self.assertIsInstance(dm, DirectMessage) def test_direct_send_video(self): - example = self.cl.user_id_from_username("example") + instagram = self.user_id_from_username("instagram") path = self.cl.video_download( self.cl.media_pk_from_url("https://www.instagram.com/p/B3rFQPblq40/") ) - dm = self.cl.direct_send_video(path=path, user_ids=[example]) + dm = self.cl.direct_send_video(path=path, user_ids=[instagram]) self.assertIsInstance(dm, DirectMessage) def test_direct_thread_by_participants(self): @@ -1134,10 +1139,10 @@ def test_account_change_picture(self): # current one = self.cl.user_info(self.cl.user_id) self.assertIsInstance(one, User) - example = self.cl.user_info_by_username("example") + instagram = self.user_info_by_username("instagram") # change two = self.cl.account_change_picture( - self.cl.photo_download_by_url(example.profile_pic_url) + self.cl.photo_download_by_url(instagram.profile_pic_url) ) self.assertIsInstance(two, UserShort) # return back @@ -1254,41 +1259,41 @@ class ClientHashtagTestCase(ClientPrivateTestCase): ] def test_hashtag_info(self): - hashtag = self.cl.hashtag_info("dhbastards") + hashtag = self.cl.hashtag_info("instagram") self.assertIsInstance(hashtag, Hashtag) - self.assertEqual("dhbastards", hashtag.name) + self.assertEqual("instagram", hashtag.name) def test_extract_hashtag_info(self): - hashtag_a1 = self.cl.hashtag_info_a1("dhbastards") - hashtag_v1 = self.cl.hashtag_info_v1("dhbastards") + hashtag_a1 = self.cl.hashtag_info_a1("instagram") + hashtag_v1 = self.cl.hashtag_info_v1("instagram") self.assertIsInstance(hashtag_a1, Hashtag) self.assertIsInstance(hashtag_v1, Hashtag) - self.assertEqual("dhbastards", hashtag_a1.name) + self.assertEqual("instagram", hashtag_a1.name) self.assertEqual(hashtag_a1.id, hashtag_v1.id) self.assertEqual(hashtag_a1.name, hashtag_v1.name) self.assertEqual(hashtag_a1.media_count, hashtag_v1.media_count) def test_hashtag_medias_top(self): - medias = self.cl.hashtag_medias_top("dhbastards", amount=2) + medias = self.cl.hashtag_medias_top("instagram", amount=2) self.assertEqual(len(medias), 2) self.assertIsInstance(medias[0], Media) def test_extract_hashtag_medias_top(self): - medias_a1 = self.cl.hashtag_medias_top_a1("dhbastards", amount=9) - medias_v1 = self.cl.hashtag_medias_top_v1("dhbastards", amount=9) + medias_a1 = self.cl.hashtag_medias_top_a1("instagram", amount=9) + medias_v1 = self.cl.hashtag_medias_top_v1("instagram", amount=9) self.assertEqual(len(medias_a1), 9) self.assertIsInstance(medias_a1[0], Media) self.assertEqual(len(medias_v1), 9) self.assertIsInstance(medias_v1[0], Media) def test_hashtag_medias_recent(self): - medias = self.cl.hashtag_medias_recent("dhbastards", amount=2) + medias = self.cl.hashtag_medias_recent("instagram", amount=2) self.assertEqual(len(medias), 2) self.assertIsInstance(medias[0], Media) def test_extract_hashtag_medias_recent(self): - medias_v1 = self.cl.hashtag_medias_recent_v1("dhbastards", amount=31) - medias_a1 = self.cl.hashtag_medias_recent_a1("dhbastards", amount=31) + medias_v1 = self.cl.hashtag_medias_recent_v1("instagram", amount=31) + medias_a1 = self.cl.hashtag_medias_recent_a1("instagram", amount=31) self.assertEqual(len(medias_a1), 31) self.assertIsInstance(medias_a1[0], Media) self.assertEqual(len(medias_v1), 31) @@ -1319,7 +1324,7 @@ def test_extract_hashtag_medias_recent(self): class ClientStoryTestCase(ClientPrivateTestCase): def test_story_pk_from_url(self): story_pk = self.cl.story_pk_from_url( - "https://www.instagram.com/stories/dhbastards/2581281926631793076/" + "https://www.instagram.com/stories/instagram/2581281926631793076/" ) self.assertEqual(story_pk, 2581281926631793076) @@ -1328,12 +1333,12 @@ def test_upload_photo_story(self): path = self.cl.photo_download(media_pk) self.assertIsInstance(path, Path) caption = "Test photo caption" - example = self.cl.user_info_by_username("example") - self.assertIsInstance(example, User) - mentions = [StoryMention(user=example)] + instagram = self.user_info_by_username("instagram") + self.assertIsInstance(instagram, User) + mentions = [StoryMention(user=instagram)] medias = [StoryMedia(media_pk=media_pk, x=0.5, y=0.5, width=0.6, height=0.8)] - links = [StoryLink(webUri="https://example.org/")] - # hashtags = [StoryHashtag(hashtag=self.cl.hashtag_info('dhbastards'))] + links = [StoryLink(webUri="https://instagram.com/")] + # hashtags = [StoryHashtag(hashtag=self.cl.hashtag_info('instagram'))] # locations = [ # StoryLocation( # location=Location( @@ -1383,12 +1388,12 @@ def test_upload_video_story(self): path = self.cl.video_download(media_pk) self.assertIsInstance(path, Path) caption = "Test video caption" - example = self.cl.user_info_by_username("example") - self.assertIsInstance(example, User) - mentions = [StoryMention(user=example)] + instagram = self.user_info_by_username("instagram") + self.assertIsInstance(instagram, User) + mentions = [StoryMention(user=instagram)] medias = [StoryMedia(media_pk=media_pk, x=0.5, y=0.5, width=0.6, height=0.8)] - links = [StoryLink(webUri="https://example.org/")] - # hashtags = [StoryHashtag(hashtag=self.cl.hashtag_info('dhbastards'))] + links = [StoryLink(webUri="https://instagram.com/")] + # hashtags = [StoryHashtag(hashtag=self.cl.hashtag_info('instagram'))] # locations = [ # StoryLocation( # location=Location( @@ -1425,18 +1430,18 @@ def test_upload_video_story(self): self.assertTrue(self.cl.story_delete(story.id)) def test_user_stories(self): - user_id = self.cl.user_id_from_username("dhbastards") + user_id = self.user_id_from_username("instagram") stories = self.cl.user_stories(user_id, 2) self.assertEqual(len(stories), 2) story = stories[0] self.assertIsInstance(story, Story) for field in REQUIRED_STORY_FIELDS: self.assertTrue(hasattr(story, field)) - stories = self.cl.user_stories(self.cl.user_id_from_username("example")) + stories = self.cl.user_stories(self.user_id_from_username("instagram")) self.assertIsInstance(stories, list) def test_extract_user_stories(self): - user_id = self.cl.user_id_from_username("dhbastards") + user_id = self.user_id_from_username("instagram") stories_v1 = self.cl.user_stories_v1(user_id, amount=2) stories_gql = self.cl.user_stories_gql(user_id, amount=2) self.assertEqual(len(stories_v1), 2) @@ -1487,7 +1492,7 @@ def test_extract_user_stories(self): self.assertEqual(gql_val, v1_val) def test_story_info(self): - user_id = self.cl.user_id_from_username("dhbastards") + user_id = self.user_id_from_username("instagram") stories = self.cl.user_stories(user_id, amount=1) story = self.cl.story_info(stories[0].pk) self.assertIsInstance(story, Story) @@ -1524,14 +1529,14 @@ def test_totp_code(self): class ClientHighlightTestCase(ClientPrivateTestCase): def test_highlight_pk_from_url(self): highlight_pk = self.cl.highlight_pk_from_url( - "https://www.instagram.com/stories/highlights/17933911816568671/" + "https://www.instagram.com/stories/highlights/17983407089364361/" ) - self.assertEqual(highlight_pk, 17933911816568671) + self.assertEqual(highlight_pk, "17983407089364361") def test_highlight_info(self): - highlight = self.cl.highlight_info(17933911816568671) + highlight = self.cl.highlight_info(17983407089364361) self.assertIsInstance(highlight, Highlight) - self.assertEqual(highlight.pk, 17933911816568671) + self.assertEqual(highlight.pk, "17983407089364361") self.assertTrue(len(highlight.items) > 0) self.assertEqual(len(highlight.items), highlight.media_count) self.assertEqual(len(highlight.items), len(highlight.media_ids)) @@ -1547,18 +1552,18 @@ def test_share_info_by_url(self): url = "https://www.instagram.com/s/aGlnaGxpZ2h0OjE3OTMzOTExODE2NTY4Njcx?utm_medium=share_sheet" share = self.cl.share_info_by_url(url) self.assertIsInstance(share, Share) - self.assertEqual(share.pk, 17933911816568671) + self.assertEqual(share.pk, "17933911816568671") self.assertEqual(share.type, "highlight") def test_share_info(self): share = self.cl.share_info("aGlnaGxpZ2h0OjE3OTMzOTExODE2NTY4Njcx") self.assertIsInstance(share, Share) - self.assertEqual(share.pk, 17933911816568671) + self.assertEqual(share.pk, "17933911816568671") self.assertEqual(share.type, "highlight") # UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 6: invalid start byte share = self.cl.share_info("aGlnaGxpsdsdZ2h0OjE3OTg4MDg5NjI5MzgzNzcw") self.assertIsInstance(share, Share) - self.assertEqual(share.pk, 17988089629383770) + self.assertEqual(share.pk, "17988089629383770") self.assertEqual(share.type, "highlight")