示例#1
0
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, {})
示例#2
0
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, {})
示例#3
0
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
示例#5
0
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')
示例#6
0
def test_malformed():
    '''Tests User.account with bad user info.'''

    user = udacity.User('bad', 'data')
    assert_raises(requests.exceptions.HTTPError, user.account)
示例#7
0
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
示例#8
0
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')
示例#10
0
def test_key():
    '''Tests User.key'''

    user = udacity.User(USER, PW)
    assert type(user.key()) is str or unicode
示例#11
0
def enrollments():
    '''Tests User.enrollments'''

    user = udacity.User(USER, PW)
    assert type(user.enrollments()) is list
    assert 'cs101' in user.enrollments()
示例#12
0
def test_site_prefs():
    '''Tests User.site_preferences'''

    user = udacity.User(USER, PW)
    assert type(user.site_preferences()) is dict
示例#13
0
def test_email():
    '''Tests User.email'''

    user = udacity.User(USER, PW)
    assert '@' in user.email()
示例#14
0
def test_nickname():
    '''Tests User.nickname'''

    user = udacity.User(USER, PW)
    assert type(user.nickname()) is str or unicode