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)
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)
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
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
def workstation_image(self): return get_workstation_image_or_404(**self.kwargs)
def get_permission_object(self): return get_workstation_image_or_404(**self.kwargs).workstation