def test_base_methods(self): # create calls save and new sub1 = Submission().create( **{ "title": "title", "email": "email", "card_id": "card_id", "card_url": "card_url", "card_email": "card_email", "description": "description", "notes": "notes", "pitch": "pitch", }) assert Submission().get_by_id(sub1.id) assert Submission().first(email="email") Submission().update(sub1, card_id="new_card_id") assert Submission().find(card_id="new_card_id") assert Submission().all() is not None assert sub1 in Submission().get_all(sub1.id) assert Submission().get_or_404(sub1.id) is not None assert sub1.to_dict() == { "title": sub1.title, "card_id": sub1.card_id, "card_url": sub1.card_url, "created_at": sub1.created_at, "updated_at": sub1.updated_at, "type": "Submission", "email": sub1.email, "hook": sub1.hook, "status": sub1.status, "card_email": sub1.card_email, "description": sub1.description, "notes": sub1.notes, "pitch": sub1.pitch, } with pytest.raises(ValueError): sub1._isinstance(str()) Submission().delete(sub1) assert Submission().get_by_id(sub1.id) is None
def post(self, course_name, name, page=1): """Creates a new submission.""" course = Course.objects.get_or_404(name=course_name) project = Project.objects.get_or_404(name=name) if len(Submission.objects(project=project, submitter=g.user, processed=False)) > 4: abort(429, message="Too many pending submissions") if not g.user in course.students: abort(403, message="Must be a course student to submit") if not project in course.projects: abort(404, message="Project not found.") if not project.can_submit: abort(498, message="Due date has passed, tough luck!") if project.is_quiz: # Verify verification code args = submission_parser.parse_args() if g.user.verification_code != args['verification_code']: abort(400, message="Invalid verification code.") if len(request.files.values()) == 1: subm = Submission(submitter=g.user, project=project) for file in request.files.values(): if allowed_code_file(file.filename): grid_file = db.GridFSProxy() grid_file.put( file, filename=secure_filename(file.filename), content_type=file.mimetype) subm.code = grid_file else: abort(400, message="Only {0} files allowed".format(','.join(api.app.config['ALLOWED_CODE_EXTENSIONS']))) subm.save() project.submissions.append(subm) project.save() if api.app.config['DELETE_SUBMISSIONS']: junit_task.delay(str(subm.id)) else: junit_no_deletion.delay(str(subm.id)) return marshal(subm.to_dict(parent_course=course, parent_project=project), submission_fields), 201 else: abort(400, message="Can only submit one file.") # Bad request