Skip to content

Commit

Permalink
Run flake8 against tests
Browse files Browse the repository at this point in the history
  • Loading branch information
osteele committed May 4, 2018
1 parent 7560950 commit acdea31
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install:

script:
- pipenv run coverage run --source abe -m unittest
- pipenv run flake8 abe *.py
- pipenv run flake8 abe tests *.py

after_success:
- codecov
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ $ open htmlcov/index.html
Lint all the things:

```shell
$ flake8 abe *.py
$ flake8 abe tests *.py
```

## API Documentation
Expand Down
1 change: 0 additions & 1 deletion tests/abe_unittest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import unittest

from pymongo import MongoClient
Expand Down
4 changes: 0 additions & 4 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
This test suite requires a local mongodb instance and writes to/drops a
database named "abe-unittest" for testing.
"""
import os
import unittest

import flask
from pymongo import MongoClient

from . import abe_unittest
from .context import abe # noqa: F401
Expand Down
10 changes: 3 additions & 7 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
"""
import os
import unittest
import sys
from importlib import reload

import flask
from flask import request
from werkzeug.exceptions import HTTPException

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from abe import auth
from abe import auth # # noqa: F401

app = flask.Flask(__name__)


class AuthTestCase(unittest.TestCase):

def test_intranet_ips(self):
global auth
os.environ['INTRANET_IPS'] = '127.0.0.1/24'
Expand Down Expand Up @@ -75,6 +74,3 @@ def route():
headers={'X-Forwarded-For': '127.0.0.1,192.168.0.1'}):
with self.assertRaises(HTTPException) as http_error:
route()

if __name__ == '__main__':
unittest.main()
19 changes: 6 additions & 13 deletions tests/test_email_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import skip
from unittest.mock import Mock, patch, ANY
import email
from unittest.mock import ANY, Mock, patch

from icalendar import Calendar

from . import abe_unittest
Expand All @@ -15,8 +15,8 @@
with open('./tests/cal_script.txt', 'r') as cal_file:
cal = Calendar.from_ical(cal_file.read())

class EmailHelpersTestCase(abe_unittest.TestCase):

class EmailHelpersTestCase(abe_unittest.TestCase):

def test_get_msg_list(self):
message_txt = [s.encode() for s in ['first line', 'second line']]
Expand All @@ -28,14 +28,12 @@ def test_get_msg_list(self):
self.assertEqual(len(messages), 1)
self.assertEqual(messages[0].as_string(), "\nfirst line\nsecond line")


def test_ical_to_dict(self):
test_dict, test_sender = email_helpers.ical_to_dict(cal)
self.assertEqual(test_sender, 'test.case@tests.com')
self.assertEqual(test_dict['description'], 'Test Event')
self.assertEqual(test_dict['labels'], ['test'])


def test_get_messages_from_email(self):
with patch('poplib.POP3_SSL') as pop_conn_factory:
pop_conn = pop_conn_factory()
Expand All @@ -48,13 +46,11 @@ def test_get_messages_from_email(self):
pop_conn.quit.assert_called()
self.assertEqual(len(messages), 1)


def test_get_calendars_from_messages(self):
cal_list = email_helpers.get_calendars_from_messages([message])
self.assertEqual(len(cal_list), 1)
self.assertIsInstance(cal_list[0], Calendar)


@patch('abe.helper_functions.email_helpers.error_reply', return_value=None)
@patch('abe.helper_functions.email_helpers.reply_email', return_value=None)
def test_cal_to_event(self, email_error, email_reply):
Expand All @@ -65,7 +61,6 @@ def test_cal_to_event(self, email_error, email_reply):
self.assertEqual(exit_code, 201)
self.assertEqual(event_dict['description'], event['description'])


def test_smtp_connect(self):
with patch('smtplib.SMTP_SSL') as server_factory:
server = server_factory()
Expand All @@ -76,7 +71,7 @@ def test_smtp_connect(self):
server.login.assert_called()

@patch('abe.helper_functions.email_helpers.send_email', return_value=None)
@patch('abe.helper_functions.email_helpers.smtp_connect', return_value=('server','from_addr'))
@patch('abe.helper_functions.email_helpers.smtp_connect', return_value=('server', 'from_addr'))
def test_error_reply(self, smtp, send):
error = Mock()
error.errors = [12]
Expand All @@ -86,17 +81,15 @@ def test_error_reply(self, smtp, send):
smtp.assert_called()
send.assert_called_with('server', ANY, 'from_addr', to)


@patch('abe.helper_functions.email_helpers.send_email', return_value=None)
@patch('abe.helper_functions.email_helpers.smtp_connect', return_value=('server','from_addr'))
@patch('abe.helper_functions.email_helpers.smtp_connect', return_value=('server', 'from_addr'))
def test_reply_email(self, smtp, send):
event_dict = {'title':'Test', 'labels':['test'], 'description':'empty test'}
event_dict = {'title': 'Test', 'labels': ['test'], 'description': 'empty test'}
to = "to_addr"
email_helpers.reply_email(to, event_dict)
smtp.assert_called()
send.assert_called_with('server', ANY, 'from_addr', to)


def test_send_email(self):
server = Mock()
server.sendmail = Mock()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_recurrences.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from datetime import datetime

from abe.helper_functions import recurring_helpers

from . import abe_unittest
from .context import abe # noqa: F401

# This import has to happen after .context sets the environment variables
from abe.helper_functions import sub_event_helpers # isort:skip
from abe.helper_functions import recurring_helpers

# TODO: add test cases for YEARLY frequency (are there others)?
# TODO: add test cases for by_month, by_month_day
Expand Down
2 changes: 0 additions & 2 deletions tests/test_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
This test suite requires a local mongodb instance and writes to/drops a
database named "abe-unittest" for testing.
"""
import unittest

from . import abe_unittest
from .context import abe # noqa: F401

Expand Down
4 changes: 0 additions & 4 deletions tests/test_subscription_resources.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from datetime import datetime
from unittest import skip

import icalendar

from . import abe_unittest
from .context import abe # noqa: F401

# This import has to happen after .context sets the environment variables
# from abe.document_model import subscription_documents # isort:skip
from abe.resource_models import subscription_resources # isort:skip


Expand Down

0 comments on commit acdea31

Please sign in to comment.