<commit_before>import os

from django.core.files.uploadedfile import UploadedFile

from rest_framework import status

from hs_core.hydroshare import resource
from hs_core.hydroshare.utils import resource_file_add_process
from hs_core.views.utils import create_folder, move_or_rename_file_or_folder

from .base import HSRESTTestCase


class TestSetFileTypeEndPoint(HSRESTTestCase):
    def setUp(self):
        super(TestSetFileTypeEndPoint, self).setUp()
        self.raster_file_name = 'cea.tif'
        self.raster_file_path = 'hs_core/tests/data/cea.tif'

        self.rtype = 'CompositeResource'
        self.title = 'My Test resource'
        self.resource = resource.create_resource(self.rtype,
                                                 self.user,
                                                 self.title)

        self.resources_to_delete.append(self.resource.short_id)

    def test_set_file_type_success_1(self):
        # here we will set the tif file to GeoRaster file type

        # resource should have no file at this point
        self.assertEqual(self.resource.files.count(), 0)
        # add the tif file to the composite resource
        tif_file_obj = open(self.raster_file_path, "r")
        uploaded_file = UploadedFile(file=tif_file_obj,
                                     name=os.path.basename(tif_file_obj.name))
        resource_file_add_process(resource=self.resource,
                                  files=(uploaded_file,), user=self.user)

        # resource should have one file at this point
        self.assertEqual(self.resource.files.count(), 1)
        res_file = self.resource.files.all().first()
        self.assertEqual(res_file.file_name, self.raster_file_name)
<commit_msg>[#1993] pep8<commit_after>import os

from django.core.files.uploadedfile import UploadedFile

from rest_framework import status

from hs_core.hydroshare import resource
from hs_core.hydroshare.utils import resource_file_add_process
from hs_core.views.utils import create_folder, move_or_rename_file_or_folder

from .base import HSRESTTestCase


class TestSetFileTypeEndPoint(HSRESTTestCase):
    def setUp(self):
        super(TestSetFileTypeEndPoint, self).setUp()
        self.raster_file_name = 'cea.tif'
        self.raster_file_path = 'hs_core/tests/data/cea.tif'

        self.rtype = 'CompositeResource'
        self.title = 'My Test resource'
        self.resource = resource.create_resource(self.rtype,
                                                 self.user,
                                                 self.title)

        self.resources_to_delete.append(self.resource.short_id)

    def test_set_file_type_success_1(self):
        # here we will set the tif file to GeoRaster file type

        # resource should have no file at this point
        self.assertEqual(self.resource.files.count(), 0)
        # add the tif file to the composite resource
        tif_file_obj = open(self.raster_file_path, "r")
        uploaded_file = UploadedFile(file=tif_file_obj,
                                     name=os.path.basename(tif_file_obj.name))
        resource_file_add_process(resource=self.resource,
                                  files=(uploaded_file,), user=self.user)

        # resource should have one file at this point
        self.assertEqual(self.resource.files.count(), 1)
        res_file = self.resource.files.all().first()
        self.assertEqual(res_file.file_name, self.raster_file_name)
{'fraction_non_alphanumeric': 0.07734646581691773, 'fraction_numerical': 0.003186558516801854, 'mean_word_length': 2.484359233097881, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6192124', 'n_tokens_mistral': 1023, 'n_tokens_neox': 968, 'n_words': 205}