Beispiel #1
0
    def setUp(self):
        """
        Define test variables and initialize app
        Has to be in this awkward camelCase to overload method in TestCase
        """
        self.app = create_app()
        self.client = self.app.test_client

        self.database_path = os.environ['HEROKU_POSTGRESQL_AQUA_URL']
        setup_db(self.app, self.database_path)

        # binds the app to the current context
        with self.app.app_context():

            # populate tables with test values
            e1 = Exercise(
                name='kb swing',
                equipment='kettlebell',
                target='reps',
                link='dummy link'
            )
            e2 = Exercise(
                name='kb goblet squat',
                equipment='kettlebell',
                target='reps',
                link='another dummy link here'
            )
            e1.insert()
            e2.insert()
            w = Workout(
                name='test workout',
                focus='legs',
                repeat=False
            )
            w.insert()
            m = WorkoutExercise(
                workout_id=1,
                exercise_id=1,
                sets=3,
                reps=8,
                weight=4
            )
            m.insert()
Beispiel #2
0
    def create_exercise():
        try:
            all_data = request.get_json()
            name = all_data['name']
            equipment = all_data['equipment']
            target = all_data['target']
            link = all_data['link']

            for value in [name, equipment, target, link]:
                if value is None:
                    abort(400)

            exercise = Exercise(name=name,
                                equipment=equipment,
                                target=target,
                                link=link)

            # could check whether we expect this to fail
            # based on inputs, and abort(500) otherwise
            exercise.insert()
        except Exception:
            abort(400)

        return jsonify({'success': True, 'id': exercise.id})
					print exercise					
	elif sys.argv[1] == 'insert':
		if sys.argv[2] == 'school':
			school = School.insert(name=sys.argv[3]).execute()
			print "New school: " + str(School.select().where(School.id==school).get())
		elif sys.argv[2] == 'batch':
			batch = Batch.insert(school=sys.argv[3], name=sys.argv[4]).execute()
			print "New batch: "	+ str(Batch.select().where(Batch.id==batch).get())
		elif sys.argv[2] == 'student':
			if len(sys.argv) == 6:
				student = Student.insert(batch=sys.argv[3], age=sys.argv[4], last_name='', first_name=sys.argv[5]).execute()
			else:		
				student = Student.insert(batch=sys.argv[3], age=sys.argv[4], last_name=sys.argv[5], first_name=sys.argv[6]).execute()
			print "New student: " + str(Student.select().where(Student.id==student).get())
		elif sys.argv[2] == 'exercise':
			exercise = Exercise.insert(student=sys.argv[3], subject=sys.argv[4],note=sys.argv[5]).execute()
			print "New exercise: " + str(Exercise.select().where(Exercise.id==exercise).get())
	elif sys.argv[1] == 'delete':
		if sys.argv[2] == 'school':
			if School.select().where(School.id==sys.argv[3]).count() == 0:
				print "Nothing to delete"
			else:
				print_school = "Delete: " + str(School.select().where(School.id==sys.argv[3]).get())	
				school = School.delete().where(School.id == sys.argv[3]).execute()
				print print_school
		elif sys.argv[2] == 'student':
			if Student.select().where(Student.id==sys.argv[3]).count() == 0:
				print "Nothing to delete"
			else:
				print_student = "Delete: " + str(Student.select().where(Student.id==sys.argv[3]).get())	
				student = Student.delete().where(Student.id == sys.argv[3]).execute()