def test_neighbor_boundary_high_valid(self): form = NearNeighborForm({ 'seqid': '2015-SEQ-0711', 'number_neighbors': 250 }) self.assertTrue(form.is_valid()) seqid, name, number_neighbors, uploaded_file = form.cleaned_data self.assertEqual(seqid, '2015-SEQ-0711') self.assertEqual(number_neighbors, 250)
def test_neighbor_uploaded_file_bad_extension(self): with open('olc_webportalv2/test_files/config.xml', 'rb') as upload_file: form = NearNeighborForm({ 'seqid': '', 'uploaded_file': SimpleUploadedFile(upload_file.name, upload_file.read()), 'number_neighbors': 4 }) self.assertFalse(form.is_valid())
def test_neighbor_uploaded_file_no_seqid(self): with open('olc_webportalv2/geneseekr/tests/good_fasta.fasta', 'rb') as upload_file: file_data = { 'uploaded_file': SimpleUploadedFile(upload_file.name, upload_file.read()) } form = NearNeighborForm({ 'seqid': '', 'number_neighbors': 4 }, file_data) self.assertTrue(form.is_valid())
def neighbor_request(request): form = NearNeighborForm() if request.method == 'POST': form = NearNeighborForm(request.POST, request.FILES) if form.is_valid(): seqid, name, number_neighbors, uploaded_file = form.cleaned_data if name is None: name = '' if seqid is None: seqid = '' if uploaded_file is None: uploaded_file_name = '' else: uploaded_file_name = uploaded_file.name nearest_neighbor_task = NearestNeighbors.objects.create( seqid=seqid, number_neighbors=number_neighbors, name=name, user=request.user, uploaded_file_name=uploaded_file_name, status='Processing') nearest_neighbor_task.save() if uploaded_file_name != '': container_name = 'neighbor-{}'.format(nearest_neighbor_task.pk) blob_client = BlockBlobService( account_name=settings.AZURE_ACCOUNT_NAME, account_key=settings.AZURE_ACCOUNT_KEY) blob_client.create_container(container_name) blob_client.create_blob_from_bytes( container_name=container_name, blob_name=uploaded_file_name, blob=uploaded_file.read()) run_nearest_neighbors.apply_async( queue='geneseekr', args=(nearest_neighbor_task.pk, ), countdown=10) return redirect('geneseekr:neighbor_result', neighbor_request_pk=nearest_neighbor_task.pk) return render(request, 'geneseekr/neighbor_request.html', {'form': form})
def neighbor_rename(request, neighbor_request_pk): neighbor_request_object = get_object_or_404(NearestNeighbors, pk=neighbor_request_pk) name = {'name': neighbor_request_object.name} form = NearNeighborForm(initial=name) if request.method == "POST": neighbor_request_object.name = request.POST["name"] neighbor_request_object.save() return redirect('geneseekr:neighbor_home') return render(request, 'rename.html', { 'neighbor_request': neighbor_request_object, 'form': form })
def test_neighbor_boundary_low_invalid(self): form = NearNeighborForm({'seqid': '2015-SEQ-0711', 'number_neighbors': 0}) self.assertFalse(form.is_valid())
def test_bad_seqid(self): form = NearNeighborForm({'seqid': '2015-FAKE-0711', 'number_neighbors': 10}) self.assertFalse(form.is_valid())
def test_negative_neighbors(self): form = NearNeighborForm({'seqid': '2015-SEQ-0711', 'number_neighbors': -10}) self.assertFalse(form.is_valid())