Skip to content

Commit 9db1db1

Browse files
House-keeping
1 parent ff6a4b4 commit 9db1db1

File tree

7 files changed

+14
-108
lines changed

7 files changed

+14
-108
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ It uses email as an unique key and supports a range of authentication methods th
114114
```python
115115
from moonsheep.views import ChooseNicknameView
116116

117-
urlpatterns = [an url
117+
urlpatterns = [
118118
# name needs to be set to 'choose-nickname'
119119
path('get-a-nickname', ChooseNicknameView.as_view(template_name='nickname.html'), name='choose-nickname'),
120120
]

moonsheep/forms.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
from django.core.validators import RegexValidator, ValidationError
55

66

7-
class NewTaskForm(forms.Form):
8-
url = forms.URLField(label="Report URL")
9-
10-
117
class MultipleRangeField(forms.CharField):
128
default_validators = [RegexValidator(regex="[\w\d]+[\w]?(-[\w\d]+[\w]?)?(,[\w\d]+[\w]?(-[\w\d]+[\w]?)?)*")]
139

moonsheep/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
'MIN_ENTRIES_TO_CROSSCHECK': 3,
1212
'MIN_ENTRIES_TO_MARK_DIRTY': 4,
1313
'FAKER_LOCALE': 'it_IT', # See supported locales at https://github.com/joke2k/faker#localization
14-
'USER_AUTHENTICATION': 'nickname' # available settings: 'nickname', 'anonymous', TODO email #60
15-
# 'APP': 'myapp' # needs to be set in project
14+
'USER_AUTHENTICATION': 'anonymous' # available settings: 'nickname', 'anonymous', TODO email #60
15+
# 'APP': 'myapp' # needs to be set in project # TODO (should not be set at all)
1616
}
1717

1818
AUTH_USER_MODEL = 'moonsheep.User'

moonsheep/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AbstractTask(object):
2424
def __init__(self, instance: Task):
2525
self.instance = instance
2626
self.id = instance.id # TODO attr rather than field
27-
self.params = instance.params
27+
self.params = instance.params # TODO attr rather than field
2828

2929
# per-instance overrides
3030
if 'task_form' in self.params:

moonsheep/templates/error-messages/no-tasks.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<li> Provide tasks
77
<ol>
88
<li>For development of forms you might want to enable rotating through available task types by setting
9-
<code>MOONSHEEP['DEV_ROTATE_TASKS'] = true</code>
9+
<code>MOONSHEEP['DEV_ROTATE_TASKS'] = True</code>
1010
</li>
11-
<li><a href="{% url "ms-new-task" %}">In production you want to import tasks to the system</a>
12-
and also come up with a better error template for your users than this
11+
<li><a href="{% url "documents" %}">In production you want to import tasks to the system</a>
12+
and also come up with a better error template for your users than this (TODO how to do it <!-- TODO configurable error_template or error handling --> )
1313
</li>
1414
</ol>
1515
</li>

moonsheep/tests/tests.py

Lines changed: 2 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
from unittest.mock import MagicMock, patch, sentinel, call
1212

1313
from moonsheep.exceptions import PresenterNotDefined, TaskMustSetTemplate, NoTasksLeft
14-
from moonsheep.forms import NewTaskForm, MultipleRangeField
14+
from moonsheep.forms import MultipleRangeField
1515
from moonsheep.mapper import ModelMapper
1616
from moonsheep.tasks import AbstractTask
1717
from moonsheep.verifiers import equals, OrderedListVerifier
18-
from moonsheep.views import unpack_post, TaskView, NewTaskFormView
18+
from moonsheep.views import unpack_post, TaskView
1919

2020

2121
# TODO dev env: `DJANGO_SETTINGS_MODULE=moonsheep.tests.migrations_settings django-admin makemigrations` should return that everything is up to date
@@ -84,9 +84,6 @@
8484

8585
# TODO test error handling for Tasks with no form and no template
8686

87-
# views.py
88-
PYBOSSA_PROJECT_ID = 1
89-
9087

9188
def setup_view(view, request, *args, **kwargs):
9289
"""
@@ -112,10 +109,8 @@ def setUp(self):
112109
'task_form': 'myapp.forms.TaskForm'
113110
}
114111
}
115-
self.pybossa_project_id = 1
116112
self.task_id = 1
117113
self.post_data = {
118-
'_project_id': self.pybossa_project_id,
119114
'_task_id': self.task_id
120115
}
121116

@@ -302,9 +297,6 @@ def test_get_context_data(
302297
context = view.get_context_data()
303298
self.assertIsInstance(context['task'], AbstractTask)
304299
self.assertEqual(context['task'], view.task)
305-
self.assertEqual(context['project_id'], PYBOSSA_PROJECT_ID)
306-
from moonsheep.settings import PYBOSSA_BASE_URL
307-
self.assertEqual(context['pybossa_url'], PYBOSSA_BASE_URL)
308300

309301
@patch('moonsheep.views.TaskView._get_task')
310302
@patch('moonsheep.views.TaskView.initialize_task_data')
@@ -337,9 +329,6 @@ def test_get_context_data_no_task(
337329
self.assertTrue(context['error'])
338330
self.assertEqual(context['message'], 'Sample error message')
339331
self.assertEqual(context['template'], 'Sample error template')
340-
self.assertEqual(context['project_id'], PYBOSSA_PROJECT_ID)
341-
from moonsheep.settings import PYBOSSA_BASE_URL
342-
self.assertEqual(context['pybossa_url'], PYBOSSA_BASE_URL)
343332

344333
@patch('moonsheep.models.klass_from_name')
345334
def test_initialize_task_data(
@@ -408,7 +397,6 @@ def test_get_task_new(
408397
# # TODO: FIXME
409398
# @patch('pbclient.get_task')
410399
# @patch('moonsheep.tasks.AbstractTask.create_task_instance')
411-
# @override_settings(TASK_SOURCE=PYBOSSA_SOURCE)
412400
# def test_get_task_old_not_development(
413401
# self,
414402
# create_task_instance_mock: MagicMock,
@@ -441,8 +429,6 @@ def test_form_valid(self):
441429

442430
# TODO: FIXME
443431
# @patch('moonsheep.views.TaskView.get_random_pybossa_task')
444-
# @override_settings(TASK_SOURCE=PYBOSSA_SOURCE)
445-
# @patch('moonsheep.settings.TASK_SOURCE', PYBOSSA_SOURCE)
446432
# def test_get_new_task_random_pybossa_task(self, get_random_pybossa_task_mock: MagicMock):
447433
# from moonsheep.views import TaskView
448434
# request = self.factory.get(self.fake_path)
@@ -467,7 +453,6 @@ def test_form_valid(self):
467453
# TODO: test tasks rotation
468454
def test_get_random_mocked_task_data(self):
469455
request = self.factory.get(self.fake_path)
470-
base_task.register(AbstractTask)
471456
view = TaskView()
472457
view = setup_view(view, request)
473458
task = view.get_random_mocked_task_data()
@@ -479,7 +464,6 @@ def test_get_random_mocked_task_data(self):
479464
},
480465
'id': 'moonsheep.tasks.AbstractTask'
481466
})
482-
base_task.clear()
483467

484468
def test_get_random_mocked_task_data_no_registry(self):
485469
request = self.factory.get(self.fake_path)
@@ -512,81 +496,6 @@ def test_send_task(self):
512496
pass
513497

514498

515-
@override_settings(ROOT_URLCONF='moonsheep.urls')
516-
class NewTaskFormViewTest(DjangoTestCase):
517-
def setUp(self):
518-
self.factory = RequestFactory()
519-
self.client = Client()
520-
self.path = reverse('ms-new-task')
521-
self.pybossa_project_id = 1
522-
self.task_id = 1
523-
524-
def test_get_success_url(self):
525-
request = self.factory.get(self.path)
526-
view = NewTaskFormView()
527-
view.request = request
528-
success_url = view.get_success_url()
529-
self.assertEquals(success_url, self.path)
530-
531-
@patch('pbclient.set')
532-
@patch('pbclient.create_task')
533-
def test_form_valid_no_registry(
534-
self,
535-
create_task_mock: MagicMock,
536-
set_mock: MagicMock
537-
):
538-
request = self.factory.get(self.path)
539-
view = NewTaskFormView()
540-
view.request = request
541-
form_data = {
542-
'url': 'http://byleco.pl'
543-
}
544-
form = NewTaskForm(form_data)
545-
form.full_clean()
546-
with self.assertRaises(ImproperlyConfigured):
547-
view.form_valid(form)
548-
549-
@patch('pbclient.set')
550-
@patch('pbclient.create_task')
551-
def test_form_valid(
552-
self,
553-
create_task_mock: MagicMock,
554-
set_mock: MagicMock
555-
):
556-
request = self.factory.get(self.path)
557-
initial_task.register(AbstractTask)
558-
view = NewTaskFormView()
559-
view.request = request
560-
form_data = {
561-
'url': 'http://byleco.pl'
562-
}
563-
form = NewTaskForm(form_data)
564-
form.full_clean()
565-
success_url = view.form_valid(form).url
566-
self.assertEquals(success_url, self.path)
567-
initial_task.clear()
568-
# set_mock.assert_has_calls([call('endpoint', settings.PY)])
569-
# create_task_mock.assert_any_call({
570-
# 'project_id': PYBOSSA_PROJECT_ID,
571-
# 'info': {
572-
# 'type':
573-
# }
574-
# })
575-
576-
# def test_form_valid_no_base_tasks(self):
577-
578-
579-
class WebhookTaskRunViewTest(UnitTestCase):
580-
def test_dispatch(self):
581-
pass
582-
583-
def test_get(self):
584-
pass
585-
586-
def test_post(self):
587-
pass
588-
589-
590499
class UnpackPostTest(UnitTestCase):
591500
"""
592501
It tests moonsheep.views.unpack_post function.

moonsheep/views.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131

3232
class TaskView(UserRequiredMixin, FormView):
33-
task_type = None
33+
task_type: AbstractTask = None
34+
template_name: str = None
3435
form_class = None
3536
error_message = None
3637
error_template = None
@@ -49,16 +50,16 @@ def get(self, request, *args, **kwargs):
4950
try:
5051
self.task_type = self._get_task()
5152
self.configure_template_and_form()
52-
except NoTasksLeft:
53+
except NoTasksLeft: # TODO test case for project
5354
self.error_message = 'Task Chooser returned no tasks'
5455
self.error_template = 'error-messages/no-tasks.html'
5556
self.task_type = None
56-
self.template_name = 'views/message.html'
57+
self.template_name = 'error-messages/no-tasks.html' # TODO we do not want to define the main err template in Moonsheep. How to generally handle messages and errors?
5758
except PresenterNotDefined:
5859
self.error_message = 'Presenter not defined'
5960
self.error_template = 'error-messages/presenter-not-defined.html'
6061
self.task_type = None
61-
self.template_name = 'views/message.html'
62+
self.template_name = 'error-messages/presenter-not-defined.html' # TODO we do not want to main err template it in Moonsheep. How to generally handle messages and errors?
6263

6364
context = self.get_context_data(**kwargs)
6465
return self.render_to_response(context)

0 commit comments

Comments
 (0)