<commit_before># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

from webapi_tests.semiauto import TestCase
from webapi_tests.device_storage import DeviceStorageTestCommon


class TestSdcardStorage(TestCase, DeviceStorageTestCommon):

    def setUp(self):
        self.file_name = "test_sdcard_certsuite"
        self.file_contents = "This is a sample text file"
        self.addCleanup(self.clean_up)
        super(TestSdcardStorage, self).setUp()
        self.marionette.execute_script("window.wrappedJSObject.sdcard = navigator.getDeviceStorage(\"sdcard\")")

    def test_sdcard_availability(self):
        ret_check_sdcard = self.is_sdcard_available()
        self.assertEqual(True, ret_check_sdcard, "SDCard is unavailable. "
                        "Please ensure there is an SD card in the device and "
                        "usb storage sharing is not enabled")

    def test_add_namedfile_sdcard(self):
        if self.is_sdcard_available():
            #add the file to sdcard
            ret_add_namedfile_sdcard = self.add_namedfile_sdcard(self.file_name,
                                                            self.file_contents)

            self.assertEqual(True, ret_add_namedfile_sdcard, "Unable "
                             "to add the file")
            #delete the file for cleanup
            if self.delete_file_sdcard(self.file_name) is False:
                self.fail("Failed to delete the file")
        else:
            self.fail("Sdcard is unavailable")

    def test_get_file_sdcard(self):
        if self.is_sdcard_available():
            if self.add_namedfile_sdcard(self.file_name, self.file_contents):
                #get the file from sdcard
                ret_file_abspath_sdcard = self.get_file_sdcard(self.file_name)
                if ret_file_abspath_sdcard is False:
                    self.fail("Not Found the file")
                #delete the file for cleanup
                if self.delete_file_sdcard(self.file_name) is False:
                    self.fail("Failed to delete the file")
            else:
                self.fail("Unable to add the file")
        else:
            self.fail("Sdcard is unavailable")

    def test_delete_file_sdcard(self):
        if self.is_sdcard_available():
            if self.add_namedfile_sdcard(self.file_name, self.file_contents):
                #delete the file
                ret_file_delete_sdcard = self.delete_file_sdcard(self.file_name)
                self.assertEqual(True, ret_file_delete_sdcard, "Unable to "
                                "delete the file")
            else:
                self.fail("Unable to add the file")
        else:
            self.fail("Sdcard is unavailable")

    def test_enumerate_files_sdcard(self):
        if self.is_sdcard_available():
            if self.add_namedfile_sdcard(self.file_name, self.file_contents):
                #enumerate the files
                filelist_sdcard_unicode = self.enumerate_files_sdcard()
                self.assertNotEqual(0, len(filelist_sdcard_unicode), "There "
                                 "should be at least one file added as part "
                                 "of this test")
                ret_file_delete_sdcard = self.delete_file_sdcard(self.file_name)
                if self.delete_file_sdcard(self.file_name) is False:
                    self.fail("Failed to delete the file")
            else:
                self.fail("Unable to add the file")
        else:<commit_msg>Bug 1016295 - Device storage tests (disable until finished/passing)<commit_after># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import unittest

from webapi_tests.semiauto import TestCase
from webapi_tests.device_storage import DeviceStorageTestCommon


class TestSdcardStorage(TestCase, DeviceStorageTestCommon):

    def setUp(self):
        self.file_name = "test_sdcard_certsuite"
        self.file_contents = "This is a sample text file"
        self.addCleanup(self.clean_up)
        super(TestSdcardStorage, self).setUp()
        self.marionette.execute_script("window.wrappedJSObject.sdcard = navigator.getDeviceStorage(\"sdcard\")")

    @unittest.skip("Currently disabled, see bug 1016295")
    def test_sdcard_availability(self):
        ret_check_sdcard = self.is_sdcard_available()
        self.assertEqual(True, ret_check_sdcard, "SDCard is unavailable. "
                        "Please ensure there is an SD card in the device and "
                        "usb storage sharing is not enabled")

    @unittest.skip("Currently disabled, see bug 1016295")
    def test_add_namedfile_sdcard(self):
        if self.is_sdcard_available():
            #add the file to sdcard
            ret_add_namedfile_sdcard = self.add_namedfile_sdcard(self.file_name,
                                                            self.file_contents)

            self.assertEqual(True, ret_add_namedfile_sdcard, "Unable "
                             "to add the file")
            #delete the file for cleanup
            if self.delete_file_sdcard(self.file_name) is False:
                self.fail("Failed to delete the file")
        else:
            self.fail("Sdcard is unavailable")

    @unittest.skip("Currently disabled, see bug 1016295")
    def test_get_file_sdcard(self):
        if self.is_sdcard_available():
            if self.add_namedfile_sdcard(self.file_name, self.file_contents):
                #get the file from sdcard
                ret_file_abspath_sdcard = self.get_file_sdcard(self.file_name)
                if ret_file_abspath_sdcard is False:
                    self.fail("Not Found the file")
                #delete the file for cleanup
                if self.delete_file_sdcard(self.file_name) is False:
                    self.fail("Failed to delete the file")
            else:
                self.fail("Unable to add the file")
        else:
            self.fail("Sdcard is unavailable")

    @unittest.skip("Currently disabled, see bug 1016295")
    def test_delete_file_sdcard(self):
        if self.is_sdcard_available():
            if self.add_namedfile_sdcard(self.file_name, self.file_contents):
                #delete the file
                ret_file_delete_sdcard = self.delete_file_sdcard(self.file_name)
                self.assertEqual(True, ret_file_delete_sdcard, "Unable to "
                                "delete the file")
            else:
                self.fail("Unable to add the file")
        else:
            self.fail("Sdcard is unavailable")

    @unittest.skip("Currently disabled, see bug 1016295")
    def test_enumerate_files_sdcard(self):
        if self.is_sdcard_available():
            if self.add_namedfile_sdcard(self.file_name, self.file_contents):
                #enumerate the files
                filelist_sdcard_unicode = self.enumerate_files_sdcard()
                self.assertNotEqual(0, len(filelist_sdcard_unicode), "There "
                                 "should be at least one file added as part "
                                 "of this test")
                ret_file_delete_sdcard = self.delete_file_sdcard(self.file_name)
                if self.delete_file_sdcard(self.file_name) is False:
                    self.fail("Failed to delete the file")
            else:
                self.fail("Unable to add the file")
        else:
{'fraction_non_alphanumeric': 0.07508845498624034, 'fraction_numerical': 0.0068143100511073255, 'mean_word_length': 2.047923322683706, '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': '2135550', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2074, 'n_words': 523}