import forum.database as database import sqlite3 DEFAULT_DATA_DUMP = "db/forum_data_dump.sql" engine = database.Engine() engine.create_users_table() engine.create_exercise_table() engine.create_friends_table() con = sqlite3.connect('db/forum.db') cur = con.cursor() keys_on = 'PRAGMA foreign_keys = ON' cur.execute(keys_on) #Populate database from dump dump = DEFAULT_DATA_DUMP with open(dump) as f: sql = f.read() cur = con.cursor() cur.executescript(sql)
import sqlite3, unittest from forum import database DB_PATH = 'db/updown_test.db' ENGINE = database.Engine(DB_PATH) CURRENCY1_ID = 'msg-1' class MessageDBAPITestCase(unittest.TestCase): @classmethod def setUpClass(cls): print("Testing ", cls.__name__) ENGINE.remove_database() ENGINE.create_tables() @classmethod def tearDownClass(cls): print("Testing ENDED for ", cls.__name__) ENGINE.remove_database() def setUp(self): try: #This method load the initial values from forum_data_dump.sql ENGINE.populate_tables() #Creates a Connection instance to use the API self.connection = ENGINE.connect() except Exception as e: #For instance if there is an error while populating the tables ENGINE.clear() def tearDown(self):
#TODO #3# #STUDENT APIARY PROJECT SHOULD HAVE THE STUDENTS PROJECT URL" STUDENT_APIARY_PROJECT = "https://pwp2018exercise316.docs.apiary.io" APIARY_PROFILES_URL = STUDENT_APIARY_PROJECT + "/#reference/profiles/" APIARY_RELS_URL = STUDENT_APIARY_PROJECT + "/#reference/link-relations/" USER_SCHEMA_URL = "/forum/schema/user/" LINK_RELATIONS_URL = "/forum/link-relations/" #Define the application and the api app = Flask(__name__, static_folder="static", static_url_path="/.") app.debug = True # Set the database Engine. In order to modify the database file (e.g. for # testing) provide the database path app.config to modify the #database to be used (for instance for testing) app.config.update({"Engine": database.Engine()}) #Start the RESTful API. api = Api(app) # These two classes below are how we make producing the resource representation # JSON documents manageable and resilient to errors. As noted, our mediatype is # Mason. Similar solutions can easily be implemented for other mediatypes. class MasonObject(dict): """ A convenience class for managing dictionaries that represent Mason objects. It provides nice shorthands for inserting some of the more elements into the object but mostly is just a parent for the much more useful subclass defined next. This class is generic in the sense that it does not contain any application specific implementation details.