#!/usr/bin/env python """Tests for distribution points. These tests will FAIL! A few of the tests assert values local to my institution. Edit them to work in your environment, or find a better way to do it and send me an email! """ from nose.tools import * import os import jss global j_global jp = jss.JSSPrefs() j_global = jss.JSS(jss_prefs=jp) class TestJSSPrefs(object): def test_jssprefs_no_repos(self): # Make sure that if you don't specify any repository information in # your preference file, everything still works correctly (just no # repos). Of course, needs a preferences file with no repos in it. no_repos_prefs = "com.github.sheagcraig.python-jss-no-repos.plist" if jss.is_osx(): pref_path = os.path.join("~/Library/Preferences", no_repos_prefs) elif jss.is_linux(): pref_path = os.path.join("~", "." + no_repos_prefs) else: raise Exception("Unknown/unsupported OS.") jssPrefs = jss.JSSPrefs(pref_path)
def fixture_a_jss(): # You'll need to create this file... prefs = jkc.KJSSPrefs( preferences_file='tests/com.github.gkluoe.git2jss.plist') JSS = jss.JSS(prefs) return JSS
def make_selection(): selected = raw_input("Select release channel to switch to: ") try: selected = int(selected) except ValueError: print "Select from the options above." return make_selection() if selected < 1 or selected > len(CHANNELS): print "Select from the options above." return make_selection() return selected j = jss.JSS(jss.JSSPrefs()) udid = subprocess.check_output( "system_profiler SPHardwareDataType | awk '/UUID/ { print $3; }'", shell=True) for num, channel in enumerate(CHANNELS, 1): print '{}. {}'.format(num, channel) selected = make_selection() new_channel = CHANNELS[selected - 1] c = j.Computer('udid=%s' % udid) v = c.find('extension_attributes/extension_attribute/[id="%s"]/value' % EXT_ATTR) old_channel = v.text v.text = new_channel
import string import sys import jss try: USER = sys.argv[1] ATTR = sys.argv[2] except IndexError: print "Usage: {} username attributename".format(sys.argv[0]) print "Use this script to test whether it's possible to modify a User Extension Attribute on a JSS" print "User <username> should have <attributename> set to some value that you don't mind losing" print "WARNING: we will not set the value back to what it was before!" sys.exit(255) jss_prefs = jss.JSSPrefs() j = jss.JSS(jss_prefs) user = j.User(USER) print "Testing Extension Attribute {} on user {}".format(ATTR, USER) print "Using JSS at ", j.base_url init_val = user.find( ".//extension_attribute[name='{}']/value".format(ATTR)).text print "Initial value is: ", init_val newval = ''.join( random.choice(string.ascii_letters + string.digits) for _ in range(5)) print "Trying to change value to: ", newval user.find(".//extension_attribute[name='{}']/value".format(ATTR)).text = newval
# --*-- encoding: utf-8 --*-- import git2jss.processors as processors import git2jss.vcs as vcs import git2jss.jss_keyring as jkc import pytest from pytest import raises import jss # You'll need to create this file... prefs = jkc.KJSSPrefs(preferences_file='tests/com.github.gkluoe.git2jss.plist') JSS = jss.JSS(prefs) repo = vcs.GitRepo(tag='0.0.49', sourcedir='_JSS') def test_new_generic_object(): """ Can we create a new Script object? """ newobj = processors.JSSObject(repo, JSS, 'coreconfig-softwareupdate-run.py', target='macad-2018-test.py') assert newobj def test_new_script_object(): """ Can we create a new Script object? """ newobj = processors.Script(repo, JSS, source_file='coreconfig-softwareupdate-run.py', target='macad-2018-test.py') assert newobj