def test_empty(): '''Tests User.clear with no existing data.''' user = udacity.User(USER, PW) assert_dict_equal(user.cache.data, {}) user.clear() assert_dict_equal(user.cache.data, {})
def test_filled(): '''Tests User.clear with existing data.''' user = udacity.User(USER, PW) assert_dict_equal(user.cache.data, {}) courses = user.enrollments() assert user.cache.data.get('account') is not None user.clear() assert_dict_equal(user.cache.data, {})
def test_correct(): '''Tests udacity.User with the correct number of arguments.''' user = udacity.User('*****@*****.**', 'password123') assert_dict_equal(user.creds, { 'udacity': { 'username': '******', 'password': '******' } }) assert isinstance(user.cache, bx.Db)
def test_progress(): '''Tests User.progress''' user = udacity.User(USER, PW) prog = user.progress('cs101') assert type(prog) is dict assert type(prog['current_lesson']) is dict keys = [ 'key', 'title', 'quiz_count', 'morsel_count', 'completed', 'quizzes_completed', 'morsels_completed', 'last_visited', 'time_away_ms', 'most_recent_url', 'current_lesson' ] for k in keys: assert k in prog
import udacity user = udacity.User('*****@*****.**', 'password123') name = user.name() # print out quiz completion rate in each course for course in user.enrollments(): prog = user.progress(course) print('Course: ' + prog['title']) print('\t' + str(prog['quizzes_completed']) + '/' + str(prog['quiz_count']) + ' quizzes completed')
def test_malformed(): '''Tests User.account with bad user info.''' user = udacity.User('bad', 'data') assert_raises(requests.exceptions.HTTPError, user.account)
def test_cache(): '''Tests to make sure data is cached after the first request.''' user = udacity.User(USER, PW) data = user.account() assert user.cache.get('account') is not None
def test_legit(): '''Tests User.account with actual data.''' user = udacity.User(USER, PW) data = user.account() assert data['first_name'] == 'Ty-Lucas'
def test_progress_malformed(): '''Tests User.progress with a nonexistant course key.''' user = udacity.User(USER, PW) assert_raises(IndexError, user.progress, 'aaaaaaa')
def test_key(): '''Tests User.key''' user = udacity.User(USER, PW) assert type(user.key()) is str or unicode
def enrollments(): '''Tests User.enrollments''' user = udacity.User(USER, PW) assert type(user.enrollments()) is list assert 'cs101' in user.enrollments()
def test_site_prefs(): '''Tests User.site_preferences''' user = udacity.User(USER, PW) assert type(user.site_preferences()) is dict
def test_email(): '''Tests User.email''' user = udacity.User(USER, PW) assert '@' in user.email()
def test_nickname(): '''Tests User.nickname''' user = udacity.User(USER, PW) assert type(user.nickname()) is str or unicode