Пример #1
0
    def test_connection(self):
        '''
        This unittest will test whether the mongo driver is connecting successfully to:
        Database name: 
        collection name = "aggregated_GCOE"
        '''
        try:
            conn = mongo.mongo_driver()
            conn.get_db_collection(DB_NAME, COLLECTION_NAME)
            conn_status = True
        except:
            conn_status = False

        return self.assertEqual(True, conn_status)
Пример #2
0
    def test_course_api_endings(self):
        '''
        This unit test will ping each of the currently created api endings with a variety of different courses to make sure they hit.

        '''
        # Define the currently working courses - You can generate this by running api_functions.py
        course_function_list = [
            CourseFig1Table, CourseFig2Chart, CourseFig3Timeseries,
            CourseFig4TableBar
        ]
        # Generate random course/instructor IDs for the test
        response = SearchAutocomplete(mongo_driver(), 'course')
        res_dict = json.loads(json.dumps(response))
        id_list = [el['value'] for el in res_dict]
        test_id_list = random.choices(id_list, k=8)
        print(
            'Testing for the following instructor IDs, generated randomly from viable options: '
        )
        pprint.pprint(test_id_list)

        # Create connection to the db
        db = mongo.mongo_driver()

        # Try the function for autocomplete for all courses
        try:
            print('SearchAutocomplete for all courses')
            response = SearchAutocomplete(db, search_type='course')
            response_dict = json.loads(json.dumps(response))

        except:
            return self.assertEqual(True, False)

        for course in test_id_list:
            print(course)
            for func in course_function_list:
                try:
                    response = func(db, course)
                    json.loads(json.dumps(response))
                except:
                    return self.assertEqual(True, False)

        return self.assertEqual(True, True)
Пример #3
0
    def test_instructor_api_endings(self):
        '''
        This unit test will ping each of the currently created api endings with a variety of different instructors to make sure they hit.

        '''
        # Define the currently working course APIs
        instructor_function_list = [
            InstructorFig1Table, InstructorFig2Timeseries,
            InstructorFig3TableBar
        ]

        # Generate random course/instructor IDs for the test
        response = SearchAutocomplete(mongo_driver(), 'instructor')
        res_dict = json.loads(json.dumps(response))
        id_list = [el['value'] for el in res_dict]
        test_id_list = random.choices(id_list, k=8)
        print(
            'Testing for the following instructor IDs, generated randomly from viable options: '
        )
        pprint.pprint(test_id_list)

        # Create connection to the db
        db = mongo.mongo_driver()
        try:
            print('SearchAutocomplete for all instructors')
            response = SearchAutocomplete(db, search_type='instructor')
            response_dict = json.loads(json.dumps(response))
        except:
            return self.assertEqual(True, False)

        print('Testing the api functions for the following instructors: ')
        for instr in test_id_list:
            print(instr)
            for func in instructor_function_list:
                try:
                    response = func(db, instr)
                    json.loads(json.dumps(response))
                except:
                    return self.assertEqual(True, False)

        return self.assertEqual(True, True)
Пример #4
0
from flask_cors import CORS
from data_loader import update_database
from mongo import mongo_driver
from bson.json_util import dumps
import pandas as pd
import json
import api_functions as api

# Establish a database connection
DB_NAME = "reviews-db"
COLLECTION_NAME = "reviews-collection"

# base route for this api version
base_api_route = '/api/v0/'

db = mongo_driver()

# PreCompute the instructor and course lists
instructor_list = api.SearchAutocomplete(db, 'instructor')
course_list = api.SearchAutocomplete(db, 'course')

app = Flask(__name__)
CORS(app)

# useful for testing
# curl -i http://localhost:5050/api/v0/

@app.route('/')
def hello_world():
    return 'Ping <a href="/api/v0/">/api/v0/</a> for api'.format(str(request.remote_addr))
Пример #5
0
            df_coll = pd.DataFrame(list(cursor))
            df_coll.drop_duplicates(search_key, inplace=True)
            df = pd.concat([df, df_coll], ignore_index=True, sort=True)
    df.drop_duplicates(search_key, inplace=True)

    # Now, we just need to convert the dataframe to a dictionary with needed form for search autocomplete
    if search_type == 'course':
        # Create the label column
        df['label'] = df['Subject Code'].str.strip()+df['Course Number'].astype(str)+': '+df['Course Title']
        return_list = [{'label':row['label'], 'value':row[search_key]} for index, row in df.iterrows()]
    else:
        df['label'] = df['Instructor First Name']+' '+ df['Instructor Last Name']
        return_list = [{'label':row['label'], 'value':row[search_key]} for index, row in df.iterrows()]
    return return_list

if __name__ == '__main__':
    # Test the db search
    # test = [201410, 201420, 201530, 201620, 201230, 201810]
    # print(test)
    # sort_by_term_code([201710, 201820, 201620, 201410, 201110, 201630, 201610])

    # uuid_df, coll_name = query_df_from_mongo(mongo_driver(),cursor)
    pprint.pprint(CourseFig1Table(mongo_driver(), "753572960")) # Statics
    pprint.pprint(CourseFig2Chart(mongo_driver(), "753572960"))
    pprint.pprint(CourseFig3Timeseries(mongo_driver(), "753572960"))
    pprint.pprint(CourseFig4TableBar(mongo_driver(), "753572960")) # Make sure the full unmodified dataset is uploaded before running
    pprint.pprint(InstructorFig1Table(mongo_driver(), 624629390)) # Janet Allen
    pprint.pprint(InstructorFig2Timeseries(mongo_driver(), 624629390))
    pprint.pprint(InstructorFig3TableBar(mongo_driver(), 624629390)) # Make sure the full unmodified dataset is uploaded before running
    pprint.pprint(InstructorChipAPI(mongo_driver(), 624629390))