def test_fail_with_bad_url(self):
        ext_dep_file_path = os.path.join(test_dir, "bad_ext_dep.json")
        with open(ext_dep_file_path, "w+") as ext_dep_file:
            ext_dep_file.write(bad_json_file)

        ext_dep_descriptor = EDF.ExternDepDescriptor(
            ext_dep_file_path).descriptor_contents
        ext_dep = WebDependency(ext_dep_descriptor)
        with self.assertRaises(urllib.error.HTTPError):
            ext_dep.fetch()
            self.fail("should have thrown an Exception")
    def test_single_file(self):
        ext_dep_file_path = os.path.join(test_dir, "good_ext_dep.json")
        with open(ext_dep_file_path, "w+") as ext_dep_file:
            ext_dep_file.write(
                json.dumps(single_file_extdep))  # dump to a file

        ext_dep_descriptor = EDF.ExternDepDescriptor(
            ext_dep_file_path).descriptor_contents
        ext_dep = WebDependency(ext_dep_descriptor)
        ext_dep.fetch()

        ext_dep_name = single_file_extdep['name'] + "_extdep"
        file_path = os.path.join(test_dir, ext_dep_name,
                                 single_file_extdep['internal_path'])
        if not os.path.isfile(file_path):
            self.fail("The downloaded file isn't there")
    def test_sha256_lowercase_single_file(self):
        ext_dep_file_path = os.path.join(test_dir, "good_ext_dep.json")
        jquery_json = jquery_json_file.copy()
        jquery_json["sha256"] = jquery_json["sha256"].lower()
        with open(ext_dep_file_path, "w+") as ext_dep_file:
            ext_dep_file.write(json.dumps(jquery_json))  # dump to a file

        ext_dep_descriptor = EDF.ExternDepDescriptor(
            ext_dep_file_path).descriptor_contents
        ext_dep = WebDependency(ext_dep_descriptor)
        ext_dep.fetch()

        ext_dep_name = jquery_json['name'] + "_extdep"
        file_path = os.path.join(test_dir, ext_dep_name,
                                 jquery_json['internal_path'])
        if not os.path.isfile(file_path):
            self.fail("The downloaded file isn't there")
    def test_sha256_whole_tar_directory(self):
        ext_dep_file_path = os.path.join(test_dir, "good_ext_dep.json")

        with open(ext_dep_file_path, "w+") as ext_dep_file:
            ext_dep_file.write(
                json.dumps(tar_directory_extdep))  # dump to a file

        ext_dep_descriptor = EDF.ExternDepDescriptor(
            ext_dep_file_path).descriptor_contents
        ext_dep = WebDependency(ext_dep_descriptor)
        ext_dep.fetch()

        ext_dep_name = tar_directory_extdep['name'] + "_extdep"
        folder_path = os.path.join(test_dir, ext_dep_name)
        if not os.path.exists(os.path.join(folder_path, "README")):
            logging.warning(folder_path)
            self.fail()