Skip to content

Commit

Permalink
Merge pull request #213 from uw-it-aca/develop
Browse files Browse the repository at this point in the history
Minimize pytz usage (#212)
  • Loading branch information
fanglinfang authored Feb 5, 2024
2 parents 651e080 + 53088e6 commit 30e7ce0
Show file tree
Hide file tree
Showing 46 changed files with 76 additions and 71 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ name: tests

env:
APP_NAME: uw_sws
COVERAGE_PYTHON_VERSION: '3.10'

on:
push:
Expand All @@ -37,22 +38,29 @@ on:

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

strategy:
matrix:
python-version:
- '3.8'
- '3.9'
- '3.10'

steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install commonconf nose2 coverage coveralls==2.2.0
pip install commonconf nose2 coverage coveralls==3.3.1
- name: Run Python Linters
uses: uw-it-aca/actions/python-linters@main
Expand All @@ -65,6 +73,7 @@ jobs:
coverage run ${APP_NAME}/test.py -v
- name: Report Test Coverage
if: matrix.python-version == env.COVERAGE_PYTHON_VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
Expand All @@ -75,16 +84,16 @@ jobs:

needs: test

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.10'

- name: Publish to PyPi
uses: uw-it-aca/actions/publish-pypi@main
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

import os
from setuptools import setup

Expand All @@ -17,13 +20,13 @@
name='UW-RestClients-SWS',
version=VERSION,
packages=['uw_sws'],
author="UW-IT AXDD",
author="UW-IT T&LS",
author_email="aca-it@uw.edu",
include_package_data=True,
install_requires=['UW-RestClients-Core',
'UW-RestClients-PWS',
'mock',
'pytz',
'mock',
],
license='Apache License, Version 2.0',
description=('A library for connecting to the SWS at the University '
Expand All @@ -35,7 +38,6 @@
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
],
)

Expand Down
2 changes: 1 addition & 1 deletion uw_sws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

import json
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/adviser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

# Interfacing with the search for a student's academic advisers
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/campus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/college.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/course.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/curriculum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
15 changes: 6 additions & 9 deletions uw_sws/dao.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Contains SWS DAO implementations.
"""
import json
import time
import os
import re
import random
from datetime import datetime, timedelta
from pytz import timezone
from commonconf import settings
import pytz
from datetime import datetime, timedelta, timezone
from os.path import abspath, dirname
import os
from restclients_core.dao import DAO, MockDAO

SWS_TIMEZONE = timezone("US/Pacific")
SWS_TIMEZONE = pytz.timezone('America/Los_Angeles')


def sws_now():
"""
Return a naive datetime corresponding to the natural SWS timezone.
"""
return datetime.fromtimestamp(
int(datetime.utcnow().strftime('%s')) +
int(datetime.now(timezone.utc).strftime('%s')) +
int(datetime.now(SWS_TIMEZONE).utcoffset().total_seconds()))


Expand Down
2 changes: 1 addition & 1 deletion uw_sws/degree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

# Interfacing with the search for a student's degree status
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/department.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/enrollment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from restclients_core.exceptions import DataFailureException
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/financial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

import logging
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

import json
Expand Down
9 changes: 4 additions & 5 deletions uw_sws/notice.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Interfaceing with the Student Web Service,
for notice resource
"""
import copy

from datetime import timezone
from dateutil import parser
import logging
import pytz
from uw_sws.models import Notice, NoticeAttribute
from uw_sws import get_resource, SWS_TIMEZONE

Expand All @@ -22,13 +22,12 @@ def get_notices_by_regid(regid):
for the passed regid.
"""
url = notice_res_url_prefix + regid + ".json"

return _notices_from_json(get_resource(url))


def _str_to_utc(date_str):
date = parser.parse(date_str)
return SWS_TIMEZONE.localize(date).astimezone(pytz.utc)
return SWS_TIMEZONE.localize(date).astimezone(timezone.utc)


def _notices_from_json(notice_data):
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/person.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/registration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/section.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/section_status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from uw_sws.exceptions import InvalidSectionID
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/term.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
Empty file added uw_sws/term_util.py
Empty file.
2 changes: 1 addition & 1 deletion uw_sws/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

# This is just a test runner for coverage
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/compatible.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_adviser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_campus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_college.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_course.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_curriculum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_dao.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_degree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_department.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_enrollment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_financial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_independent_study.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_instructor_no_regid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
10 changes: 4 additions & 6 deletions uw_sws/tests/test_notice.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
from datetime import date, datetime
import pytz
from datetime import datetime, timezone
from uw_sws.util import fdao_sws_override
from uw_pws.util import fdao_pws_override
from uw_sws.notice import get_notices_by_regid
Expand All @@ -14,9 +13,8 @@

def date_to_dtime(adate):
return SWS_TIMEZONE.localize(
datetime(
year=adate.year, month=adate.month, day=adate.day)
).astimezone(pytz.utc).isoformat()
datetime(year=adate.year, month=adate.month, day=adate.day)
).astimezone(timezone.utc).isoformat()


@fdao_pws_override
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_person.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
2 changes: 1 addition & 1 deletion uw_sws/tests/test_registrations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from unittest import TestCase
Expand Down
Loading

0 comments on commit 30e7ce0

Please sign in to comment.