def test_form_renders_seq_text_input_widget(self): """ Tests correct rendering of form input text area :return: """ form = QueryForm() field = form['align_input'] self.assertIn('Paste in your alignment:<br>(FASTA, clustalw, stockholm or phylip)', field.label_tag()) self.assertIn('placeholder="Alignment (FASTA, clustalw, stockholm or phylip)"', form.as_p()) self.assertIn('class="form-control"', form.as_p())
def test_form_validation_returns_correct_seqrecord_alphabet(self): """ Tests that seqrecords get correct alphabet according to user input of seq_type :return: """ input_seqs = file_to_string('protein.fasta') form = QueryForm(data={'align_input': input_seqs, 'seq_type': 'Protein'}) self.assertTrue(form.is_valid()) for f in form.cleaned_data['align_input']: self.assertEqual(str(f.seq.alphabet), "Gapped(ExtendedIUPACProtein(), '-')", Gapped(ExtendedIUPACProtein()).letters) input_seqs = file_to_string('DNA.fasta') form = QueryForm(data={'align_input': input_seqs, 'seq_type': 'DNA'}) self.assertTrue(form.is_valid()) for f in form.cleaned_data['align_input']: self.assertEqual(str(f.seq.alphabet), "Gapped(ExtendedIUPACDNA(), '-')", Gapped(ExtendedIUPACDNA()).letters)
def validation(self, error_text, input_file='', seq_type='Protein'): """ Performs validation test for invalid forms, takes a user alignment input, asserts form.is_valid as false and checks the error :param: :return: """ if input_file: input_seqs = file_to_string(input_file) else: input_seqs = '' form = QueryForm(data={'align_input': input_seqs, 'seq_type': seq_type}) self.assertFalse(form.is_valid()) self.assertEqual( form.errors['align_input'], [error_text], format(form.errors['align_input']) )
def test_form_renders_sequence_type_radio_buttons(self): """ Tests correct rendering of form radio buttons :return: """ form = QueryForm() field = form['seq_type'] self.assertIn('Input sequence type:', field.label_tag()) self.assertIn('<input id="id_seq_type_0" name="seq_type" type="radio" value="Protein"', form.as_p()) self.assertIn('<input checked="checked" id="id_seq_type_1" name="seq_type" type="radio" value="DNA"', form.as_p())
def index(request): """ Serves home page :param request: HTTP request :return: HttpResponse object """ if request.method == 'GET': form = QueryForm() return render(request, 'base/index.html', {'form': form}) elif request.method == 'POST': form = QueryForm(request.POST) if form.is_valid(): align = form.cleaned_data['align_input'] save_align = Alignment.objects.create_alignment('name', align) slug = save_align.slug return redirect('/query-sequences/' + str(slug) + '/') else: return render(request, 'base/index.html', {'form': form}) else: return HttpResponseNotAllowed(['POST', 'GET'])