def test__is_idempotent(self): path = self.set_bootresources_yaml(factory.make_string()) upgrade_cluster.retire_bootresources_yaml() content_after_upgrade = read_text_file(path) upgrade_cluster.retire_bootresources_yaml() self.assertThat(path, FileContains(content_after_upgrade, encoding="utf-8"))
def test__prefixes_header_to_file_if_present(self): content = factory.make_string() path = self.set_bootresources_yaml(content) upgrade_cluster.retire_bootresources_yaml() self.assertThat( path, FileContains(upgrade_cluster.BOOTRESOURCES_WARNING + content, encoding="utf-8"))
def test__survives_encoding_problems(self): path = os.path.join(self.make_dir(), 'bootresources.yaml') content = b'[[%s]]' % sample_binary_data with open(path, 'wb') as config: config.write(content) self.patch(upgrade_cluster, 'BOOTRESOURCES_FILE', path) upgrade_cluster.retire_bootresources_yaml() self.assertThat( path, FileContains( upgrade_cluster.BOOTRESOURCES_WARNING.encode('ascii') + content))
def test_survives_encoding_problems(self): path = os.path.join(self.make_dir(), "bootresources.yaml") content = b"[[%s]]" % sample_binary_data with open(path, "wb") as config: config.write(content) self.patch(upgrade_cluster, "BOOTRESOURCES_FILE", path) upgrade_cluster.retire_bootresources_yaml() self.assertThat( path, FileContains( upgrade_cluster.BOOTRESOURCES_WARNING.encode("ascii") + content ), )
def test__does_nothing_if_file_not_present(self): path = self.set_bootresources_yaml('') os.remove(path) upgrade_cluster.retire_bootresources_yaml() self.assertThat(path, Not(FileExists()))