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 directory #73

Merged
merged 6 commits into from May 20, 2018
Merged

Tests directory #73

merged 6 commits into from May 20, 2018

Conversation

@Inveracity
Copy link
Contributor

Inveracity commented May 20, 2018

pipenv run test
Copy link
Member

jchristgit left a comment

some thoughts and ideas

try:
del os.environ["FLASK_DEBUG"] # Some unit tests fail if this is set
except KeyError:
pass

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

Probably just me, but I think just checking whether it exists would be a fair bit cleaner.

if "FLASK_DEBUG" in os.environ:
    del os.environ["FLASK_DEBUG"]  # Some unit tests fail if this is set

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

good point!

@@ -0,0 +1,25 @@
from tests import SiteTest, app

class ApiEndpointsRootEndpoints(SiteTest):

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

doesn't flake8 demand two newlines before this?

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

skipping

- snake_idioms
- snake_facts
"""
os.environ['BOT_API_KEY'] = 'abcdefg'

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

why is this in the class?

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

fixed 👍

try:
try_json_type("not json")
except Exception as error_message:
self.assertEqual(type(error_message), AttributeError)

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

how about assertRaises instead?

with self.assertRaises(AttributeError):
    try_json_type("not json")

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

I like it, sorted 👍

rv.setup(manager, 'sdfsdf')
except RuntimeError:
return True
raise Exception('Expected runtime error on setup() when giving wrongful arguments')

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

this would probably also be nicer with self.assertRaises

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

done! 👍


def test_logout(self):
""" Make sure at least apart of logout is working :/ """
self.assertIs(manager.oauth_backend.logout(), None)

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

these would probably all be cleaner with the assertIsNone as shown above

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

triple done 👍

def test_error(self):
""" Check the /error/XYZ page """
response = self.client.get('/error/418')
self.assertEqual(response.status_code, 418)

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

this only checks a single error page, i'm not sure if it's desired, but how about checking all of them with something like

for code in HANDLED_ERROR_CODES:
    response = self.client.get(f'/error/{code}')
    self.assertEqual(response.status_code, code)

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

The other status codes are satisfied in other tests, but I do like this, so I'm gonna try it

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

looped done 👍

ev.setup(manager, 'sdfsdf')
except RuntimeError:
return True
raise Exception('Expected runtime error on setup() when giving wrongful arguments')

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

this might also benefit from self.assertRaises

TestWS(None).on_message("test")
return False
except NotImplementedError:
return True

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

what would return True / return False do in a test? self.assertRaises is probably also wanted here?

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

I don't know who wrote this, so I'm gonna skip it

@@ -2,5 +2,5 @@
max-line-length=120
application_import_names=pysite
ignore=P102,B311,W503,E226,S311
exclude=__pycache__, venv, app_test.py, .venv
exclude=__pycache__, venv, .venv, tests

This comment has been minimized.

@jchristgit

jchristgit May 20, 2018

Member

this is flake8, right? why do we exclude tests from linting?

This comment has been minimized.

@Inveracity

Inveracity May 20, 2018

Author Contributor

we exclude tests from linting because some tests require some terrible python code that flake8 really dislikes

Copy link
Member

jchristgit left a comment

👍

@Inveracity Inveracity merged commit 687fedf into master May 20, 2018
2 checks passed
2 checks passed
Travis CI - Pull Request Build Passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Inveracity Inveracity deleted the tests-directory branch May 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.