import json

from rest_framework.test import APIClient
from rest_framework import status
from rest_framework.test import APITestCase

from hs_core.hydroshare.utils import get_resource_types


class TestResourceTypes(APITestCase):

    def setUp(self):
        self.client = APIClient()

    def test_resource_typelist(self):
        resource_types = set([t.__name__ for t in get_resource_types()])

        response = self.client.get('/hsapi/resourceTypes/', format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        content = json.loads(response.content)
        rest_resource_types = set([t['resource_type'] for t in content])

        self.assertEqual(resource_types, rest_resource_types)
import json

from rest_framework.test import APIClient
from rest_framework import status
from rest_framework.test import APITestCase


class TestResourceTypes(APITestCase):

    def setUp(self):
        self.client = APIClient()

        # Use a static list so that this test breaks when a resource type is
        # added or removed (so that the test can be updated)
        self.resource_types = {'GenericResource',
                               'RasterResource',
                               'RefTimeSeriesResource',
                               'TimeSeriesResource',
                               'NetcdfResource',
                               'ModelProgramResource',
                               'ModelInstanceResource',
                               'ToolResource',
                               'SWATModelInstanceResource',
                               'GeographicFeatureResource',
                               'ScriptResource'}

    def test_resource_typelist(self):
        response = self.client.get('/hsapi/resourceTypes/', format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        content = json.loads(response.content)
        rest_resource_types = set([t['resource_type'] for t in content])

        self.assertEqual(self.resource_types, rest_resource_types)

Make resource type list static
Make resource type list static

  import json
  
  from rest_framework.test import APIClient
  from rest_framework import status
  from rest_framework.test import APITestCase
- 
- from hs_core.hydroshare.utils import get_resource_types
  
  
  class TestResourceTypes(APITestCase):
  
      def setUp(self):
          self.client = APIClient()
  
+         # Use a static list so that this test breaks when a resource type is
+         # added or removed (so that the test can be updated)
+         self.resource_types = {'GenericResource',
+                                'RasterResource',
+                                'RefTimeSeriesResource',
+                                'TimeSeriesResource',
+                                'NetcdfResource',
+                                'ModelProgramResource',
+                                'ModelInstanceResource',
+                                'ToolResource',
+                                'SWATModelInstanceResource',
+                                'GeographicFeatureResource',
+                                'ScriptResource'}
+ 
      def test_resource_typelist(self):
-         resource_types = set([t.__name__ for t in get_resource_types()])
- 
          response = self.client.get('/hsapi/resourceTypes/', format='json')
          self.assertEqual(response.status_code, status.HTTP_200_OK)
          content = json.loads(response.content)
          rest_resource_types = set([t['resource_type'] for t in content])
  
-         self.assertEqual(resource_types, rest_resource_types)
+         self.assertEqual(self.resource_types, rest_resource_types)
+ 
Make resource type list static
## Code Before:
import json

from rest_framework.test import APIClient
from rest_framework import status
from rest_framework.test import APITestCase

from hs_core.hydroshare.utils import get_resource_types


class TestResourceTypes(APITestCase):

    def setUp(self):
        self.client = APIClient()

    def test_resource_typelist(self):
        resource_types = set([t.__name__ for t in get_resource_types()])

        response = self.client.get('/hsapi/resourceTypes/', format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        content = json.loads(response.content)
        rest_resource_types = set([t['resource_type'] for t in content])

        self.assertEqual(resource_types, rest_resource_types)
## Instruction:
Make resource type list static
## Code After:
import json

from rest_framework.test import APIClient
from rest_framework import status
from rest_framework.test import APITestCase


class TestResourceTypes(APITestCase):

    def setUp(self):
        self.client = APIClient()

        # Use a static list so that this test breaks when a resource type is
        # added or removed (so that the test can be updated)
        self.resource_types = {'GenericResource',
                               'RasterResource',
                               'RefTimeSeriesResource',
                               'TimeSeriesResource',
                               'NetcdfResource',
                               'ModelProgramResource',
                               'ModelInstanceResource',
                               'ToolResource',
                               'SWATModelInstanceResource',
                               'GeographicFeatureResource',
                               'ScriptResource'}

    def test_resource_typelist(self):
        response = self.client.get('/hsapi/resourceTypes/', format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        content = json.loads(response.content)
        rest_resource_types = set([t['resource_type'] for t in content])

        self.assertEqual(self.resource_types, rest_resource_types)
