Пример #1
0
    def test_choices_ordered_by_votes_then_alphabetical(self):
        question = Question.objects.create(question_text='Are choices ordered correctly?')
        yes_choice = Choice.objects.create(question=question, choice_text='Yes')
        no_choice = Choice.objects.create(question=question, choice_text='No')
        resource = QuestionResource()
        resource.obj = question

        def get_choices():
            return map(lambda r: r.obj, resource.get_relations()['choices'])

        self.assertEqual(get_choices(), [no_choice, yes_choice])

        yes_choice.vote()
        self.assertEqual(get_choices(), [yes_choice, no_choice])
Пример #2
0
    def test_choices_ordered_by_votes_then_alphabetical(self):
        question = Question.objects.create(question_text='Are choices ordered correctly?')
        yes_choice = Choice.objects.create(question=question, choice_text='Yes')
        no_choice = Choice.objects.create(question=question, choice_text='No')
        resource = QuestionResource()
        resource.obj = question

        def get_choices():
            return map(lambda r: r.obj, resource.get_relations()['choices'])

        self.assertEqual(get_choices(), [no_choice, yes_choice])

        yes_choice.vote()
        self.assertEqual(get_choices(), [yes_choice, no_choice])
Пример #3
0
    try:
        connections['default'].cursor()
    except ImproperlyConfigured:
        # Database is not configured (DATABASE_URL may not be set)
        database_accessible = False
    except OperationalError:
        # Database is not accessible
        database_accessible = False

    if database_accessible:
        return JsonResponse({'status': 'ok'}, content_type=content_type)

    return JsonResponse({'status': 'fail'},
                        status=503,
                        content_type=content_type)


def error_view(request):
    raise Exception('Test exception')


urlpatterns = [
    path('', RootResource.as_view()),
    path('questions', QuestionCollectionResource.as_view()),
    path('questions/<int:pk>', QuestionResource.as_view()),
    path('questions/<int:question_pk>/choices/<int:pk>',
         ChoiceResource.as_view()),
    path('healthcheck', healthcheck_view),
    path('500', error_view),
]
Пример #4
0
from django.conf.urls import patterns, include, url
from polls.views import (RootResource, QuestionCollectionResource,
                         QuestionResource, ChoiceResource)


urlpatterns = patterns('',
    url(r'^$', RootResource.as_view()),
    url(r'^questions$', QuestionCollectionResource.as_view()),
    url(r'^questions/(?P<pk>[\d]+)$', QuestionResource.as_view()),
    url(r'^questions/(?P<question_pk>[\d]+)/choices/(?P<pk>[\d]+)$', ChoiceResource.as_view()),
)
Пример #5
0
from django.conf.urls import patterns, include, url
from polls.views import RootResource, QuestionCollectionResource, QuestionResource, ChoiceResource


urlpatterns = patterns(
    "",
    url(r"^$", RootResource.as_view()),
    url(r"^questions$", QuestionCollectionResource.as_view()),
    url(r"^questions/(?P<pk>[\d]+)$", QuestionResource.as_view()),
    url(r"^questions/(?P<question_pk>[\d]+)/choices/(?P<pk>[\d]+)$", ChoiceResource.as_view()),
)