Squashed commit of the following:

Updated the supported python versions list.
    Fixed regression in displaying xposts. #173.
    Fixing a few style things.
    Added a more robust test for the tornado handler.
    Trying without pytest-cov
    Updated travis for coverage.
    Remove python 3.2 support because no unicode literals, following what praw supports.
    "Side effect is not iterable."
    Added requirements for travis.
    Renamed travis file correctly.
    Adding test configurations, got tox working.
    Adding vcr cassettes to the repo.
    Renamed requirements files.
    Split up tests and cleaned up test names.
    Tests done, still one failure.
    Treat cassettes as binary to prevent bad merging.
    Fixed a few broken tests.
    Added a timeout to notifications.
    Prepping subreddit page.
    Finished submission page tests.
    Working on submission tests.
    Fixed vcr matching on urls with params, started submission tests.
    Log cleanup.
    Still trying to fix a broken test.
    -Fixed a few pytest bugs and tweaked logging.
    Still working on subscription tests.
    Finished page tests, on to subscription page.
    Finished content tests and starting page tests.
    Added the test refresh-token file to gitignore.
    Moved functional test file out of the repository.
    Continuing work on subreddit content tests.
    Tests now match module names, cassettes are split into individual tests for faster loading.
    Linter fixes.
    Cleanup.
    Added support for nested loaders.
    Added pytest options, starting subreddit content tests.
    Back on track with loader, continuing content tests.
    Finishing submission content tests and discovered snag with loader exception handling.
    VCR up and running, continuing to implement content tests.
    Playing around with vcr.py
    Moved helper functions into terminal and new objects.py
    Fixed a few broken tests.
    Working on navigator tests.
    Reorganizing some things.
    Mocked webbrowser._tryorder for terminal test.
    Completed oauth tests.
    Progress on the oauth tests.
    Working on adding fake tornado request.
    Starting on OAuth tool tests.
    Finished curses helpers tests.
    Still working on curses helpers tests.
    Almost finished with tests on curses helpers.
    Adding tests and working on mocking stdscr.
    Starting to add tests for curses functions.
    Merge branch 'future_work' of https://github.com/michael-lazar/rtv into future_work
    Refactoring controller, still in progress.
    Renamed auth handler.
    Rename CursesHelper to CursesBase.
    Added temporary file with a possible template for func testing.
    Mixup between basename and dirname.
    Merge branch 'future_work' of https://github.com/michael-lazar/rtv into future_work
    py3 compatability for mock.
    Beginning to refactor the curses session.
    Started adding tests, improved unicode handling in the config.
    Cleanup, fixed a few typos.
    Major refactor, almost done!.
    Started a config class.
    Merge branch 'master' into future_work
    The editor now handles unicode characters in all situations.
    Fixed a few typos from previous commits.
    __main__.py formatting.
    Cleaned up history logic and moved to the config file.
This commit is contained in:
Michael Lazar
2015-12-02 22:37:50 -08:00
parent b91bb86e36
commit a7b789bfd9
70 changed files with 42141 additions and 1560 deletions

143
tests/test_config.py Normal file
View File

@@ -0,0 +1,143 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import codecs
from tempfile import NamedTemporaryFile
from rtv.config import Config
try:
from unittest import mock
except ImportError:
import mock
def test_config_interface():
"Test setting and removing values"
config = Config(ascii=True)
assert config['ascii'] is True
config['ascii'] = False
assert config['ascii'] is False
config['ascii'] = True
del config['ascii']
assert config['ascii'] is False
config.update(subreddit='cfb', new_value=2.0)
assert config['subreddit'] == 'cfb'
assert config['new_value'] == 2.0
def test_config_from_args():
"Ensure that command line arguments are parsed properly"
args = ['rtv',
'-s', 'cfb',
'-l', 'https://reddit.com/permalink •',
'--log', 'logfile.log',
'--ascii',
'--non-persistent',
'--clear-auth']
with mock.patch('sys.argv', ['rtv']):
config = Config()
config.from_args()
assert config.config == {}
with mock.patch('sys.argv', args):
config = Config()
config.from_args()
assert config['ascii'] is True
assert config['subreddit'] == 'cfb'
assert config['link'] == 'https://reddit.com/permalink •'
assert config['log'] == 'logfile.log'
assert config['ascii'] is True
assert config['persistent'] is False
assert config['clear_auth'] is True
def test_config_from_file():
"Ensure that config file arguments are parsed properly"
args = {
'ascii': True,
'persistent': False,
'clear_auth': True,
'log': 'logfile.log',
'link': 'https://reddit.com/permalink •',
'subreddit': 'cfb'}
with NamedTemporaryFile(suffix='.cfg') as fp:
config = Config(config_file=fp.name)
config.from_file()
assert config.config == {}
rows = ['{0}={1}'.format(key, val) for key, val in args.items()]
data = '\n'.join(['[rtv]'] + rows)
fp.write(codecs.encode(data, 'utf-8'))
fp.flush()
config.from_file()
assert config.config == args
def test_config_refresh_token():
"Ensure that the refresh token can be loaded, saved, and removed"
with NamedTemporaryFile(delete=False) as fp:
config = Config(token_file=fp.name)
# Write a new token to the file
config.refresh_token = 'secret_value'
config.save_refresh_token()
# Load a valid token from the file
config.refresh_token = None
config.load_refresh_token()
assert config.refresh_token == 'secret_value'
# Discard the token and delete the file
config.delete_refresh_token()
assert config.refresh_token is None
assert not os.path.exists(fp.name)
# Saving should create a new file
config.refresh_token = 'new_value'
config.save_refresh_token()
# Which we can read back to verify
config.refresh_token = None
config.load_refresh_token()
assert config.refresh_token == 'new_value'
# And delete again to clean up
config.delete_refresh_token()
assert not os.path.exists(fp.name)
# Loading from the non-existent file should return None
config.refresh_token = 'secret_value'
config.load_refresh_token()
assert config.refresh_token is None
def test_config_history():
"Ensure that the history can be loaded and saved"
with NamedTemporaryFile(delete=False) as fp:
config = Config(history_file=fp.name, history_size=3)
config.history.add('link1')
config.history.add('link2')
config.history.add('link3')
config.history.add('link4')
assert len(config.history) == 4
# Saving should only write the 3 most recent links
config.save_history()
config.load_history()
assert len(config.history) == 3
assert 'link1' not in config.history
assert 'link4' in config.history
config.delete_history()
assert len(config.history) == 0
assert not os.path.exists(fp.name)