def create_test_topics(db_conn): users = [{ 'id': user_uuid, 'name': 'test', 'email': '*****@*****.**', 'password': '******', }, { 'id': user_b_uuid, 'name': 'other', 'email': '*****@*****.**', 'password': '******', }] raw_insert_users(db_conn, users) units = [{ 'user_id': user_uuid, 'entity_id': test_unit_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun' }, { 'user_id': user_uuid, 'entity_id': test_unit_b_uuid, 'name': 'test unit subtract', 'body': 'subtracting numbers is fun' }] raw_insert_units(db_conn, units) topics = [{ 'id': test_topic_id, 'user_id': user_uuid, 'entity_id': test_unit_uuid, 'entity_kind': 'unit', 'name': 'Lets talk about adding numbers', }] raw_insert_topics(db_conn, topics)
def test_follow_409(db_conn, session): """ Expect to fail to follow entity if already followed. """ raw_insert_units(db_conn, [{ 'entity_id': unit_a_uuid, 'name': 'Foo', 'body': 'Foo', }]) raw_insert_follows(db_conn, [{ 'user_id': user_id, 'entity_kind': 'unit', 'entity_id': unit_a_uuid, }]) request = { 'cookies': { 'session_id': session }, 'params': { 'entity_kind': 'unit', 'entity_id': unit_a_uuid, }, 'db_conn': db_conn } code, _ = routes.follow.follow_route(request) assert code == 400
def create_response_test_data(db_conn): users = [{ 'id': user_a_uuid, 'name': 'test', 'email': '*****@*****.**', 'password': '******', }] raw_insert_users(db_conn, users) units = [{ 'entity_id': test_unit_uuid, 'name': 'Calculus', 'user_id': user_a_uuid, 'body': 'Calculus is fun sometimes.', }] raw_insert_units(db_conn, units) cards = [{ 'user_id': user_a_uuid, 'entity_id': test_card_uuid, 'unit_id': test_unit_uuid, 'kind': 'choice', 'name': 'Meaning of Life', 'data': { 'body': 'What is the meaning of life?', 'options': [{ 'id': convert_uuid_to_slug(test_card_option1_uuid), 'value': '42', 'correct': True, 'feedback': 'Yay!', }, { 'id': convert_uuid_to_slug(test_card_option2_uuid), 'value': 'love', 'correct': False, 'feedback': 'Boo!', }], 'order': 'set', 'max_options_to_show': 4, }, }] raw_insert_cards(db_conn, cards) responses = [{ 'user_id': user_a_uuid, 'card_id': test_card_uuid, 'unit_id': test_unit_uuid, 'response': test_card_option1_uuid, 'score': 1, 'learned': 0.5, }, { 'user_id': user_a_uuid, 'card_id': test_card_uuid, 'unit_id': test_unit_uuid, 'response': test_card_option2_uuid, 'score': 0, 'learned': 0.4, }] raw_insert_responses(db_conn, responses)
def test_update_entity_status_by_kind(db_conn): create_test_user(db_conn) unit_version_a_uuid = uuid.uuid4() card_version_a_uuid = uuid.uuid4() subject_version_a_uuid = uuid.uuid4() units = [{ 'version_id': unit_version_a_uuid, 'user_id': user_a_uuid, 'entity_id': unit_a_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun', 'status': 'pending', }] raw_insert_units(db_conn, units) cards = [{ 'version_id': card_version_a_uuid, 'status': 'pending', 'entity_id': uuid.uuid4(), 'unit_id': unit_a_uuid, 'user_id': user_a_uuid, 'kind': 'video', 'name': 'Meaning of Life Video', 'data': { 'site': 'youtube', 'video_id': convert_uuid_to_slug(uuid.uuid4()), }, }] raw_insert_cards(db_conn, cards) subjects = [{ 'version_id': subject_version_a_uuid, 'status': 'pending', 'entity_id': subject_a_uuid, 'name': 'Math', 'user_id': user_a_uuid, 'body': 'Math is fun.', 'members': [], }] raw_insert_subjects(db_conn, subjects) unit, errors = update_entity_status_by_kind(db_conn, kind='unit', version_id=unit_version_a_uuid, status='accepted') assert not errors assert unit['status'] == 'accepted' card, errors = update_entity_status_by_kind(db_conn, kind='card', version_id=card_version_a_uuid, status='accepted') assert not errors assert card['status'] == 'accepted' subject, errors = update_entity_status_by_kind( db_conn, kind='subject', version_id=subject_version_a_uuid, status='accepted') assert not errors assert subject['status'] == 'accepted'
def create_unit_in_db(db_conn, status='accepted'): units = [{ 'version_id': unit_version_a_uuid, 'user_id': user_id, 'entity_id': unit_a_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun', 'status': status, }] raw_insert_units(db_conn, units)
def create_route_subject_test_data(db_conn): units = [{ 'version_id': unit_version_a_uuid, 'user_id': user_id, 'entity_id': unit_a_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun' }, { 'user_id': user_id, 'entity_id': unit_b_uuid, 'name': 'test unit subtract', 'body': 'subtracting numbers is fun', 'require_ids': [unit_a_uuid], }] raw_insert_units(db_conn, units) cards = [{ 'entity_id': card_a_uuid, 'unit_id': unit_a_uuid, 'kind': 'video', 'name': 'Video Z', }] raw_insert_cards(db_conn, cards) subjects = [{ 'version_id': subject_version_a_uuid, 'entity_id': subject_a_uuid, 'name': 'Math', 'user_id': user_id, 'body': 'Math is fun.', 'members': [{ 'kind': 'unit', 'id': convert_uuid_to_slug(unit_a_uuid), }, { 'kind': 'unit', 'id': convert_uuid_to_slug(unit_b_uuid), }], }, { 'entity_id': subject_b_uuid, 'name': 'An Introduction to Electronic Music', 'user_id': user_id, 'body': 'Art is fun.', 'members': [{ 'kind': 'subject', 'id': convert_uuid_to_slug(subject_a_uuid), }], }] raw_insert_subjects(db_conn, subjects)
def create_subject_test_data(db_conn): users = [{ 'id': user_a_uuid, 'name': 'test', 'email': '*****@*****.**', 'password': '******', }, { 'id': user_b_uuid, 'name': 'other', 'email': '*****@*****.**', 'password': '******', }] raw_insert_users(db_conn, users) units = [{ 'user_id': user_a_uuid, 'entity_id': unit_a_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun' }, { 'user_id': user_a_uuid, 'entity_id': unit_b_uuid, 'name': 'test unit subtract', 'body': 'subtracting numbers is fun', 'require_ids': [unit_a_uuid], }] raw_insert_units(db_conn, units) subjects = [{ 'version_id': subject_version_a_uuid, 'entity_id': test_subject_a_uuid, 'name': 'Math', 'user_id': user_b_uuid, 'body': 'Math is fun.', 'members': [{ 'kind': 'unit', 'id': convert_uuid_to_slug(unit_a_uuid), }, { 'kind': 'unit', 'id': convert_uuid_to_slug(unit_b_uuid), }], }, { 'entity_id': test_subject_b_uuid, 'name': 'Art', 'user_id': user_b_uuid, 'body': 'Art is fun.', 'members': [{ 'kind': 'subject', 'id': convert_uuid_to_slug(test_subject_a_uuid), }], }] raw_insert_subjects(db_conn, subjects)
def create_route_unit_test_data(db_conn): units = [{ 'version_id': unit_version_a_uuid, 'user_id': user_id, 'entity_id': unit_a_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun' }, { 'user_id': user_id, 'entity_id': unit_b_uuid, 'name': 'test unit subtract', 'body': 'subtracting numbers is fun', 'require_ids': [unit_a_uuid], }] raw_insert_units(db_conn, units)
def create_one_subject(db_conn): raw_insert_units(db_conn, [{ 'entity_id': unit_a_uuid, 'name': 'Unit', 'body': 'doesnt matter', }]) raw_insert_subjects(db_conn, [{ 'entity_id': subject_a_uuid, 'name': 'A', 'body': 'Apple', 'members': [{ 'kind': 'unit', 'id': convert_uuid_to_slug(unit_a_uuid), }] }])
def create_recurse_test_data(db_conn): create_test_user(db_conn) units = [{ 'user_id': user_a_uuid, 'entity_id': unit_a_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun' }, { 'user_id': user_a_uuid, 'entity_id': unit_b_uuid, 'name': 'test unit subtract', 'body': 'subtracting numbers is fun', }] raw_insert_units(db_conn, units) subjects = [{ 'entity_id': subject_a_uuid, 'name': 'Math', 'user_id': user_a_uuid, 'body': 'Math is fun.', 'members': [{ 'kind': 'unit', 'id': convert_uuid_to_slug(unit_a_uuid), }, { 'kind': 'unit', 'id': convert_uuid_to_slug(unit_b_uuid), }], }, { 'entity_id': subject_b_uuid, 'name': 'Art', 'user_id': user_a_uuid, 'body': 'Art is fun.', 'members': [{ 'kind': 'subject', 'id': convert_uuid_to_slug(subject_a_uuid), }], }] raw_insert_subjects(db_conn, subjects)
def test_update_entity_statuses(db_conn): create_test_user(db_conn) unit_version_a_uuid = uuid.uuid4() topic_uuid = uuid.uuid4() proposal_uuid = uuid.uuid4() units = [{ 'version_id': unit_version_a_uuid, 'user_id': user_a_uuid, 'entity_id': unit_a_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun', 'status': 'pending', }] raw_insert_units(db_conn, units) topics = [{ 'id': topic_uuid, 'user_id': user_a_uuid, 'entity_id': unit_a_uuid, 'entity_kind': 'unit', 'name': 'Lets talk about adding numbers', }] raw_insert_topics(db_conn, topics) posts = [{ 'id': proposal_uuid, 'kind': 'proposal', 'body': 'A new version', 'entity_versions': [{ 'id': convert_uuid_to_slug(unit_version_a_uuid), 'kind': 'unit', }], 'user_id': user_a_uuid, 'topic_id': topic_uuid, }] raw_insert_posts(db_conn, posts) proposal = get_post(db_conn, {'id': proposal_uuid}) update_entity_statuses(db_conn, proposal) unit = get_unit_version(db_conn, unit_version_a_uuid) assert unit assert unit['status'] == 'accepted'
def create_topic_in_db(db_conn, user_id=user_id): users = [{ 'id': user_b_uuid, 'name': 'other', 'email': '*****@*****.**', 'password': '******', }] raw_insert_users(db_conn, users) raw_insert_units(db_conn, [{ 'user_id': user_id, 'entity_id': unit_uuid, 'name': 'test unit subtract', 'body': 'subtracting numbers is fun', }]) raw_insert_topics(db_conn, [{ 'id': topic_uuid, 'user_id': user_id, 'name': 'A Modest Proposal', 'entity_id': unit_uuid, 'entity_kind': 'unit' }])
def test_get_sitemap_route(db_conn): raw_insert_users(db_conn, [{ 'id': user_uuid, 'name': 'test', 'email': '*****@*****.**', 'password': '******', }]) raw_insert_units(db_conn, [{ 'user_id': user_uuid, 'entity_id': unit_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun' }]) raw_insert_topics(db_conn, [{ 'id': topic_uuid, 'user_id': user_uuid, 'entity_id': unit_uuid, 'entity_kind': 'unit', 'name': 'Lets talk about adding numbers', }]) request = {'db_conn': db_conn} code, _ = get_sitemap_route(request) assert code == 200
def test_follow(db_conn, session): """ Expect to follow an entity. """ raw_insert_units(db_conn, [{ 'entity_id': unit_a_uuid, 'name': 'Foo', 'body': 'Foo', }]) request = { 'cookies': { 'session_id': session }, 'params': { 'entity_kind': 'unit', 'entity_id': unit_a_uuid, }, 'db_conn': db_conn } code, _ = routes.follow.follow_route(request) assert code == 200
def create_test_posts(db_conn): users = [{ 'id': user_uuid, 'name': 'test', 'email': '*****@*****.**', 'password': '******', }, { 'id': user_b_uuid, 'name': 'other', 'email': '*****@*****.**', 'password': '******', }] raw_insert_users(db_conn, users) units = [{ 'version_id': test_unit_version_uuid, 'user_id': user_uuid, 'entity_id': test_unit_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun', }, { 'version_id': test_unit_b_version_uuid, 'user_id': user_uuid, 'entity_id': test_unit_b_uuid, 'name': 'test unit subtract', 'body': 'subtracting numbers is fun', }] raw_insert_units(db_conn, units) topics = [{ 'id': test_topic_id, 'user_id': user_uuid, 'entity_id': test_unit_uuid, 'entity_kind': 'unit', 'name': 'Lets talk about adding numbers', }, { 'id': test_topic_b_id, 'user_id': user_uuid, 'entity_id': test_unit_b_uuid, 'entity_kind': 'unit', 'name': 'Lets talk about subtracting numbers', }] raw_insert_topics(db_conn, topics) posts = [{ 'id': proposal_uuid, 'kind': 'proposal', 'body': 'A new version', 'entity_versions': [{ 'id': convert_uuid_to_slug(test_unit_version_uuid), 'kind': 'unit', }], 'user_id': user_uuid, 'topic_id': test_topic_id, }, { 'id': post_uuid, 'kind': 'post', 'body': 'I just love adding numbers.', 'user_id': user_uuid, 'topic_id': test_topic_id, }, { 'id': vote_uuid, 'kind': 'vote', 'body': 'Yay!', 'replies_to_id': proposal_uuid, 'response': True, 'user_id': user_b_uuid, 'topic_id': test_topic_id, }] raw_insert_posts(db_conn, posts)
def add_test_subject(db_conn): """ Add doesn't require anything. Multiply requires add. Subtract requires add. Divide requires multiply. Add is done, Subtract needs review, Multiply needs to be learned, Divide needs to be diagnosed. """ raw_insert_units( db_conn, [{ 'entity_id': unit_add_uuid, 'user_id': user_id, 'name': 'Add', 'body': 'Add', }, { 'entity_id': unit_subtract_uuid, 'require_ids': [unit_add_uuid], 'user_id': user_id, 'name': 'Subtract', 'body': 'Subtract', }, { 'entity_id': unit_multiply_uuid, 'require_ids': [unit_add_uuid], 'user_id': user_id, 'name': 'Multiply', 'body': 'Multiply', }, { 'entity_id': unit_divide_uuid, 'require_ids': [unit_multiply_uuid, unit_subtract_uuid], 'user_id': user_id, 'name': 'Divide', 'body': 'Divide', }]) raw_insert_cards(db_conn, [{ 'entity_id': card_a_uuid, 'unit_id': unit_add_uuid, 'user_id': user_id, 'status': 'accepted', 'kind': 'video', 'name': 'Meaning of Life Video', 'data': { 'site': 'youtube', 'video_id': convert_uuid_to_slug(uuid.uuid4()), }, }]) raw_insert_responses( db_conn, [{ 'user_id': user_id, 'unit_id': unit_add_uuid, 'learned': 0.99, 'card_id': card_a_uuid, 'response': convert_uuid_to_slug(uuid.uuid4()), 'score': 1, }, { 'user_id': user_id, 'unit_id': unit_multiply_uuid, 'learned': 0.0, 'card_id': card_a_uuid, 'response': convert_uuid_to_slug(uuid.uuid4()), 'score': 1, }, { 'user_id': user_id, 'unit_id': unit_subtract_uuid, 'learned': 0.99, 'card_id': card_a_uuid, 'response': convert_uuid_to_slug(uuid.uuid4()), 'score': 1, 'created': datetime(2004, 11, 3, tzinfo=timezone.utc) }]) raw_insert_subjects(db_conn, [{ 'user_id': user_id, 'entity_id': subject_uuid, 'created': datetime(2004, 11, 1, tzinfo=timezone.utc), 'name': 'Math', 'body': 'Math', 'members': [ { 'id': convert_uuid_to_slug(unit_add_uuid), 'kind': 'unit' }, { 'id': convert_uuid_to_slug(unit_subtract_uuid), 'kind': 'unit' }, { 'id': convert_uuid_to_slug(unit_multiply_uuid), 'kind': 'unit' }, { 'id': convert_uuid_to_slug(unit_divide_uuid), 'kind': 'unit' }, ], }])
def create_test_cards(db_conn): units = [{ 'entity_id': unit_id, 'status': 'accepted', 'name': 'Wildwood', 'body': 'Wildwood', }] raw_insert_units(db_conn, units) cards = [{ 'entity_id': entity_id, 'unit_id': unit_id, 'status': 'accepted', 'kind': 'video', 'name': 'Video A', 'require_ids': [entity_id_r], }, { 'entity_id': entity_id, 'unit_id': unit_id, 'created': datetime(1986, 11, 3, tzinfo=timezone.utc), 'modified': datetime(1986, 11, 3, tzinfo=timezone.utc), 'status': 'accepted', 'kind': 'video', 'name': 'Video A', }, { 'entity_id': entity_id_r, 'unit_id': unit_id, 'status': 'accepted', 'kind': 'video', 'name': 'Video Z', }, { 'entity_id': entity_id_b, 'unit_id': unit_id, 'status': 'accepted', 'kind': 'choice', 'require_ids': [entity_id], 'name': 'Video X', }, { 'version_id': card_version_id, 'entity_id': card_id, 'unit_id': unit_id, 'status': 'accepted', 'kind': 'choice', 'name': 'Meaning of Life', 'data': { 'body': 'What is the meaning of life?', 'options': [{ 'id': convert_uuid_to_slug(good_response_id), 'value': '42', 'correct': True, 'feedback': 'Yay!', }, { 'id': convert_uuid_to_slug(uuid.uuid4()), 'value': 'love', 'correct': False, 'feedback': 'Boo!', }], 'order': 'set', 'max_options_to_show': 4, }, }, { 'entity_id': uuid.uuid4(), 'unit_id': unit_id, 'status': 'accepted', 'kind': 'choice', 'name': 'Meaning of Love', 'data': { 'body': 'What is the meaning of love?', 'options': [{ 'id': convert_uuid_to_slug(uuid.uuid4()), 'value': 'Flava Flav', 'correct': True, 'feedback': 'Yay!', }, { 'id': convert_uuid_to_slug(uuid.uuid4()), 'value': 'life', 'correct': False, 'feedback': 'Boo!', }], 'order': 'set', 'max_options_to_show': 4, }, }] raw_insert_cards(db_conn, cards)
def create_card_test_data(db_conn): users = [{ 'id': user_a_uuid, 'name': 'test', 'email': '*****@*****.**', 'password': '******', }, { 'id': user_b_uuid, 'name': 'other', 'email': '*****@*****.**', 'password': '******', }] raw_insert_users(db_conn, users) units = [{ 'version_id': unit_version_a_uuid, 'user_id': user_a_uuid, 'entity_id': unit_a_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun' }] raw_insert_units(db_conn, units) cards = [{ 'version_id': card_version_a_uuid, 'entity_id': card_a_uuid, 'unit_id': unit_a_uuid, 'user_id': user_a_uuid, 'status': 'accepted', 'kind': 'video', 'name': 'Meaning of Life Video', 'data': { 'site': 'youtube', 'video_id': convert_uuid_to_slug(uuid.uuid4()), }, }, { 'version_id': card_version_b_uuid, 'entity_id': card_b_uuid, 'unit_id': unit_a_uuid, 'user_id': user_a_uuid, 'kind': 'choice', 'name': 'Meaning of Life', 'data': { 'body': 'What is the meaning of life?', 'options': [{ 'id': convert_uuid_to_slug(test_card_option1_uuid), 'value': '42', 'correct': True, 'feedback': 'Yay!', }, { 'id': convert_uuid_to_slug(test_card_option2_uuid), 'value': 'love', 'correct': False, 'feedback': 'Boo!', }], 'order': 'set', 'max_options_to_show': 4, }, 'require_ids': [card_a_uuid] }] raw_insert_cards(db_conn, cards)