Skip to content

Commit

Permalink
Deleted/commented out redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
shouhanzen committed Sep 29, 2023
1 parent 6c1951c commit 898940c
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 127 deletions.
3 changes: 1 addition & 2 deletions src/dsmlp/app/factory.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from dsmlp.ext.awsed import DefaultAwsedClient, ExternalAwsedClient
from dsmlp.ext.awsed import ExternalAwsedClient
from dsmlp.ext.kube import DefaultKubeClient


class AppFactory:
def __init__(self):
# self.awsed_client = DefaultAwsedClient()
self.awsed_client = ExternalAwsedClient()
self.kube_client = DefaultKubeClient()
27 changes: 0 additions & 27 deletions src/dsmlp/ext/awsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,6 @@
import awsed.client
import awsed.types

class DefaultAwsedClient(AwsedClient):
def __init__(self):
self.endpoint = os.environ.get('AWSED_ENDPOINT')
self.awsed_api_key = os.environ.get('AWSED_API_KEY')

def describe_user(self, username: str) -> UserResponse:
return self.dataclass_request(UserResponse, f"/users/{username}")

def list_user_teams(self, username: str) -> ListTeamsResponse:
return self.dataclass_request(ListTeamsResponse, f"/teams?username={username}")

def json_request(self, url):
result = requests.get(self.endpoint + url, headers=self.auth())

return result.json()

def dataclass_request(self, data_class, url):
result = requests.get(self.endpoint + url, headers=self.auth())
if result.status_code != 200:
raise UnsuccessfulRequest()

return from_dict(data_class=data_class, data=result.json())

def auth(self):
headers = {'Authorization': 'AWSEd api_key=' + self.awsed_api_key}
return headers

class ExternalAwsedClient(AwsedClient):
def __init__(self):
self.client = awsed.client.DefaultAwsedClient(endpoint=os.environ.get('AWSED_ENDPOINT'),
Expand Down
198 changes: 100 additions & 98 deletions tests/ext/test_awsed.py
Original file line number Diff line number Diff line change
@@ -1,109 +1,111 @@
import os
import requests_mock
from hamcrest import assert_that, equal_to
from dsmlp.ext.awsed import DefaultAwsedClient, ExternalAwsedClient
from dsmlp.ext.awsed import ExternalAwsedClient
from dsmlp.plugin.awsed import ListTeamsResponse, TeamJson, UserResponse


class TestAwsedClient:
# noinspection PyMethodMayBeStatic
def setup_method(self) -> None:
os.environ['AWSED_ENDPOINT'] = 'https://awsed.ucsd.edu/api'
os.environ['AWSED_API_KEY'] = "1234"
# No point testing just the API client. Leaving the imports here for reference.

# noinspection PyMethodMayBeStatic
def teardown_method(self) -> None:
os.environ.pop('AWSED_ENDPOINT')
os.environ.pop('AWSED_API_KEY')
# class TestAwsedClient:
# # noinspection PyMethodMayBeStatic
# def setup_method(self) -> None:
# os.environ['AWSED_ENDPOINT'] = 'https://awsed.ucsd.edu/api'
# os.environ['AWSED_API_KEY'] = "1234"

def test_describe_user(self, requests_mock):
"""test list courses by tag"""
requests_mock.get('https://awsed.ucsd.edu/api/users/user1', text="""
{
"username": "user1",
"firstName": "user",
"lastName": "1",
"uid":1,
"enrollments": ["ABC1", "ABC2"]
}
""")
c = ExternalAwsedClient()
user = c.describe_user("user1")
# # noinspection PyMethodMayBeStatic
# def teardown_method(self) -> None:
# os.environ.pop('AWSED_ENDPOINT')
# os.environ.pop('AWSED_API_KEY')

assert_that(user, equal_to(
UserResponse(uid=1)
))
# def test_describe_user(self, requests_mock):
# """test list courses by tag"""
# requests_mock.get('https://awsed.ucsd.edu/api/users/user1', text="""
# {
# "username": "user1",
# "firstName": "user",
# "lastName": "1",
# "uid":1,
# "enrollments": ["ABC1", "ABC2"]
# }
# """)
# c = ExternalAwsedClient()
# user = c.describe_user("user1")

def test_list_user_teams(self, requests_mock):
"""test list courses by tag"""
requests_mock.get('https://awsed.ucsd.edu/api/teams?username=user1', text="""
{
"teams": [
{
"teamName": "string",
"sanitizedTeamName": "string",
"uniqueName": "string",
"gid": 1,
"members": [
{
"username": "string",
"firstName": "string",
"lastName": "string",
"uid": 0,
"role": "string"
}
],
"course": {
"tags": [
"string"
],
"enrollments": [
{
"username": "string",
"firstName": "string",
"lastName": "string",
"uid": 0,
"role": "string"
}
],
"courseId": "string",
"pool": {
"name": "string",
"poolRootName": "string",
"rule": "string",
"ou": "string",
"courseName": "string",
"mode": "string"
},
"active": true,
"grader": {
"username": "string",
"firstName": "string",
"lastName": "string",
"uid": 0,
"role": "string"
},
"fileSystem": {
"identifier": "string",
"server": "string",
"path": "string"
},
"snowTicket": "string",
"quarter": "string",
"subject": "string",
"courseNumber": "string",
"instructor": "string",
"instructorEmail": "string"
}
}
]
}
""")
c = ExternalAwsedClient()
user = c.list_user_teams('user1')
# assert_that(user, equal_to(
# UserResponse(uid=1)
# ))

assert_that(user, equal_to(
ListTeamsResponse(teams=[
TeamJson(gid=1)
])
))
# def test_list_user_teams(self, requests_mock):
# """test list courses by tag"""
# requests_mock.get('https://awsed.ucsd.edu/api/teams?username=user1', text="""
# {
# "teams": [
# {
# "teamName": "string",
# "sanitizedTeamName": "string",
# "uniqueName": "string",
# "gid": 1,
# "members": [
# {
# "username": "string",
# "firstName": "string",
# "lastName": "string",
# "uid": 0,
# "role": "string"
# }
# ],
# "course": {
# "tags": [
# "string"
# ],
# "enrollments": [
# {
# "username": "string",
# "firstName": "string",
# "lastName": "string",
# "uid": 0,
# "role": "string"
# }
# ],
# "courseId": "string",
# "pool": {
# "name": "string",
# "poolRootName": "string",
# "rule": "string",
# "ou": "string",
# "courseName": "string",
# "mode": "string"
# },
# "active": true,
# "grader": {
# "username": "string",
# "firstName": "string",
# "lastName": "string",
# "uid": 0,
# "role": "string"
# },
# "fileSystem": {
# "identifier": "string",
# "server": "string",
# "path": "string"
# },
# "snowTicket": "string",
# "quarter": "string",
# "subject": "string",
# "courseNumber": "string",
# "instructor": "string",
# "instructorEmail": "string"
# }
# }
# ]
# }
# """)
# c = ExternalAwsedClient()
# user = c.list_user_teams('user1')

# assert_that(user, equal_to(
# ListTeamsResponse(teams=[
# TeamJson(gid=1)
# ])
# ))

0 comments on commit 898940c

Please sign in to comment.