def setUp(self): self.chunk1 = Chunk(key='testchunk1', content='I LIKE PIE', description='') self.chunk1.save() # on production, CHUNKS_WRAP is False setattr(settings, 'CHUNKS_WRAP', False)
def make_chunk_tuple(chunk_key): """ Helper to make a tuple that can be turned into a dictionary to add to context """ # Some chunk keys are not appropriate as template variable names. fix those var_name = re.sub(r'[ \-,\.;]', '_', chunk_key) return var_name, Chunk.get_chunk(chunk_key, request=request)
class ChunkTagTestCase(TestCase): """ Tests the template tags """ # fixtures = ["chunks_initial_data.json"] # test of commit def setUp(self): self.chunk1 = Chunk(key='testchunk1', content='I LIKE PIE', description='') self.chunk1.save() # on production, CHUNKS_WRAP is False setattr(settings, 'CHUNKS_WRAP', False) def test_chunk(self): # chunk is rendered rendered = render_template('{% load chunks %}{% chunk "testchunk1" %}') self.assertEqual(rendered, self.chunk1.content) # chunk is created and rendered rendered = render_template('{% load chunks %}{% chunk "testchunk_not_exists" %}') self.assertEqual(rendered, 'testchunk_not_exists') self.assertEqual(len(Chunk.objects.all()), 2) def test_code_chunk(self): rendered = codechunk('testchunk1') self.assertEqual(rendered, self.chunk1.content) rendered = codechunk('testchunk_not_exists_2') self.assertEqual(rendered, 'testchunk_not_exists_2') self.assertEqual(len(Chunk.objects.all()), 2) def test_chunk_filter(self): # 1 = wrap # 0 = don't wrap rendered = render_template('{% load chunks %}{{ "testchunk1"|chunk:0 }}') self.assertEqual(rendered, self.chunk1.content) def test_chunk_caching(self): # a cached chunk should not make a database connection pass
class ChunkTagTestCase(TestCase): """ Tests the template tags """ # fixtures = ["chunks_initial_data.json"] # test of commit def setUp(self): self.chunk1 = Chunk(key="testchunk1", content="I LIKE PIE", description="") self.chunk1.save() # on production, CHUNKS_WRAP is False setattr(settings, "CHUNKS_WRAP", False) def test_chunk(self): # chunk is rendered rendered = render_template('{% load chunks %}{% chunk "testchunk1" %}') self.assertEqual(rendered, self.chunk1.content) # chunk is created and rendered rendered = render_template('{% load chunks %}{% chunk "testchunk_not_exists" %}') self.assertEqual(rendered, "testchunk_not_exists") self.assertEqual(len(Chunk.objects.all()), 2) def test_code_chunk(self): rendered = codechunk("testchunk1") self.assertEqual(rendered, self.chunk1.content) rendered = codechunk("testchunk_not_exists_2") self.assertEqual(rendered, "testchunk_not_exists_2") self.assertEqual(len(Chunk.objects.all()), 2) def test_chunk_filter(self): # 1 = wrap # 0 = don't wrap rendered = render_template('{% load chunks %}{{ "testchunk1"|chunk:0 }}') self.assertEqual(rendered, self.chunk1.content)
def view_code_upload_chunk(request): ''' Creates the necessary db objects for code to be created in Caesar as a chunk and redirects the user to their new chunk after submission. ''' user = request.user if request.method == "POST": code = request.POST["code"] file_name = request.POST["filename"] assignment = Assignment.objects.get(name='Personal Code Upload') new_submit_milestone = SubmitMilestone(assignment=assignment, name=file_name, duedate=datetime.datetime.now()) new_submit_milestone.save() new_submission = Submission(milestone=new_submit_milestone, name=file_name) new_submission.save() #save it so you can add an author which is a ManyToManyField new_submission.authors.add(user) new_submission.save() new_file = File(submission=new_submission, data=code, path=user.username+"/"+file_name) #does file path matter? new_file.save() code_size = len(code.split('\n')) new_chunk = Chunk(file=new_file, name=file_name, start=0, end=len(code), student_lines=code_size, staff_portion=0) #start, end, name new_chunk.save() return HttpResponseRedirect(reverse('chunks.views.view_chunk', args=(new_chunk.id,) ))
def create_chunk(file): return Chunk(file=file, name=get_name(file), start=0, end=len(file.data), class_type=get_type(file), staff_portion=0, student_lines=0)
def setUp(self): self.chunk1 = Chunk(key="testchunk1", content="I LIKE PIE", description="") self.chunk1.save() # on production, CHUNKS_WRAP is False setattr(settings, "CHUNKS_WRAP", False)