Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit 5ebc3f5

Browse files
authored
Merge pull request #1 from umn-microsoft-automation/pre
Initial 0.10.0 release
2 parents 60027bb + f221845 commit 5ebc3f5

33 files changed

+2281
-263
lines changed

README.md

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# grouper-python
22

3+
This is a module to interact with the [Grouper Web Services API](https://spaces.at.internet2.edu/display/Grouper/Grouper+Web+Services).
4+
35
## Installation
46

57
To install grouper library only:
@@ -8,12 +10,6 @@ To install grouper library only:
810
pip install .
911
```
1012

11-
To install additional requirements for running the included scripts:
12-
13-
``` sh
14-
pip install .[script]
15-
```
16-
1713
To install for development:
1814

1915
``` sh
@@ -22,21 +18,3 @@ pip install --editable .[dev]
2218

2319
This will install so the `grouper` module is based off the source code,
2420
and also installs neccessary linters and testing requirements.
25-
Currently there are no "tests" written for this code,
26-
but at the very least it passes `pylama` and `mypy`.
27-
28-
## Script usage
29-
30-
To use the included scripts (`docs_base.py` and `docs_site.py`)
31-
you will need to setup a `.env` file.
32-
Copy `.env.template` to `.env`.
33-
Change the values for GROUPER_USER, GROUPER_PWD, and if neccessary, GROUPER_BASE_URL.
34-
If there are double quotes (`"`) in your password, surround it with single quotes (`'`)
35-
instead of the double quotes in the sample file.
36-
37-
### Specifying sites
38-
39-
Specify the sites to create groups for using a text file (by default, `sites.txt`)
40-
in the root of this repository.
41-
Specify the URLs, one per line.
42-
This file will be read by `docs_site.py`.

azure-pipelines.yml

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
name: $(Date:yyyyMMdd).$(Rev:rr)
2+
13
pool:
24
vmImage: ubuntu-latest
35

@@ -16,11 +18,11 @@ stages:
1618
displayName: Run Tests
1719
continueOnError: true
1820
- script: |
19-
pytest --pylama -k 'pylama' --junit-xml=junit/test-pylama-results.xml -o addopts= tests/ pygrouper/
21+
pytest --pylama -k 'pylama' --junit-xml=junit/test-pylama-results.xml -o addopts= tests/ grouper_python/
2022
displayName: Run Linter Tests
2123
continueOnError: true
2224
- script: |
23-
mypy -p pygrouper --junit-xml junit/test-mypy-results.xml
25+
mypy --junit-xml junit/test-mypy-results.xml
2426
displayName: Run MyPy Tests
2527
continueOnError: true
2628
- task: PublishTestResults@2
@@ -43,36 +45,37 @@ stages:
4345
- task: TwineAuthenticate@1
4446
inputs:
4547
artifactFeed: 'ITAC-API/pygrouper'
46-
- task: PythonScript@0
47-
inputs:
48-
scriptSource: inline
49-
script: |
50-
with open('pygrouper/__init__.py', 'r+') as f:
51-
content = f.read()
48+
- ${{ if ne(variables['Build.SourceBranchName'], 'main') }}:
49+
- task: PythonScript@0
50+
inputs:
51+
scriptSource: inline
52+
script: |
53+
with open('grouper_python/__init__.py', 'r+') as f:
54+
content = f.read()
5255
53-
for line in content.splitlines():
54-
if line.startswith('__version__'):
55-
delim = '"' if '"' in line else "'"
56-
version = line.split(delim)[1]
57-
break
58-
else:
59-
raise RuntimeError("Unable to find version string.")
56+
for line in content.splitlines():
57+
if line.startswith('__version__'):
58+
delim = '"' if '"' in line else "'"
59+
version = line.split(delim)[1]
60+
break
61+
else:
62+
raise RuntimeError("Unable to find version string.")
6063
61-
print(f"found {version}")
62-
build_number = "$(Build.BuildNumber)".replace(".", "")
63-
new_version = f"{version}b{build_number}"
64-
print(f"new version: {new_version}")
64+
print(f"found {version}")
65+
build_number = "$(Build.BuildNumber)".replace(".", "")
66+
new_version = f"{version}b{build_number}"
67+
print(f"new version: {new_version}")
6568
66-
content = content.replace(version, new_version)
67-
f.seek(0)
68-
f.write(content)
69-
f.truncate()
70-
displayName: Set prerelease Version
69+
content = content.replace(version, new_version)
70+
f.seek(0)
71+
f.write(content)
72+
f.truncate()
73+
displayName: Set prerelease Version
7174
- script: |
7275
pip install build twine
7376
python -m build
7477
cat $(PYPIRC_PATH)
75-
# twine upload -r mkdocs-material-umn --config-file $(PYPIRC_PATH) dist/* --verbose
76-
pwd
77-
ls -l
78-
- publish: $(Pipeline.Workspace)/s/dist
78+
twine upload -r pygrouper --config-file $(PYPIRC_PATH) dist/* --verbose
79+
# pwd
80+
# ls -l
81+
# - publish: $(Pipeline.Workspace)/s/dist

grouper_python/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .objects.client import Client
2+
from .objects.group import Group
3+
from .objects.stem import Stem
4+
from .objects.subject import Subject
5+
from .objects.person import Person
6+
7+
__version__ = "0.1.0"
8+
9+
__all__ = ["Client", "Group", "Stem", "Subject", "Person"]

pygrouper/group.py renamed to grouper_python/group.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from __future__ import annotations
22
from typing import TYPE_CHECKING, Any
33

4-
if TYPE_CHECKING:
4+
if TYPE_CHECKING: # pragma: no cover
55
from .objects.group import CreateGroup, Group
66
from .objects.client import Client
77
from .objects.subject import Subject
88
from .objects.exceptions import (
99
GrouperGroupNotFoundException,
1010
GrouperSuccessException,
1111
GrouperStemNotFoundException,
12+
GrouperPermissionDenied,
1213
)
1314

1415

@@ -41,8 +42,9 @@ def find_group_by_name(
4142
if r_metadata["resultCode"] == "INVALID_QUERY" and r_metadata[
4243
"resultMessage"
4344
].startswith("Cant find stem"):
44-
raise GrouperStemNotFoundException(str(stem))
45+
raise GrouperStemNotFoundException(str(stem), r)
4546
else: # pragma: no cover
47+
# Some other issue, so pass the failure through
4648
raise
4749
if "groupResults" in r["WsFindGroupsResults"]:
4850
return [
@@ -101,14 +103,38 @@ def delete_groups(
101103
"wsGroupLookups": group_lookup,
102104
}
103105
}
104-
r = client._call_grouper(
105-
"/groups",
106-
body,
107-
act_as_subject=act_as_subject,
108-
)
106+
try:
107+
r = client._call_grouper(
108+
"/groups",
109+
body,
110+
act_as_subject=act_as_subject,
111+
)
112+
except GrouperSuccessException as err:
113+
r = err.grouper_result
114+
r_metadata = r["WsGroupDeleteResults"]["resultMetadata"]
115+
if r_metadata["resultCode"] == "PROBLEM_DELETING_GROUPS":
116+
raise GrouperPermissionDenied(r)
117+
else: # pragma: no cover
118+
# Some other issue, so pass the failure through
119+
raise
109120
for result in r["WsGroupDeleteResults"]["results"]:
110-
if result["resultMetadata"]["resultCode"] != "SUCCESS":
121+
meta = result["resultMetadata"]
122+
if meta["resultCode"] == "SUCCESS_GROUP_NOT_FOUND":
123+
try:
124+
result_message = meta["resultMessage"]
125+
split_message = result_message.split(",")
126+
group_name = split_message[1].split("=")[1]
127+
except Exception: # pragma: no cover
128+
# The try above feels fragile, so if it fails,
129+
# throw a SuccessException
130+
raise GrouperSuccessException(r)
131+
raise GrouperGroupNotFoundException(group_name, r)
132+
elif meta["resultCode"] != "SUCCESS": # pragma: no cover
133+
# Whatever the error here, we don't understand it
134+
# well enough to process it into something more specific
111135
raise GrouperSuccessException(r)
136+
else:
137+
pass
112138

113139

114140
def get_groups_by_parent(
@@ -134,7 +160,6 @@ def get_groups_by_parent(
134160
body,
135161
act_as_subject=act_as_subject,
136162
)
137-
print(r)
138163
if "groupResults" in r["WsFindGroupsResults"]:
139164
return [
140165
Group.from_results(client, grp)
@@ -160,5 +185,5 @@ def get_group_by_name(
160185
}
161186
r = client._call_grouper("/groups", body, act_as_subject=act_as_subject)
162187
if "groupResults" not in r["WsFindGroupsResults"]:
163-
raise GrouperGroupNotFoundException(group_name)
188+
raise GrouperGroupNotFoundException(group_name, r)
164189
return Group.from_results(client, r["WsFindGroupsResults"]["groupResults"][0])

0 commit comments

Comments
 (0)