コード例 #1
0
ファイル: test_utils.py プロジェクト: comic/comic-django
def test_get_workstation_image_or_404():
    # No default workstation
    with pytest.raises(Http404):
        get_workstation_image_or_404()

    default_wsi = WorkstationImageFactory(
        workstation__title=settings.DEFAULT_WORKSTATION_SLUG, ready=True
    )
    wsi = WorkstationImageFactory(ready=True)

    found_wsi = get_workstation_image_or_404()
    assert found_wsi == default_wsi

    found_wsi = get_workstation_image_or_404(slug=wsi.workstation.slug)
    assert found_wsi == wsi

    found_wsi = get_workstation_image_or_404(pk=wsi.pk)
    assert found_wsi == wsi

    # No images for workstation
    with pytest.raises(Http404):
        get_workstation_image_or_404(slug=WorkstationFactory().slug)

    # Incorrect pk
    with pytest.raises(Http404):
        get_workstation_image_or_404(pk=WorkstationFactory().pk)
コード例 #2
0
def test_get_workstation_image_or_404():
    # No default workstation
    with pytest.raises(Http404):
        get_workstation_image_or_404()

    default_workstation = Workstation.objects.get(
        slug=settings.DEFAULT_WORKSTATION_SLUG
    )
    default_wsi = WorkstationImageFactory(
        workstation=default_workstation, ready=True
    )
    wsi = WorkstationImageFactory(ready=True)

    found_wsi = get_workstation_image_or_404()
    assert found_wsi == default_wsi

    found_wsi = get_workstation_image_or_404(slug=wsi.workstation.slug)
    assert found_wsi == wsi

    found_wsi = get_workstation_image_or_404(pk=wsi.pk)
    assert found_wsi == wsi

    # No images for workstation
    with pytest.raises(Http404):
        get_workstation_image_or_404(slug=WorkstationFactory().slug)

    # Incorrect pk
    with pytest.raises(Http404):
        get_workstation_image_or_404(pk=WorkstationFactory().pk)
コード例 #3
0
    def get_redirect_url(self, *args, **kwargs):
        workstation_image = get_workstation_image_or_404(**kwargs)
        session = get_or_create_active_session(
            user=self.request.user, workstation_image=workstation_image)

        url = session.get_absolute_url()

        qs = self.request.META.get("QUERY_STRING", "")
        if qs:
            url = f"{url}?{qs}"

        return url
コード例 #4
0
ファイル: views.py プロジェクト: comic/comic-django
    def get_redirect_url(self, *args, **kwargs):
        workstation_image = get_workstation_image_or_404(**kwargs)
        session = get_or_create_active_session(
            user=self.request.user, workstation_image=workstation_image
        )

        url = session.get_absolute_url()

        qs = self.request.META.get("QUERY_STRING", "")
        if qs:
            url = f"{url}?{qs}"

        return url
コード例 #5
0
 def workstation_image(self):
     return get_workstation_image_or_404(**self.kwargs)
コード例 #6
0
 def get_permission_object(self):
     return get_workstation_image_or_404(**self.kwargs).workstation