Esempio n. 1
0
    def test_get_file_content(self):
        test_path = Utils.join_path(os.getcwd(), 'empty_file.json')

        Utils.create_empty_file(test_path)
        Utils.write_to_file(test_path, 'Some content')
        file_content = Utils.get_file_content(test_path)

        self.assertEqual(file_content, 'Some content')

        os.remove(test_path)
        self.assertFalse(os.path.exists(test_path))
Esempio n. 2
0
  def test_get_file_content(self):
    test_path = Utils.join_path(os.getcwd(), 'empty_file.json')

    Utils.create_empty_file(test_path)
    Utils.write_to_file(test_path,'Some content')
    file_content = Utils.get_file_content(test_path)

    self.assertEqual(file_content, 'Some content')

    os.remove(test_path)
    self.assertFalse(os.path.exists(test_path))
Esempio n. 3
0
    def test_write_to_file(self):
        test_filename = 'empty_file.txt'
        message = 'file content'
        file_path = Utils.join_path(os.getcwd(), test_filename)

        self.assertFalse(Utils.exists_path(file_path))
        Utils.write_to_file(file_path, message)

        self.assertTrue(os.path.exists(file_path))

        with open(file_path, 'rb') as f:
            self.assertEqual(f.read().decode('utf-8').find(message), 0)

        os.remove(file_path)
        self.assertFalse(os.path.exists(file_path))

        file_path = Utils.join_path(os.getcwd(), 'some_path', 'sub_path',
                                    test_filename)

        Utils.write_to_file(file_path, message)
        self.assertTrue(os.path.exists(file_path))
        with open(file_path, 'rb') as f:
            self.assertEqual(f.read().decode('utf-8').find(message), 0)
        os.remove(file_path)
        self.assertFalse(os.path.exists(file_path))
        shutil.rmtree(Utils.join_path(os.getcwd(), 'some_path'))

        os.makedirs(Utils.join_path(os.getcwd(), 'some_path'))

        file_path = Utils.join_path(os.getcwd(), 'some_path', 'sub_path',
                                    test_filename)

        Utils.write_to_file(file_path, message)
        self.assertTrue(os.path.exists(file_path))
        with open(file_path, 'rb') as f:
            self.assertEqual(f.read().decode('utf-8').find(message), 0)
        os.remove(file_path)
        self.assertFalse(os.path.exists(file_path))

        Utils.write_to_file(file_path, {"some": "content"},
                            action='a+',
                            as_json=True)
        self.assertTrue(os.path.exists(file_path))
        with open(file_path, 'rb') as f:
            self.assertEqual(f.read().decode('utf-8'), '{"some": "content"}')

        os.remove(file_path)
        self.assertFalse(os.path.exists(file_path))

        shutil.rmtree(Utils.join_path(os.getcwd(), 'some_path'))
Esempio n. 4
0
  def test_write_to_file(self):
    test_filename = 'empty_file.txt'
    message = 'file content'
    file_path = Utils.join_path(os.getcwd(), test_filename)

    self.assertFalse(Utils.exists_path(file_path))
    Utils.write_to_file(file_path, message)

    self.assertTrue(os.path.exists(file_path))

    with open(file_path, 'rb') as f:
      self.assertEqual(f.read().decode('utf-8').find(message), 0)

    os.remove(file_path)
    self.assertFalse(os.path.exists(file_path))

    file_path = Utils.join_path(os.getcwd(), 'some_path', 'sub_path', test_filename)

    Utils.write_to_file(file_path, message)
    self.assertTrue(os.path.exists(file_path))
    with open(file_path, 'rb') as f:
      self.assertEqual(f.read().decode('utf-8').find(message), 0)
    os.remove(file_path)
    self.assertFalse(os.path.exists(file_path))

    self.create_folder(Utils.join_path(os.getcwd(), 'some_path'))

    file_path = Utils.join_path(os.getcwd(), 'some_path', 'sub_path', test_filename)

    Utils.write_to_file(file_path, message)
    self.assertTrue(os.path.exists(file_path))
    with open(file_path, 'rb') as f:
      self.assertEqual(f.read().decode('utf-8').find(message), 0)
    os.remove(file_path)
    self.assertFalse(os.path.exists(file_path))

    Utils.write_to_file(file_path, {"some": "content"}, action='a+', as_json=True)
    self.assertTrue(os.path.exists(file_path))
    with open(file_path, 'rb') as f:
      self.assertEqual(f.read().decode('utf-8'), '{"some": "content"}')

    os.remove(file_path)
    self.assertFalse(os.path.exists(file_path))

    self.delete_folder(Utils.join_path(os.getcwd(), 'some_path'))