Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
fix error in DM tests. update pep8 section for linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylow committed Dec 31, 2018
1 parent 4718feb commit 1889978
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ lint:
pycodestyle --config={toxinidir}/setup.cfg twitter tests

test: lint
python setup.py test
pytest -s
#python setup.py test

tox: clean
tox
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ ignore =
[flake8]
ignore = E111,E124,E126,E221,E501

[pycodestyle]
[pep8]
ignore = E111,E124,E126,E221,E501
max-line-length = 100
28 changes: 11 additions & 17 deletions tests/test_direct_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@

from __future__ import unicode_literals, print_function

import json
import os
import re
import sys
from tempfile import NamedTemporaryFile
import unittest
try:
from unittest.mock import patch
except ImportError:
from mock import patch
import warnings

import twitter

import responses
from responses import GET, POST

DEFAULT_URL = re.compile(r'https?://.*\.twitter.com/1\.1/.*')
DEFAULT_BASE_URL = re.compile(r'https?://api\.twitter.com/1\.1/.*')
DEFAULT_UPLOAD_URL = re.compile(r'https?://upload\.twitter.com/1\.1/.*')

global api
api = twitter.Api('test', 'test', 'test', 'test', tweet_mode='extended')
Expand All @@ -30,7 +21,7 @@
def test_get_direct_messages():
with open('testdata/direct_messages/get_direct_messages.json') as f:
resp_data = f.read()
responses.add(GET, DEFAULT_URL, body=resp_data)
responses.add(GET, DEFAULT_BASE_URL, body=resp_data)

resp = api.GetDirectMessages(count=1, page=1)
direct_message = resp[0]
Expand All @@ -49,7 +40,7 @@ def test_get_direct_messages():
def test_get_sent_direct_messages():
with open('testdata/direct_messages/get_sent_direct_messages.json') as f:
resp_data = f.read()
responses.add(GET, DEFAULT_URL, body=resp_data)
responses.add(GET, DEFAULT_BASE_URL, body=resp_data)

resp = api.GetSentDirectMessages(count=1, page=1)
direct_message = resp[0]
Expand All @@ -61,7 +52,7 @@ def test_get_sent_direct_messages():
@responses.activate
def test_post_direct_message():
with open('testdata/direct_messages/post_post_direct_message.json', 'r') as f:
responses.add(POST, DEFAULT_URL, body=f.read())
responses.add(POST, DEFAULT_BASE_URL, body=f.read())
resp = api.PostDirectMessage(user_id='372018022',
text='hello')
assert isinstance(resp, twitter.DirectMessage)
Expand All @@ -71,10 +62,13 @@ def test_post_direct_message():
@responses.activate
def test_post_direct_message_with_media():
with open('testdata/direct_messages/post_post_direct_message.json', 'r') as f:
responses.add(POST, DEFAULT_URL, body=f.read())
responses.add(POST, DEFAULT_BASE_URL, body=f.read())
with open('testdata/post_upload_chunked_INIT.json') as f:
responses.add(POST, DEFAULT_UPLOAD_URL, body=f.read())

resp = api.PostDirectMessage(user_id='372018022',
text='hello',
media_file_path='testdata/media/happy.png',
media_file_path='testdata/media/happy.jpg',
media_type='dm_image')
assert isinstance(resp, twitter.DirectMessage)
assert resp.text == 'hello'
Expand All @@ -83,7 +77,7 @@ def test_post_direct_message_with_media():
@responses.activate
def test_destroy_direct_message():
with open('testdata/direct_messages/post_destroy_direct_message.json', 'r') as f:
responses.add(POST, DEFAULT_URL, body=f.read())
responses.add(POST, DEFAULT_BASE_URL, body=f.read())
resp = api.DestroyDirectMessage(message_id=855194351294656515)

assert isinstance(resp, twitter.DirectMessage)
Expand Down
2 changes: 1 addition & 1 deletion twitter/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ def _UploadMediaChunkedInit(self,
if additional_owners and len(additional_owners) > 100:
raise TwitterError({'message': 'Maximum of 100 additional owners may be specified for a Media object'})
if additional_owners:
parameters['additional_owners'] = ','.join(map(str,additional_owners))
parameters['additional_owners'] = ','.join(map(str, additional_owners))
if media_category:
parameters['media_category'] = media_category

Expand Down

0 comments on commit 1889978

Please sign in to comment.