def test__creates_directory(self): parent = self.make_dir() new_home = self.make_nonexistent_path(parent) self.patch_gnupg_home(new_home) self.patch_call() upgrade_cluster.create_gnupg_home() self.assertThat(new_home, DirExists())
def test__does_not_set_ownership_if_not_running_as_root(self): parent = self.make_dir() new_home = self.make_nonexistent_path(parent) self.patch_gnupg_home(new_home) call = self.patch_call() self.patch(os, 'geteuid').return_value = 101 upgrade_cluster.create_gnupg_home() self.assertThat(call, MockNotCalled())
def test__doesnt_set_ownership_to_maas_when_in_snap(self): parent = self.make_dir() new_home = self.make_nonexistent_path(parent) self.patch_gnupg_home(new_home) call = self.patch_call() self.patch(os, 'geteuid').return_value = 0 self.patch(snappy, 'running_in_snap').return_value = True upgrade_cluster.create_gnupg_home() self.assertThat(call, MockNotCalled())
def test__sets_ownership_to_maas_if_running_as_root(self): parent = self.make_dir() new_home = self.make_nonexistent_path(parent) self.patch_gnupg_home(new_home) call = self.patch_call() self.patch(os, 'geteuid').return_value = 0 upgrade_cluster.create_gnupg_home() self.assertThat(call, MockCalledOnceWith(['chown', 'maas:maas', new_home]))
def test__succeeds_if_directory_exists(self): existing_home = self.make_dir() self.patch_gnupg_home(existing_home) self.patch_call() upgrade_cluster.create_gnupg_home() self.assertEqual([], os.listdir(existing_home))