Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions exodus/analysis_query/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from django import forms
from django.utils.translation import gettext_lazy as _

from .models import AnalysisRequest

Expand All @@ -9,6 +10,13 @@ class Meta:
model = AnalysisRequest
fields = ('handle', 'source')

def clean(self):
cleaned_data = super().clean()
handle = cleaned_data.get('handle')
if not handle:
self.add_error('handle', _('A handle is required to submit an analysis.'))
return cleaned_data


class UploadRequestForm(forms.ModelForm):
class Meta:
Expand Down
22 changes: 20 additions & 2 deletions exodus/analysis_query/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

# from django.test import TestCase
from unittest.mock import patch

# Create your tests here.
from django.test import TestCase

from .forms import AnalysisRequestForm


class AnalysisRequestFormTests(TestCase):

def test_empty_handle_is_rejected(self):
form = AnalysisRequestForm(data={'handle': '', 'source': 'google'})

self.assertFalse(form.is_valid())
self.assertIn('handle', form.errors)

@patch('analysis_query.models._is_app_in_store', return_value=True)
def test_valid_handle_is_accepted(self, mock_store):
form = AnalysisRequestForm(
data={'handle': 'com.example.app', 'source': 'google'})

self.assertTrue(form.is_valid())