from django.test import LiveServerTestCase

try:
    from django.urls import reverse
except ImportError:  # django < 1.10
    from django.core.urlresolvers import reverse

from tusclient import client


class TestUploadView(LiveServerTestCase):

    def test_get_is_not_allowed(self):
        response = self.client.get(reverse('tus_upload'))
        assert response.status_code == 405

    def test_upload_file(self):
        tus_client = client.TusClient(
            self.live_server_url + reverse('tus_upload')
        )
        uploader = tus_client.uploader('tests/files/hello_world.txt', chunk_size=200)
        uploader.upload()
        assert uploader.request.status_code == 204

try:
    from django.urls import reverse
except ImportError:  # django < 1.10
    from django.core.urlresolvers import reverse

from tusclient.client import TusClient


class TestUploadView(object):

    def test_get_is_not_allowed(self, client):
        response = client.get(reverse('tus_upload'))
        assert response.status_code == 405

    def test_upload_file(self, live_server):
        tus_client = TusClient(
            live_server.url + reverse('tus_upload')
        )
        uploader = tus_client.uploader('tests/files/hello_world.txt', chunk_size=200)
        uploader.upload()
        assert uploader.request.status_code == 204

Refactor view to use fixtures from `pytest-django`.
Refactor view to use fixtures from `pytest-django`.

- from django.test import LiveServerTestCase
- 
  try:
      from django.urls import reverse
  except ImportError:  # django < 1.10
      from django.core.urlresolvers import reverse
  
- from tusclient import client
+ from tusclient.client import TusClient
  
  
- class TestUploadView(LiveServerTestCase):
+ class TestUploadView(object):
  
-     def test_get_is_not_allowed(self):
+     def test_get_is_not_allowed(self, client):
-         response = self.client.get(reverse('tus_upload'))
+         response = client.get(reverse('tus_upload'))
          assert response.status_code == 405
  
-     def test_upload_file(self):
+     def test_upload_file(self, live_server):
-         tus_client = client.TusClient(
+         tus_client = TusClient(
-             self.live_server_url + reverse('tus_upload')
+             live_server.url + reverse('tus_upload')
          )
          uploader = tus_client.uploader('tests/files/hello_world.txt', chunk_size=200)
          uploader.upload()
          assert uploader.request.status_code == 204
  
Refactor view to use fixtures from `pytest-django`.
## Code Before:
from django.test import LiveServerTestCase

try:
    from django.urls import reverse
except ImportError:  # django < 1.10
    from django.core.urlresolvers import reverse

from tusclient import client


class TestUploadView(LiveServerTestCase):

    def test_get_is_not_allowed(self):
        response = self.client.get(reverse('tus_upload'))
        assert response.status_code == 405

    def test_upload_file(self):
        tus_client = client.TusClient(
            self.live_server_url + reverse('tus_upload')
        )
        uploader = tus_client.uploader('tests/files/hello_world.txt', chunk_size=200)
        uploader.upload()
        assert uploader.request.status_code == 204

## Instruction:
Refactor view to use fixtures from `pytest-django`.
## Code After:
try:
    from django.urls import reverse
except ImportError:  # django < 1.10
    from django.core.urlresolvers import reverse

from tusclient.client import TusClient


class TestUploadView(object):

    def test_get_is_not_allowed(self, client):
        response = client.get(reverse('tus_upload'))
        assert response.status_code == 405

    def test_upload_file(self, live_server):
        tus_client = TusClient(
            live_server.url + reverse('tus_upload')
        )
        uploader = tus_client.uploader('tests/files/hello_world.txt', chunk_size=200)
        uploader.upload()
        assert uploader.request.status_code == 204
