Example #1
0
def test_marketplace_manage(client):
    rv = client.get(flask.url_for('marketplace.manage'))
    assert rv.status_code == 302
    assert rv.location == flask.url_for('auth.login')

    with client.session_transaction() as sess:
        sess['username'] = '******'
    rv = client.get(flask.url_for('marketplace.manage'))
    assert rv.status_code == 200
    assert b'Your listings' in rv.data

    rv = client.get(flask.url_for('marketplace.archive', item_id=3))
    assert rv.status_code == 302
    assert rv.location == flask.url_for('marketplace.manage')
    assert not helpers.table_fetch('marketplace_items',
                                   one=True,
                                   fields=['item_active'],
                                   attrs={'item_id': 3})

    rv = client.get(flask.url_for('marketplace.view_item', item_id=3))
    assert rv.status_code == 200
    assert b'This item has been archived!' in rv.data

    rv = client.get(flask.url_for('marketplace.unarchive', item_id=3))
    assert rv.status_code == 302
    assert rv.location == flask.url_for('marketplace.manage')
    assert helpers.table_fetch('marketplace_items',
                               one=True,
                               fields=['item_active'],
                               attrs={'item_id': 3})

    rv = client.get(flask.url_for('marketplace.view_item', item_id=3))
    assert rv.status_code == 200
    assert b'This item has been archived!' not in rv.data

    # Manage should fail if permissions are missing
    with client.session_transaction() as sess:
        sess['username'] = '******'
    rv = client.get(flask.url_for('marketplace.archive', item_id=3))
    assert rv.status_code == 302
    assert rv.location == flask.url_for('marketplace.marketplace')
    assert helpers.table_fetch('marketplace_items',
                               one=True,
                               fields=['item_active'],
                               attrs={'item_id': 3})
    rv = client.get(flask.url_for('marketplace.unarchive', item_id=3))
    assert rv.status_code == 302
    assert rv.location == flask.url_for('marketplace.marketplace')
Example #2
0
def test_my_page(client):
    with client.session_transaction() as sess:
        sess['username'] = '******'
    res = client.get(flask.url_for('core.my_directory_page'))
    assert res.status_code == 302
    assert res.headers['location'] == flask.url_for(
        'directory_search.view_user', user_id=3)
Example #3
0
def test_plain_editor_page(client):
    assert client.get(flask.url_for('editor.editor')).status_code == 403
    assert client.get(flask.url_for('editor.page_list')).status_code == 200
    # Since dude has admin privileges, he should be able to access the editor
    # page.
    with client.session_transaction() as sess:
        sess['username'] = '******'
    assert client.get(flask.url_for('editor.editor')).status_code == 200
Example #4
0
def test_set_name(client):
    with client.session_transaction() as sess:
        sess['username'] = '******'
    assert helpers.get_user(3)['preferred_name'] == 'Belac'
    res = client.post(flask.url_for('core.set_name'), data={'name': 'Clb'})
    assert res.status_code == 302
    assert res.headers['location'] == flask.url_for(
        'directory_search.view_user', user_id=3)
    assert helpers.get_user(3)['preferred_name'] == 'Clb'
Example #5
0
def test_set_name(client):
    with client.session_transaction() as sess:
        sess['username'] = '******'
    assert helpers.get_user(3)['gender_string'] == 'new_gender'
    res = client.post(flask.url_for('core.set_gender'),
                      data={'gender': 'Male'})
    assert res.status_code == 302
    assert res.headers['location'] == flask.url_for(
        'directory_search.view_user', user_id=3)
    assert helpers.get_user(3)['gender_string'] == 'Male'
Example #6
0
def test_marketplace_edit(client):
    with client.session_transaction() as sess:
        sess['username'] = '******'

    rv = client.get(flask.url_for('marketplace.sell', state='edit'),
                    follow_redirects=True)
    assert rv.status_code == 200
    assert b'Invalid item' in rv.data

    rv = client.get(flask.url_for('marketplace.sell',
                                  state='edit',
                                  item_id=100),
                    follow_redirects=True)
    assert rv.status_code == 200
    assert b'Invalid item' in rv.data

    rv = client.get(flask.url_for('marketplace.sell', state='edit', item_id=1),
                    follow_redirects=True)
    assert rv.status_code == 200
    assert b'You do not have permission to edit this item' in rv.data

    rv = client.get(flask.url_for('marketplace.sell', state='edit', item_id=4))
    assert rv.status_code == 200
    assert b'Couch' in rv.data
    assert b'12.34' in rv.data

    new_item = {
        'cat': 1,
        'item_title': 'Slouch',
        'item_condition': 'Poor',
        'item_price': '.77',
        'item_details': 'Possibly cursed'
    }
    rv = client.post(flask.url_for('marketplace.sell', state='edit',
                                   item_id=4),
                     data=new_item,
                     follow_redirects=True)
    assert rv.status_code == 200
    assert b'Updated!' in rv.data

    rv = client.get(flask.url_for('marketplace.view_item', item_id=4))
    assert rv.status_code == 200
    assert b'Furniture' in rv.data
    assert b'Slouch' in rv.data
    assert b'Poor' in rv.data
    assert b'$0.77' in rv.data
    assert b'https://i.imgur.com/abcdef123.png' not in rv.data
    assert b'csander' in rv.data
