Skip to content

Commit

Permalink
integration test, uses api_client (with API raw response mocked out) …
Browse files Browse the repository at this point in the history
…to process and store results in database. confirms that API response with null bytes is successfully stored in database.
  • Loading branch information
macpd committed Nov 20, 2024
1 parent ffc2130 commit 03ffe7e
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Tests integration of database storage of api client retrun values (using mocked http responses).
"""
import attrs
import pendulum
import pytest
import re
import responses
from sqlalchemy import (
select,
)
from sqlalchemy.orm import Session

from tests.common import (
all_crawls,
all_hashtag_names_sorted,
all_hashtags,
all_videos,
FAKE_SECRETS_YAML_FILE,
)
from tiktok_research_api_helper import api_client
from tiktok_research_api_helper.models import (
Crawl,
CrawlTag,
Effect,
Hashtag,
Video,
upsert_videos,
)
from tiktok_research_api_helper import query


@responses.activate
def test_tiktok_request_client_removes_null_chars(
basic_video_query,
basic_video_query_config,
basic_acquisition_config,
testdata_api_videos_response_unicode_json,
test_database_engine,
):
responses.post("https://open.tiktokapis.com/v2/oauth/token/", json= {
"access_token": "mock_access_token_1",
"expires_in": 7200,
"token_type": "Bearer",
})
responses.post(re.compile('https://open.tiktokapis.com/v2/*'),
json=testdata_api_videos_response_unicode_json)
request_client = api_client.TikTokApiRequestClient.from_credentials_file(
FAKE_SECRETS_YAML_FILE,
api_request_session=None,
access_token_fetcher_session=None,
)
client = api_client.TikTokApiClient(
request_client=request_client, config=attrs.evolve(basic_acquisition_config,
engine=test_database_engine)
)
client.fetch_and_store_all(basic_video_query_config)
with Session(test_database_engine) as session:
assert session.scalars(select(Video.id).order_by(Video.id)).all() == [testdata_api_videos_response_unicode_json['data']['videos'][0]['id']]

0 comments on commit 03ffe7e

Please sign in to comment.