Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests and Updates #41

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Tests and Updates #41

wants to merge 14 commits into from

Conversation

s2t2
Copy link
Contributor

@s2t2 s2t2 commented Oct 11, 2024

Maintenance Updates

  1. Implements Continuous Integration using GitHub Actions, to run tests on CI server. To make this work, you need to set the environment variables as repository secrets (see README.md). See working example here: https://github.com/s2t2/truthbrush/actions

  2. Updates to Python 3.10:

poetry env use 3.10
  1. Splits API tests into resource-specific test files, to stay organized.

Functionality Updates

  1. Improves documentation and performance of the pull_statuses method. Makes user_name an optional parameter. Removes unnecessary API call using the username - if a user_id is supplied it uses the user_id in the request instead.

  2. Improves documentation for the search method, designating which resources are valid (closes How to get a group id? #42 ).

  3. Adds a simplified search method (search_simple) which returns only the resources requested.

  4. Adds a datetime conversion utility function which is helpful when asking for posts after a given datetime.

@s2t2

This comment was marked as outdated.

@s2t2 s2t2 marked this pull request as ready for review October 13, 2024 15:55
@s2t2 s2t2 mentioned this pull request Oct 13, 2024
@lxcode lxcode requested a review from milesmcc October 13, 2024 16:18
@s2t2 s2t2 changed the title Pull Statuses - Username Optional Tests and Updates Oct 13, 2024
env:
# set environment variables using repo secrets
TRUTHSOCIAL_USERNAME: ${{ secrets.TRUTHSOCIAL_USERNAME }}
TRUTHSOCIAL_PASSWORD: ${{ secrets.TRUTHSOCIAL_PASSWORD }}
Copy link
Contributor Author

@s2t2 s2t2 Oct 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values need to be set on the upstream repo, using the repository secrets menu in the settings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the login isn't really needed: #32

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like that's maybe a change from when we first built the tool. Pretty sure it used to all be authwalled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the username and password allows us to test auth-walled functionality.

We can use a new test account if concerned about security.

@@ -153,9 +182,9 @@ def _get_paginated(self, url: str, params: dict = None, resume: str = None) -> A

def user_likes(
self, post: str, include_all: bool = False, top_num: int = 40
) -> bool | Any:
) -> Union[bool, Any]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes error by using Union

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, bool | Any is equivalent to Any; also, the return type of this function doesn't make sense to me — shouldn't this return a list of some sort?

Copy link
Contributor Author

@s2t2 s2t2 Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about type hints or this function specifically. I had run into an issue with bool | Any and that was the suggested change. I'm happy to try changing it back.

truthbrush/api.py Show resolved Hide resolved
@@ -209,14 +238,20 @@ def search(
searchtype: str = None,
query: str = None,
limit: int = 40,
resolve: bool = 4,
resolve: bool = 4, # bool = 4 ?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI not sure if bool type and default value of 4 are compatible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was the one who mistakenly introduced this: 1c74a96#diff-b8a4f09258d1b070faf6806097b4e7047930f99777e63d753dc1b03e7eae31a4R117

Needs to be changed ofc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I will change to int

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, what does the resolve do?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it needs to be a boolean (defaulted to True). Not sure what it does, changing from true to false does not change the output at all.

The params I get when executing a search in TS website are:

params = {
    'q': 'trump',
    'limit': '20',
    'resolve': 'true',
    'type': 'accounts',
}

So probably resolve needs to be 'true' if resolve else 'false' in the HTTP req. 1c74a96#diff-b8a4f09258d1b070faf6806097b4e7047930f99777e63d753dc1b03e7eae31a4R124

@@ -248,30 +283,54 @@ def search(
),
)

offset += 40
offset += 40 # use limit here?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be referencing the limit?

truthbrush/api.py Show resolved Hide resolved
@s2t2
Copy link
Contributor Author

s2t2 commented Oct 13, 2024

FYI this PR is ready for review anytime. Takes some tests and docstring updates from #38 , as requested.

from curl_cffi import requests
import curl_cffi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes error by importing this package

"""

params = {}
user_id = self.lookup(username)["id"]
user_id = user_id or self.lookup(username)["id"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skips separate request when able

@@ -209,14 +238,20 @@ def search(
searchtype: str = None,
query: str = None,
limit: int = 40,
resolve: bool = 4,
resolve: int = 4,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updates type hint



@pytest.fixture(scope="module")
def user_timeline(client):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI fixtures defined in the conftest.py can get referenced by test functions in other files.

@milesmcc
Copy link
Collaborator

Thanks! Ack, will review shortly.

Co-authored-by: Konrad Iturbe <[email protected]>
@s2t2
Copy link
Contributor Author

s2t2 commented Oct 22, 2024

I have started to see some cloudflare restricted pages. I assume when making too many requests in too short a period of time. But does anyone know what the logic is for when they appear?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to get a group id?
3 participants