Example #7
0
def test_text_editor_page(client):
    with client.session_transaction() as sess:
        sess['username'] = '******'
    with app.test_request_context():
        flask.session['username'] = '******'
        helpers.create_page_in_database(
            "Some really really really interesting title",
            "nothing to see here")
        helpers.change_lock_status(
            "Some really really really interesting title", False)
        assert not helpers.is_locked(
            "Some really really really interesting title")
        helpers.create_page_in_database("Some less interesting title",
                                        "or is there")
        helpers.change_lock_status("Some less interesting title", True)
        assert helpers.is_locked("Some less interesting title")
        helpers.change_lock_status("default", True, default=True)
        assert not helpers.is_locked("default")

    rv = client.get(
        flask.url_for('editor.editor',
                      title="Some really really really interesting title"))
    assert rv.status_code == 200
    assert b'Some really really really interesting title' in rv.data
Example #8
0
def test_scheduler_mine(client):
    # Test when not logged in
    rv = client.get(flask.url_for('courses.scheduler_mine', year=2018, term=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == []
    rv = client.get(
        flask.url_for('courses.scheduler_add_section', course=1, section=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {
        'success': False,
        'message': 'Must be logged in to save'
    }
    rv = client.get(
        flask.url_for('courses.scheduler_drop_section', course=1, section=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {
        'success': False,
        'message': 'Must be logged in to save'
    }
    # Test sections list when no sections have been added
    with client.session_transaction() as sess:
        sess['username'] = '******'
    rv = client.get(flask.url_for('courses.scheduler_mine', year=2018, term=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == []
    # Test adding some sections
    rv = client.get(
        flask.url_for('courses.scheduler_add_section', course=1, section=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'success': True}
    rv = client.get(
        flask.url_for('courses.scheduler_add_section', course=6, section=2))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'success': True}
    rv = client.get(
        flask.url_for('courses.scheduler_add_section', course=2, section=3))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'success': True}
    # Test sections list now that sections have been added
    rv = client.get(flask.url_for('courses.scheduler_mine', year=2018, term=1))
    assert rv.status_code == 200
    assert sorted(json.loads(rv.data), key=lambda course: course['id']) == [{
        'id':
        1,
        'section':
        1
    }, {
        'id':
        2,
        'section':
        3
    }]
    rv = client.get(flask.url_for('courses.scheduler_mine', year=2018, term=3))
    assert rv.status_code == 200
    assert json.loads(rv.data) == [{'id': 6, 'section': 2}]
    # Test dropping a section
    rv = client.get(
        flask.url_for('courses.scheduler_drop_section', course=1, section=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'success': True}
    rv = client.get(flask.url_for('courses.scheduler_mine', year=2018, term=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == [{'id': 2, 'section': 3}]
Example #9
0
def test_planner_mine(client):
    # Test when not logged in
    rv = client.get(flask.url_for('courses.planner_mine'))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'courses': [], 'placeholders': []}
    rv = client.get(
        flask.url_for('courses.planner_add_course', course_id=1, year=2))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {
        'success': False,
        'message': 'Must be logged in to save'
    }
    rv = client.get(
        flask.url_for('courses.planner_drop_course', course_id=1, year=2))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {
        'success': False,
        'message': 'Must be logged in to save'
    }
    # Test courses list when no courses have been added
    with client.session_transaction() as sess:
        sess['username'] = '******'
    rv = client.get(flask.url_for('courses.planner_mine'))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'courses': [], 'placeholders': []}
    # Test adding some courses
    rv = client.get(
        flask.url_for('courses.planner_add_course', course_id=1, year=2))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'success': True}
    rv = client.get(
        flask.url_for('courses.planner_add_course', course_id=5, year=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'success': True}
    rv = client.get(
        flask.url_for('courses.planner_add_course', course_id=6, year=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'success': True}
    # Test adding a duplicate course (should fail)
    rv = client.get(
        flask.url_for('courses.planner_add_course', course_id=1, year=2))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {
        'success': False,
        'message': 'Cannot add a class twice in the same term'
    }
    # Test courses list now that courses have been added; verify order
    rv = client.get(flask.url_for('courses.planner_mine'))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {
        'courses': [{
            'ids': [1],
            'number': 'CS 124',
            'terms': [1],
            'units': 12,
            'year': 2
        }, {
            'ids': [6],
            'number': 'Bi 1',
            'terms': [3],
            'units': 9,
            'year': 1
        }, {
            'ids': [5],
            'number': 'CS 38',
            'terms': [3],
            'units': 9,
            'year': 1
        }],
        'placeholders': []
    }
    # Test dropping a course
    rv = client.get(
        flask.url_for('courses.planner_drop_course', course_id=5, year=1))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {'success': True}
    rv = client.get(flask.url_for('courses.planner_mine'))
    assert rv.status_code == 200
    assert json.loads(rv.data) == {
        'courses': [{
            'ids': [1],
            'number': 'CS 124',
            'terms': [1],
            'units': 12,
            'year': 2
        }, {
            'ids': [6],
            'number': 'Bi 1',
            'terms': [3],
            'units': 9,
            'year': 1
        }],
        'placeholders': []
    }
Example #10
0
def test_marketplace_sell(client):
    rv = client.get(flask.url_for('marketplace.sell'))
    assert rv.status_code == 302
    assert rv.location == flask.url_for('auth.login')

    with client.session_transaction() as sess:
        sess['username'] = '******'
    rv = client.get(flask.url_for('marketplace.sell', state='abc'))
    assert rv.status_code == 302
    assert rv.location == flask.url_for('marketplace.sell')

    rv = client.get(flask.url_for('marketplace.sell'))
    assert rv.status_code == 200
    assert b'Please select a category for your item' in rv.data

    item = {}
    for cat in (None, 'abc', '10'):
        item['cat'] = cat
        rv = client.post(flask.url_for('marketplace.sell'), data=item)
        assert rv.status_code == 200
        assert b'Invalid category' in rv.data

    item['cat'] = '1'  # Furniture
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Invalid category' not in rv.data
    assert b'Missing item title' in rv.data

    item['item_title'] = 'Couch'
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Missing item title' not in rv.data
    assert b'Missing condition' in rv.data

    item['item_condition'] = 'Saggy'
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Missing condition' not in rv.data
    assert b'Invalid price' in rv.data

    for price in ('cash $$$', '1.3'):
        item['item_price'] = price
        rv = client.post(flask.url_for('marketplace.sell'), data=item)
        assert rv.status_code == 200
        assert b'Invalid price' in rv.data

    item['item_price'] = '12.34'
    item['images'] = ['not_an_image']
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Invalid price' not in rv.data
    assert b'Invalid image' in rv.data

    item['images'] = ['http://imgur.com/abcdef123']
    rv = client.post(flask.url_for('marketplace.sell'),
                     data=item,
                     follow_redirects=True)
    assert rv.status_code == 200
    assert b'Invalid image' not in rv.data
    assert b'Posted!' in rv.data

    rv = client.get(flask.url_for('marketplace.view_item', item_id=4))
    assert rv.status_code == 200
    assert b'Furniture' in rv.data
    assert b'Couch' in rv.data
    assert b'Saggy' in rv.data
    assert b'$12.34' in rv.data
    assert b'https://i.imgur.com/abcdef123.png' in rv.data
    assert b'csander' in rv.data

    item = {'cat': '2'}
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Missing textbook title' in rv.data

    item['textbook_title'] = 'Algebra'
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Missing textbook title' not in rv.data
    assert b'Missing textbook author' in rv.data

    item['textbook_author'] = 'Serge Lang'
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Missing textbook author' not in rv.data

    item['textbook_id'] = '10'
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Invalid textbook' in rv.data
    del item['textbook_id']

    item['textbook_edition'] = 'not_an_edition'
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Invalid textbook edition' in rv.data

    item['textbook_edition'] = '3'
    item['textbook_isbn'] = 'not_an_isbn'
    rv = client.post(flask.url_for('marketplace.sell'), data=item)
    assert rv.status_code == 200
    assert b'Invalid textbook edition' not in rv.data
    assert b'Invalid textbook ISBN' in rv.data

    item['textbook_isbn'] = '0-387-95385-X'
    item['item_condition'] = 'New'
    item['item_price'] = '69'
    item['item_details'] = 'Caused much pain and suffering'
    rv = client.post(flask.url_for('marketplace.sell'),
                     data=item,
                     follow_redirects=True)
    assert rv.status_code == 200
    assert b'Invalid textbook ISBN' not in rv.data
    assert b'Posted!' in rv.data

    rv = client.get(flask.url_for('marketplace.view_item', item_id=5))
    assert rv.status_code == 200
    assert b'Textbooks' in rv.data
    assert b'Algebra' in rv.data
    assert b'Serge Lang' in rv.data
    assert b'New' in rv.data
    assert b'038795385X' in rv.data
    assert b'$69.00' in rv.data
    assert b'Caused much pain and suffering' in rv.data
    assert b'csander' in rv.data
Example #11
0
def test_edit_page(client):
    with client.session_transaction() as sess:
        sess['username'] = '******'
    assert client.get(flask.url_for('core.edit_user')).status_code == 200
Example #12
0
def test_data_handling(client):

    with client.session_transaction() as sess:
        # Should be able to do everything
        sess['username'] = '******'
    with app.test_request_context():
        flask.session['username'] = '******'
        assert helpers.get_permission() == {
            'ASCIT': True,
            'Avery': True,
            'Bechtel': True,
            'Blacker': True,
            'Dabney': True,
            'Fleming': True,
            'Lloyd': True,
            'Page': True,
            'Ricketts': True,
            'Ruddock': True,
            'Other': True,
            'Athletics': True,
            'Any': True
        }
        all_events = helpers.sync_data(all_data=True)
        assert all_events != []

        db_all_events = helpers.get_events_backup(all_data=True)
        for i in db_all_events:
            assert any(i['id'] == vals['id'] for vals in all_events)

        the_first_events = helpers.sync_data(11, 1111, 11, 1111)
        # In case some misguided soul or sadistic person decides to modify things in year 1111....
        ori_num = len(the_first_events)
        update_name = '我要放飞自我 la la la'

        db_events = helpers.get_events_backup(11, 1111, 11, 1111)

        assert len(db_events) == len(the_first_events)

        for i in db_events:
            assert any(i['id'] == vals['id'] for vals in the_first_events)

        # Testing insert
        name = 'this is the very first event find me and my art on inst @wingfril'
        description = 'This could be blank。 but i think that having some info is nice hahahahahhh'
        start_time = '1111-11-23T23:33:33Z'
        end_time = '1111-11-24T23:33:33Z'
        helpers.add_event(name, description, ['Avery'], start_time, end_time,
                          0)
        modded_events = helpers.get_events(11, 1111, 11, 1111)
        assert len(modded_events) == ori_num + 1

        for i in modded_events:
            if i['summary'] == name and i['description'] == description:
                the_first_event = i
        assert the_first_event

        # Testing updates
        update_name = '我要放飞自我 la la la'
        update_description = '''The Heavy Task of Reducing Air Pollution from Heavy-Duty Diesel
A Discussion with Dr. Francisco Dóñez, U.S. Environmental Protection Agency
This Thursday | May 30th | 12:00 to 1:30 pm (with a break at 12:50 for those with 1 pm commitments)
BBB B180 | Lunch Provided | Please RSVP Wednesday: https://forms.gle/UdeiV4oftb89eikk8 

Join us for a discussion with Dr. Francisco Dóñez, from the Air and Radiation Division at the U.S. Environmental Protection Agency (EPA) Pacific Southwest Regional Office (Region 9), who will speak about the EPA’s work to reduce air pollution from heavy-duty vehicles and equipment, particularly in the freight movement sector.  It is an effort crucial to air quality in southern California and an urgent environmental justice issue in numerous communities.  He will also discuss the intersecting issues of health, technology, policy and justice surrounding this work.

Dr. Dóñez leads the Ports and Railroad sector workgroups for the West Coast Collaborative, a public-private partnership to reduce air pollution form heavy-duty diesel engines.  He has championed environmental justice, diversity and equity perspectives within EPA and other organizations.  

Dr. Dóñez spent his early career at EPA headquarters in Washington, DC, where he performed economic analysis of environmental regulations, and coordinated climate change policy and research collaborations with the Mexican government.  Dr. Dóñez earned a Ph.D in Energy and Resources from UC Berkeley, an M.S. In public policy from Georgia Tech, and an S.B. in mechanical engineering from MIT.

Programs introduce one perspective in order to stimulate thought and to provide a forum for respectful dialogue and examination.  The views expressed by speakers are solely those of the speakers.  Presentations do not necessarily reflect the opinion of the California Institute of Technology or the Caltech Y and should not be taken as an endorsement of the ideas, speakers or groups.i\'m writing this at 2am. i have too much time'''
        helpers.add_event(update_name,
                          update_description,
                          [the_first_event['organizer']['displayName']],
                          the_first_event['start']['dateTime'],
                          the_first_event['end']['dateTime'],
                          1,
                          event_id=the_first_event['id'])

        modded_events = helpers.get_events(11, 1111, 11, 1111)

        assert len(modded_events) == ori_num + 1
        updated = False
        for i in modded_events:
            if i['summary'] == update_name and i[
                    'description'] == update_description:
                updated = True
                deleted = helpers.delete(i['id'],
                                         i['organizer']['displayName'])

        assert updated
        modded_events = helpers.get_events(11, 1111, 11, 1111)
        assert len(modded_events) == ori_num

        db_events = helpers.get_events_backup(11, 1111, 11, 1111)
        assert ori_num == len(db_events)