Skip to content

Commit

Permalink
Hacky test for checking correct tweeting directly from the project
Browse files Browse the repository at this point in the history
  • Loading branch information
nahuelhds committed May 26, 2020
1 parent 7f168c8 commit 46d8bbd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TEST_DATABASE_URL=postgres://nsotelo@localhost/diffengine_test?autorollback=true
TEST_CONSUMER_KEY=XOPVgJv5pWFVzru2QekheieNE
TEST_CONSUMER_SECRET=xKJgA6yCn8KR9Xn5EZ8AskW8Ki3DaADEkmOrHpQJrf7icMLvfD
TEST_ACCESS_TOKEN=1251342388813090816-boWeRcbEjQpkKXVxNSOHeQtrJCcWZH
TEST_ACCESS_TOKEN_SECRET=18SVyF10ZxbqXMJIUj63aH9FeGlPURIie1aGIehFvzByp
7 changes: 7 additions & 0 deletions config-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
db: "${TEST_DATABASE_URL}"
twitter:
consumer_key: "${TEST_CONSUMER_KEY}"
consumer_secret: "${TEST_CONSUMER_SECRET}"
token:
access_token: "${TEST_ACCESS_TOKEN}"
access_token_secret: "${TEST_ACCESS_TOKEN_SECRET}"
5 changes: 5 additions & 0 deletions diffengine/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ def tweet_diff(self, diff, token=None, lang={}):
diff.save()
except Exception as e:
logging.error("unable to tweet: %s", e)

def delete_diff(self, diff, token=None):
twitter = self.api(token)
twitter.destroy_status(diff.old.tweet_status_id_str)
twitter.destroy_status(diff.new.tweet_status_id_str)
30 changes: 29 additions & 1 deletion test_diffengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import re
import yaml
from envyaml import EnvYAML

import setup
import pytest
import shutil
Expand Down Expand Up @@ -43,6 +45,7 @@
)

test_home = "test"
test_config = EnvYAML("config-test.yaml", env_file=".env")

if os.path.isdir(test_home):
shutil.rmtree(test_home)
Expand All @@ -66,7 +69,7 @@ class FeedTest(TestCase):
version = None

def setUp(self) -> None:
generate_config(test_home, {"db": "sqlite:///:memory:"})
generate_config(test_home, {"db": test_config.get("db", "sqlite:///:memory:")})
# set things up but disable prompting for initial feed
init(test_home, prompt=False)
self.feed = Feed.create(name="Test", url="https://inkdroid.org/feed.xml")
Expand Down Expand Up @@ -111,6 +114,31 @@ def test_diff(self):
"^https://web.archive.org/web/diff/\\d+/\\d+/https.+$", diff.url
)

def test_tweet_diff(self):
e = self.entry
v1 = e.versions[0]

# remove some characters from the version
v1.summary = v1.summary[0:-20]
v1.save()

v2 = e.get_latest()

# Actual tweeting purposes only
# run this alone for checking correct tweeting behavior
if v2 is not None:
diff = v2.diff
try:
token = test_config.get("twitter.token")
twitter_handler = TwitterHandler(
test_config.get("twitter.consumer_key"),
test_config.get("twitter.consumer_secret"),
)
twitter_handler.tweet_diff(diff, token)
twitter_handler.delete_diff(diff, token)
except Exception:
logging.debug("no tweet configured for test. Doing nothing")

def test_html_diff(self):
e = self.entry

Expand Down

0 comments on commit 46d8bbd

Please sign in to comment.