{"id":21479968,"url":"https://github.com/rsmuthu/twitter_api-pytest","last_synced_at":"2025-08-24T17:39:22.740Z","repository":{"id":96068662,"uuid":"299723396","full_name":"RSMuthu/Twitter_API-Pytest","owner":"RSMuthu","description":null,"archived":false,"fork":false,"pushed_at":"2020-10-01T19:47:06.000Z","size":93,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T08:47:44.305Z","etag":null,"topics":["pytest","python","testing"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RSMuthu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-29T19:53:36.000Z","updated_at":"2022-08-06T06:18:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"7b188682-220b-4cb4-ad0e-ee18690d9c15","html_url":"https://github.com/RSMuthu/Twitter_API-Pytest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RSMuthu/Twitter_API-Pytest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RSMuthu%2FTwitter_API-Pytest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RSMuthu%2FTwitter_API-Pytest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RSMuthu%2FTwitter_API-Pytest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RSMuthu%2FTwitter_API-Pytest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RSMuthu","download_url":"https://codeload.github.com/RSMuthu/Twitter_API-Pytest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RSMuthu%2FTwitter_API-Pytest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271915421,"owners_count":24843188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pytest","python","testing"],"created_at":"2024-11-23T12:09:33.644Z","updated_at":"2025-08-24T17:39:22.736Z","avatar_url":"https://github.com/RSMuthu.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twitter_API-Pytest\n\nApplication developers should also be in good terms with testing different\nendpoints of different services/REST APIs that one builds for the work.\nThis is to demo a little work on unit testing Twitter API using pytest package of python.\nAs the unit testing task is basic, I am not writing any new pytest plugins for the purpose and just using the existing plugins.\n\n### Task List\nThe task is a simple and as follows:\n\n- Make a new tweet with the text \"We welcome you to MSD family :)\"\nNow retweet the same tweet.\n- Now get the retweet count \u0026 retweeters ID and validate the correctness of the data.\n- Now revert the previous retweet (un-retweet the above tweet) and get the retweet count \u0026 retweeters ID and validate the correctness of the data.\n- Now finally delete the tweet.\n\n### Design\nThe design for the test cases with intent to perform above task can be either,\n- __*Behaviour Driven Testing (BDD)*__\n- Test case execution on our __*given specific order*__.\n\nTo ease the work, I am preferring to order the test cases based on the task / dependency.\\\n##### Directory structure layout\nA seperate extra directory (for each module) outside your actual application code (in this case, we dont have the source code)\n```\nTwitter_API-Pytest\n|\n|--conftest.py\n|--tokens.json\n|--test_status_endpoints\n    |\n    |--test_status_retweet.py\n    |--test_status_tweet.py\n    |--utils.py\n```\n`conftest.py` -- configuration for pytest; creation of fixtures, creating custom marks, etc., are coded here.\\\n`tokens.json` -- tokens needed for API Authentication (OAuth1 is used)\\\n`test_status_endpoints` -- directory that holds the testcases for different endpoints under `/statuses/\u003cend_points\u003e`.\\\nMany more directories can be created same manner to hold testcases for multiple endpoints under another URI (example, `test_account_endpoints` to hold the testcases for endpoints under `/account/\u003cend_points\u003e`), that way, the Test project can be extended.\\\n`test_status_retweet.py` -- holds testcases for making a tweet and destroying the same tweet after done.\n`test_status_retweet` -- holds testcases for retweeting our tweet and unretweeting later. Endpoints tested/used are\n`utils.py` -- holds utilty methods that can be of common use across testcases.\n\n\n### Requirement\n- Twitter developer account - to use the READ/WRITE/SEARCH tweets (make sure to have the necessary API privilege)\n- _python 3.6+_ (I am using python 3.8)\n- _pytest_ (unit testing framework we will be using)\n- _pytest-html_  (pytest plugin: to make a report of test cases run in HTML format)\n- _pytest-ordering_ (pytest plugin: to help in ordering the test cases)\n- _requests_oauthlib_ (to help in OAuth1.0 for our API calls)\n\n### Setup\nMake sure that the python is installed (not going to cover it here). Use the below command to verify python\\\n`\u003e python --version`\n\nNow for the setup, Make sure to be in the project directory and execute the below command\\\n`Twitter_API-Pytest\u003e python -m pip install -r requirement.txt`\n\nIf you are using pipenv, use the following command\\\n`Twitter_API-Pytest\u003e pipenv install -r requirement.txt`\n\n### Usage\nThe usage is same as executing pytest on a directory with test cases\\\n(please refer to [pytest documentation](https://docs.pytest.org/en/stable/) for more details and references)\n\nMake sure to be in the project directory \u0026 use following Command to trigger pytest\\\n`Twitter_API-Pytest\u003e pytest --capture=sys -v --html=report.html`\n\nArgs of Pytest used :\\\n`--capture` - captures the console response from the testcases (alternatively we can also use file logging instead of stdout)\\\n`--html` - generates Test report from the outcome of pytest\\\n`-v` - Captures more details on the console (std) about the testcases that are executed/skipped/succeeded/failed.\n\nIf you using pipenv, use the following command\\\n`Twitter_API-Pytest\u003e pipenv run pytest --capture=sys --html=report.html`\\\nor Enter pipenv shell and execute pytest as below\n```\nTwitter_API-Pytest\u003e pipenv shell\n(Twitter_API-Pytest-VL_9mm1P) Twitter_API-Pytest\u003e pytest --capture=sys -v --html=report.html\n```\n\nThe pytest output will be as below\n```\nTwitter_API-Pytest\u003epipenv run pytest --capture=sys -v --html=report.html\n================================================= test session starts =================================================\nplatform win32 -- Python 3.8.5, pytest-6.1.0, py-1.9.0, pluggy-0.13.1 -- \u003cuser_home_dir\u003e\\.virtualenvs\\twitter_api-pytest-vl_9mm1p\\scripts\\python.exe\ncachedir: .pytest_cache\nmetadata: {'Python': '3.8.5', 'Platform': 'Windows-10-10.0.18362-SP0', 'Packages': {'pytest': '6.1.0', 'py': '1.9.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '2.1.1', 'metadata': '1.10.0', 'ordering': '0.6'}}\nrootdir: Twitter_API-Pytest\nplugins: html-2.1.1, metadata-1.10.0, ordering-0.6\ncollected 5 items\n\ntest_status_endpoints/test_status_tweet.py::test_make_tweet[We welcome you to MSD family :)] PASSED              [ 20%]\ntest_status_endpoints/test_status_tweet.py::test_make_tweet[Hello World !!] PASSED                               [ 40%]\ntest_status_endpoints/test_status_retweet.py::test_make_retweet PASSED                                           [ 60%]\ntest_status_endpoints/test_status_retweet.py::test_undo_retweet PASSED                                           [ 80%]\ntest_status_endpoints/test_status_tweet.py::test_delete_tweet PASSED                                             [100%]\n\n----------------------- generated html file: file://Twitter_API-Pytest\\report.html ------------------------\n================================================== 5 passed in 3.37s ==================================================\n\n```\n\n### Report -- sample look\n![Report is available in report.html file in this project directory](https://github.com/RSMuthu/Twitter_API-Pytest/blob/master/html_report_img.PNG)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsmuthu%2Ftwitter_api-pytest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frsmuthu%2Ftwitter_api-pytest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsmuthu%2Ftwitter_api-pytest/lists"}