diff --git a/.coveragerc b/.coveragerc index c5e354a..687f80e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,4 @@ [run] branch = True -source = uw_attest -include = uw_attest/* +source = uw_space +include = uw_space/* diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index b9e6e01..677604b 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -23,13 +23,13 @@ name: tests env: - APP_NAME: uw_attest + APP_NAME: uw_space on: push: - branches: [main, develop] + branches: [main, qa, develop] pull_request: - branches: [main, develop] + branches: [main, qa, develop] types: [opened, reopened, synchronize] release: branches: [main] diff --git a/MANIFEST.in b/MANIFEST.in index 600d11a..c30808b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -include uw_attest/VERSION -recursive-include uw_attest * +include uw_space/VERSION +recursive-include uw_space * diff --git a/README.md b/README.md index ff038f7..41fed0b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# uw-restclients-attestation +# uw-restclients-space Restclient for Attestations Service -[![Build Status](https://github.com/uw-it-aca/uw-restclients-attest/workflows/tests/badge.svg?branch=main)](https://github.com/uw-it-aca/uw-restclients-attest/actions) -[![Coverage Status](https://coveralls.io/repos/github/uw-it-aca/uw-restclients-attest/badge.svg?branch=main)](https://coveralls.io/github/uw-it-aca/uw-restclients-attest?branch=main) -[![PyPi Version](https://img.shields.io/pypi/v/uw-restclients-attest.svg)](https://pypi.python.org/pypi/uw-restclients-attest) -![Python versions](https://img.shields.io/pypi/pyversions/uw-restclients-attest.svg) +[![Build Status](https://github.com/uw-it-aca/uw-restclients-space/workflows/tests/badge.svg?branch=main)](https://github.com/uw-it-aca/uw-restclients-space/actions) +[![Coverage Status](https://coveralls.io/repos/github/uw-it-aca/uw-restclients-space/badge.svg?branch=main)](https://coveralls.io/github/uw-it-aca/uw-restclients-space?branch=main) +[![PyPi Version](https://img.shields.io/pypi/v/uw-restclients-space.svg)](https://pypi.python.org/pypi/uw-restclients-space) +![Python versions](https://img.shields.io/pypi/pyversions/uw-restclients-space.svg) Installation: @@ -14,14 +14,13 @@ To use this client, you'll need these settings in your application or script: # Specifies whether requests should use live or mocked resources, # acceptable values are 'Live' or 'Mock' (default) - RESTCLIENTS_ATTEST_DAO_CLASS='Live' - RESTCLIENTS_ATTEST_AUTH_DAO_CLASS='Live' - RESTCLIENTS_ATTEST_AUTH_SECRET= - RESTCLIENTS_ATTEST_AUTH_HOST='' + RESTCLIENTS_SPACE_DAO_CLASS='Live' -Optional settings: +# Paths to UWCA cert and key files +RESTCLIENTS_SPACE_CERT_FILE='/path/to/cert' +RESTCLIENTS_SPACE_KEY_FILE='/path/to/key' - # Customizable parameters for urllib3 - RESTCLIENTS_ATTEST_HOST='' - RESTCLIENTS_ATTEST_TIMEOUT=5 - RESTCLIENTS_ATTEST_POOL_SIZE=10 +Settings: + RESTCLIENTS_SPACE_HOST='' + RESTCLIENTS_SPACE_TIMEOUT=5 + RESTCLIENTS_SPACE_POOL_SIZE=10 diff --git a/conf/test.conf b/conf/test.conf index eae5f5a..e52b2b4 100644 --- a/conf/test.conf +++ b/conf/test.conf @@ -1 +1 @@ -[ATTEST] +[SPACE] diff --git a/setup.py b/setup.py index 9fd4dbf..af31ba3 100644 --- a/setup.py +++ b/setup.py @@ -3,21 +3,21 @@ README = """ See the README on `GitHub -`_. +`_. """ -version_path = 'uw_attest/VERSION' +version_path = 'uw_space/VERSION' VERSION = open(os.path.join(os.path.dirname(__file__), version_path)).read() VERSION = VERSION.replace("\n", "") # allow setup.py to be run from any path os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) -url = "https://github.com/uw-it-aca/uw-restclients-attest" +url = "https://github.com/uw-it-aca/uw-restclients-space" setup( - name='UW-RestClients-Attest', + name='UW-RestClients-Space', version=VERSION, - packages=['uw_attest'], + packages=['uw_space'], author="UW-IT AXDD", author_email="aca-it@uw.edu", include_package_data=True, diff --git a/uw_attest/__init__.py b/uw_attest/__init__.py deleted file mode 100644 index 6036a2d..0000000 --- a/uw_attest/__init__.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2021 UW-IT, University of Washington -# SPDX-License-Identifier: Apache-2.0 - -""" -This is the interface for interacting with the Attesttation Web Service. -""" -import json -import logging -from restclients_core.exceptions import DataFailureException -from uw_attest.dao import ATTEST_DAO -from uw_attest.models import Covid19Attestation - -covid_api = "/attestations/v1/covid19/{}" -logger = logging.getLogger(__name__) - - -class Attest(object): - - def __init__(self): - self.dao = ATTEST_DAO() - self._read_headers = {"Accept": "application/json"} - - def get_covid19_vaccination(self, regid): - """ - Get covid19 vaccination by regid - """ - url = covid_api.format(regid) - response = self.dao.getURL(url, self._read_headers) - logger.debug( - {'url': url, 'status': response.status, 'data': response.data}) - if response.status != 200: - raise DataFailureException(url, response.status, response.data) - return Covid19Attestation.from_json(json.loads(response.data)) diff --git a/uw_attest/dao.py b/uw_attest/dao.py deleted file mode 100644 index 6ce5cb4..0000000 --- a/uw_attest/dao.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2021 UW-IT, University of Washington -# SPDX-License-Identifier: Apache-2.0 - -from restclients_core.dao import DAO -from restclients_core.exceptions import DataFailureException -from os.path import abspath, dirname -import json -import os - - -class ATTEST_AUTH_DAO(DAO): - def service_name(self): - return "attest_auth" - - def _is_cacheable(self, method, url, headers, body=None): - return True - - def get_auth_token(self, secret): - url = "/oauth2/token" - headers = {"Authorization": "Basic {}".format(secret), - "Content-type": "application/x-www-form-urlencoded"} - - response = self.postURL(url, headers, "grant_type=client_credentials") - if response.status != 200: - raise DataFailureException(url, response.status, response.data) - - data = json.loads(response.data) - return data.get("access_token", "") - - def service_mock_paths(self): - return [abspath(os.path.join(dirname(__file__), "resources"))] - - def _edit_mock_response(self, method, url, headers, body, response): - if response.status == 404 and method != "GET": - alternative_url = "{0}.{1}".format(url, method) - backend = self.get_implementation() - new_resp = backend.load(method, alternative_url, headers, body) - response.status = new_resp.status - response.data = new_resp.data - - -class ATTEST_DAO(DAO): - def __init__(self): - self.auth_dao = ATTEST_AUTH_DAO() - return super(ATTEST_DAO, self).__init__() - - def service_name(self): - return "attest" - - def service_mock_paths(self): - return [abspath(os.path.join(dirname(__file__), "resources"))] - - def _custom_headers(self, method, url, headers, body): - headers = {} - secret = self.get_service_setting("AUTH_SECRET", "") - if secret: - headers["Authorization"] = self.auth_dao.get_auth_token(secret) - return headers diff --git a/uw_attest/models.py b/uw_attest/models.py deleted file mode 100644 index a366e0b..0000000 --- a/uw_attest/models.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2021 UW-IT, University of Washington -# SPDX-License-Identifier: Apache-2.0 - -import json -from restclients_core import models -from uw_attest.utils import str_to_datetime, date_to_str - - -class Covid19Attestation(models.Model): - regid = models.CharField(max_length=32) - is_student = models.BooleanField(default=False) - created = models.DateTimeField() - updated = models.DateTimeField() - - def __init__(self, *args, **kwargs): - super(Covid19Attestation, self).__init__(*args, **kwargs) - self.vaccinated = None - self.exemption = None - - @staticmethod - def from_json(json_data): - ca_obj = Covid19Attestation() - ca_obj.regid = json_data.get("regId") - ca_obj.is_student = json_data.get("isStudent") - ca_obj.created = str_to_datetime(json_data.get("created")) - ca_obj.updated = str_to_datetime(json_data.get("updated")) - if json_data.get("vaccinated"): - ca_obj.vaccinated = Vaccinated.from_json( - json_data.get("vaccinated")) - if json_data.get("exemption"): - ca_obj.exemption = Exemption.from_json( - json_data.get("exemption")) - return ca_obj - - def json_data(self): - return { - "regid": self.regid, - "is_student": self.is_student, - "created": date_to_str(self.created), - "updated": date_to_str(self.updated), - "vaccinated": ( - self.vaccinated.json_data() if self.vaccinated else None), - "exemption": ( - self.exemption.json_data() if self.exemption else None), - } - - def __str__(self): - return json.dumps(self.json_data(), default=str) - - -class Vaccinated(models.Model): - vaccine = models.CharField(max_length=64) - country_code = models.CharField(max_length=2, default="US") - dose1_date = models.DateTimeField() - dose2_date = models.DateTimeField(null=True, default=None) - other_text = models.CharField(max_length=100, null=True) - - @staticmethod - def from_json(json_data): - vac_obj = Vaccinated() - vac_obj.vaccine = json_data.get("vaccine") - vac_obj.country_code = json_data.get("country") - vac_obj.dose1_date = str_to_datetime(json_data.get("dose1Date")) - vac_obj.dose2_date = str_to_datetime(json_data.get("dose2Date")) - vac_obj.other_text = json_data.get("otherText") - return vac_obj - - def json_data(self): - return { - "vaccine": self.vaccine, - "country_code": self.country_code, - "dose1_date": date_to_str(self.dose1_date), - "dose2_date": date_to_str(self.dose2_date), - "other_text": self.other_text, - } - - -class Exemption(models.Model): - type = models.CharField(max_length=64) - - @staticmethod - def from_json(json_data): - exe_obj = Exemption() - exe_obj.type = json_data.get("type") - return exe_obj - - def json_data(self): - return {"type": self.type} diff --git a/uw_attest/resources/attest/file/attestations/v1/covid19/9136CCB8F66711D5BE060004AC494F31 b/uw_attest/resources/attest/file/attestations/v1/covid19/9136CCB8F66711D5BE060004AC494F31 deleted file mode 100644 index bcf32e9..0000000 --- a/uw_attest/resources/attest/file/attestations/v1/covid19/9136CCB8F66711D5BE060004AC494F31 +++ /dev/null @@ -1,13 +0,0 @@ -{ - "isStudent": true, - "_id": "9136CCB8F66711D5BE060004AC494F31", - "exemption": { - "_id": "60c264809aac7700085195a5", - "type": "philosophical" - }, - "regId": "9136CCB8F66711D5BE060004AC494F31", - "vaccinated": null, - "created": "2021-06-10T19:14:08.533Z", - "updated": "2021-06-10T19:14:08.533Z", - "__v": 0 -} \ No newline at end of file diff --git a/uw_attest/resources/attest/file/attestations/v1/covid19/9136CCB8F66711D5BE060004AC494FFE b/uw_attest/resources/attest/file/attestations/v1/covid19/9136CCB8F66711D5BE060004AC494FFE deleted file mode 100644 index 8a37848..0000000 --- a/uw_attest/resources/attest/file/attestations/v1/covid19/9136CCB8F66711D5BE060004AC494FFE +++ /dev/null @@ -1,16 +0,0 @@ -{ - "isStudent": true, - "_id": "60bab2e60f8e380009dfa347", - "exemption": null, - "regId": "9136CCB8F66711D5BE060004AC494FFE", - "vaccinated": { - "country": "US", - "_id": "60babcf6f2d1130009c579c2", - "vaccine": "moderna", - "dose1Date": "2021-04-02T00:00:00.000Z", - "dose2Date": "2021-04-30T00:00:00.000Z" - }, - "created": "2021-06-04T23:10:30.746Z", - "updated": "2021-06-04T23:53:26.860Z", - "__v": 0 -} \ No newline at end of file diff --git a/uw_attest/resources/attest_auth/file/oauth2/token.POST b/uw_attest/resources/attest_auth/file/oauth2/token.POST deleted file mode 100644 index 0a82640..0000000 --- a/uw_attest/resources/attest_auth/file/oauth2/token.POST +++ /dev/null @@ -1,4 +0,0 @@ -{"access_token":"xxxxxxxxxxxxxxxxxx", -"expires_in":3600, -"token_type":"Bearer" -} diff --git a/uw_attest/tests/test_attest.py b/uw_attest/tests/test_attest.py deleted file mode 100644 index c868965..0000000 --- a/uw_attest/tests/test_attest.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2021 UW-IT, University of Washington -# SPDX-License-Identifier: Apache-2.0 - -from unittest import TestCase -from restclients_core.exceptions import DataFailureException -from uw_attest import Attest -from uw_attest.utils import ( - fdao_attest_override, fdao_attest_auth_override) - - -@fdao_attest_override -@fdao_attest_auth_override -class TestAttest(TestCase): - def test_get_covid19(self): - att = Attest() - result = att.get_covid19_vaccination( - "9136CCB8F66711D5BE060004AC494FFE") - self.assertEquals( - result.json_data(), - {'created': '2021-06-04 23:10:30.746000+00:00', - 'exemption': None, - 'is_student': True, - 'regid': '9136CCB8F66711D5BE060004AC494FFE', - 'updated': '2021-06-04 23:53:26.860000+00:00', - 'vaccinated': { - 'country_code': 'US', - 'dose1_date': '2021-04-02 00:00:00+00:00', - 'dose2_date': '2021-04-30 00:00:00+00:00', - 'other_text': None, - 'vaccine': 'moderna'}} - ) - self.assertTrue(len(str(result)) > 0) - - result = att.get_covid19_vaccination( - "9136CCB8F66711D5BE060004AC494F31") - self.assertEquals( - result.json_data(), - {'created': '2021-06-10 19:14:08.533000+00:00', - 'exemption': {'type': 'philosophical'}, - 'is_student': True, - 'regid': '9136CCB8F66711D5BE060004AC494F31', - 'updated': '2021-06-10 19:14:08.533000+00:00', - 'vaccinated': None} - ) diff --git a/uw_attest/tests/test_dao.py b/uw_attest/tests/test_dao.py deleted file mode 100644 index 9814589..0000000 --- a/uw_attest/tests/test_dao.py +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2021 UW-IT, University of Washington -# SPDX-License-Identifier: Apache-2.0 - -from unittest import TestCase -import mock -from commonconf import override_settings -from restclients_core.exceptions import DataFailureException -from uw_attest.dao import ATTEST_AUTH_DAO, ATTEST_DAO -from uw_attest.utils import ( - fdao_attest_override, fdao_attest_auth_override) - - -@fdao_attest_auth_override -@fdao_attest_override -class TestAttestAuth(TestCase): - - def test_no_auth_header(self): - headers = ATTEST_DAO()._custom_headers("GET", "/", {}, "") - self.assertFalse("Authorization" in headers) - - def test_get_auth_token(self): - self.assertIsNotNone( - ATTEST_AUTH_DAO().get_auth_token("test1")) - - @override_settings(RESTCLIENTS_ATTEST_AUTH_SECRET="test1") - @mock.patch.object(ATTEST_AUTH_DAO, "get_auth_token") - def test_auth_header(self, mock_get_auth_token): - mock_get_auth_token.return_value = "abcdef" - headers = ATTEST_DAO()._custom_headers("GET", "/", {}, "") - self.assertTrue("Authorization" in headers) - self.assertEqual(headers["Authorization"], "abcdef") - - def test_is_cacheable(self): - auth = ATTEST_AUTH_DAO() - self.assertTrue(auth._is_cacheable("POST", "/", {}, "")) diff --git a/uw_attest/VERSION b/uw_space/VERSION similarity index 100% rename from uw_attest/VERSION rename to uw_space/VERSION diff --git a/uw_space/__init__.py b/uw_space/__init__.py new file mode 100644 index 0000000..e0ce642 --- /dev/null +++ b/uw_space/__init__.py @@ -0,0 +1,58 @@ +# Copyright 2021 UW-IT, University of Washington +# SPDX-License-Identifier: Apache-2.0 + +import json +import logging +from restclients_core.exceptions import DataFailureException +from uw_space.dao import SPACE_DAO +from uw_space.models import Facility + +by_code_path = "/space/v1/facility.json?facility_code={}" +by_number_path = "/space/v1/facility/{}.json" +logger = logging.getLogger(__name__) + + +class Facilities(object): + + def __init__(self): + self.dao = SPACE_DAO() + self._read_headers = {"Accept": "application/json"} + + def search_by_code(self, facility_code): + """ + facility_code: string + """ + url = by_code_path.format(facility_code) + response = self.dao.getURL(url, self._read_headers) + logger.debug( + {'url': url, 'status': response.status, 'data': response.data}) + if response.status != 200: + raise DataFailureException(url, response.status, response.data) + return self.__process_json(json.loads(response.data)) + + def search_by_number(self, facility_number): + """ + facility_number: string + """ + url = by_number_path.format(facility_number) + response = self.dao.getURL(url, self._read_headers) + logger.debug( + {'url': url, 'status': response.status, 'data': response.data}) + if response.status != 200: + raise DataFailureException(url, response.status, response.data) + return Facility.from_json(json.loads(response.data)) + + def __process_json(self, json_data): + objs = [] + facilitys = json_data.get("Facilitys") + for facility in facilitys: + furi = facility.get("FacilityURI") + if furi: + url = furi.get("Href") + building_resp = self.dao.getURL(url, self._read_headers) + if building_resp.status != 200: + raise DataFailureException( + url, building_resp.status, building_resp.data) + objs.append( + Facility.from_json(json.loads(building_resp.data))) + return objs diff --git a/uw_space/dao.py b/uw_space/dao.py new file mode 100644 index 0000000..c74a977 --- /dev/null +++ b/uw_space/dao.py @@ -0,0 +1,17 @@ +# Copyright 2021 UW-IT, University of Washington +# SPDX-License-Identifier: Apache-2.0 + +from restclients_core.dao import DAO +from os.path import abspath, dirname +import os + + +class SPACE_DAO(DAO): + def __init__(self): + return super(SPACE_DAO, self).__init__() + + def service_name(self): + return "space" + + def service_mock_paths(self): + return [abspath(os.path.join(dirname(__file__), "resources"))] diff --git a/uw_space/models.py b/uw_space/models.py new file mode 100644 index 0000000..6ec359d --- /dev/null +++ b/uw_space/models.py @@ -0,0 +1,57 @@ +# Copyright 2021 UW-IT, University of Washington +# SPDX-License-Identifier: Apache-2.0 + +import json +from restclients_core import models +from uw_space.utils import date_to_str, str_to_datetime + + +class Facility(models.Model): + code = models.CharField(max_length=32) + last_updated = models.DateTimeField() + latitude = models.CharField(max_length=64) + longitude = models.CharField(max_length=64) + name = models.CharField(max_length=128) + number = models.CharField(max_length=32) + type = models.CharField(max_length=32) + site = models.CharField(max_length=96) + + def __init__(self, *args, **kwargs): + super(Facility, self).__init__(*args, **kwargs) + + @staticmethod + def from_json(json_data): + obj = Facility() + obj.code = json_data.get("FacilityCode") + obj.number = json_data.get("FacilityNumber") + obj.last_updated = str_to_datetime(json_data.get("ModifiedDate")) + obj.name = json_data.get("LongName") + + cpoint = json_data.get("CenterPoint") + if cpoint: + obj.latitude = cpoint.get("Latitude") + obj.longitude = cpoint.get("Longitude") + site_json = json_data.get("Site") + + if site_json: + obj.site = site_json.get("Description") + + ftype = json_data.get("FacilityType") + if ftype: + obj.type = ftype.get("Description") + return obj + + def json_data(self): + return { + "code": self.code, + "last_updated": date_to_str(self.last_updated), + "latitude": self.latitude, + "longitude": self.longitude, + "name": self.name, + "number": self.number, + "site": self.site, + "type": self.type, + } + + def __str__(self): + return json.dumps(self.json_data(), default=str) diff --git a/uw_space/resources/space/file/space/v1/facility.json_facility_code_MEB b/uw_space/resources/space/file/space/v1/facility.json_facility_code_MEB new file mode 100644 index 0000000..ec17b7d --- /dev/null +++ b/uw_space/resources/space/file/space/v1/facility.json_facility_code_MEB @@ -0,0 +1,51 @@ +{ + "TotalCount": 1, + "Facilitys": [{ + "FacilityCode": "MEB", + "FacilityType": { + "Code": "BLDG", + "Description": "Building" + }, + "Status": "A", + "AggregateFacilityNumber": "1347", + "Site": "SEA_MN", + "Name": "Mechanical Engr Bldg", + "LongName": "Mechanical Engineering Building", + "LeasedOrOwned": "OWNED", + "OFMCountyCode": "17", + "StreetAddress": null, + "City": null, + "State": null, + "PostalCode": null, + "Country": null, + "CountryCode2": null, + "CountryCode3": null, + "County": null, + "FacilityURI": { + "FacilityNumber": "1347", + "FacilityCode": "MEB", + "Description": "Mechanical Engr Bldg", + "Href": "/space/v1/facility/1347.json" + }, + "FacilityNumber": "1347" + }], + "Current": { + "Href": "/space/v1/facility.json?facility_type=&facility_code=MEB&status=&aggregate_number=&site=&name=&long_name=&leased_or_owned=&street=&city=&state=&postal_code=&page_start=1&page_size=10", + "FacilityType": null, + "FacilityCode": "MEB", + "Status": null, + "AggregateNumber": null, + "Site": null, + "Name": null, + "LongName": null, + "LeasedOrOwned": null, + "Street": null, + "City": null, + "State": null, + "PostalCode": null, + "PageStart": "1", + "PageSize": "10" + }, + "Next": null, + "Previous": null +} diff --git a/uw_space/resources/space/file/space/v1/facility/1347.json b/uw_space/resources/space/file/space/v1/facility/1347.json new file mode 100644 index 0000000..d047fe1 --- /dev/null +++ b/uw_space/resources/space/file/space/v1/facility/1347.json @@ -0,0 +1,45 @@ +{ + "Addresses": [ + { + "Code": null, + "PrimaryAddress": "Y", + "StreetAddress": null, + "City": null, + "State": null, + "PostalCode": null, + "Country": null, + "CountryCode2": null, + "CountryCode3": null, + "County": null, + "CenterPoint": { + "Latitude": "0.0", + "Longitude": "0.0" + } + } + ], + "AggregateFacilityNumber": "1347", + "ConstructionType": "M/W", + "FacilityCode": "MEB", + "FacilityNumber": "1347", + "FacilityType": { + "Code": "BLDG", + "Description": "Building" + }, + "GrossSquareFeet": "97768", + "IsRegisteredHistoricSite": "N", + "LeasedOrOwned": "OWNED", + "LongName": "Mechanical Engineering Building", + "ModifiedDate": "3/27/2021 4:53:09 AM", + "Name": "Mechanical Engr Bldg", + "Site": { + "Code": "SEA_MN", + "Description": "Seattle Main Campus" + }, + "RoomCount": 252, + "Status": "A", + "OFMCountyCode": "17", + "CenterPoint": { + "Latitude": "47.653693", + "Longitude": "-122.304747" + } +} diff --git a/uw_attest/test.py b/uw_space/test.py similarity index 90% rename from uw_attest/test.py rename to uw_space/test.py index 1334e5d..e0382ac 100644 --- a/uw_attest/test.py +++ b/uw_space/test.py @@ -10,7 +10,7 @@ if __name__ == '__main__': path = abspath(os.path.join(dirname(__file__), "..", "conf", "test.conf")) - use_configparser_backend(path, 'ATTEST') + use_configparser_backend(path, 'SPACE') from nose2 import discover discover() diff --git a/uw_attest/tests/__init__.py b/uw_space/tests/__init__.py similarity index 100% rename from uw_attest/tests/__init__.py rename to uw_space/tests/__init__.py diff --git a/uw_space/tests/test_dao.py b/uw_space/tests/test_dao.py new file mode 100644 index 0000000..480f579 --- /dev/null +++ b/uw_space/tests/test_dao.py @@ -0,0 +1,20 @@ +# Copyright 2021 UW-IT, University of Washington +# SPDX-License-Identifier: Apache-2.0 + +from unittest import TestCase +import mock +from commonconf import override_settings +from restclients_core.exceptions import DataFailureException +from uw_space.dao import SPACE_DAO +from uw_space.utils import fdao_space_override + + +@fdao_space_override +class TestSpaceDao(TestCase): + + def test_dao(self): + dao = SPACE_DAO() + self.assertEqual(dao.service_name(), "space") + self.assertTrue( + dao.service_mock_paths()[0].endswith( + "uw-restclients-space/uw_space/resources")) diff --git a/uw_space/tests/test_facilities.py b/uw_space/tests/test_facilities.py new file mode 100644 index 0000000..da5a38a --- /dev/null +++ b/uw_space/tests/test_facilities.py @@ -0,0 +1,40 @@ +# Copyright 2021 UW-IT, University of Washington +# SPDX-License-Identifier: Apache-2.0 + +from unittest import TestCase +from restclients_core.exceptions import DataFailureException +from uw_space import Facilities +from uw_space.utils import fdao_space_override + +data = { + 'code': 'MEB', + 'last_updated': '2021-03-27 04:53:09', + 'latitude': '47.653693', + 'longitude': '-122.304747', + 'name': 'Mechanical Engineering Building', + 'number': '1347', + 'site': 'Seattle Main Campus', + 'type': 'Building' + } + + +@fdao_space_override +class TestSpace(TestCase): + def test_search_by_code(self): + fac = Facilities().search_by_code("MEB") + self.assertEqual(len(fac), 1) + self.assertEqual(fac[0].json_data(), data) + + self.assertRaises( + DataFailureException, + Facilities().search_by_code, "None" + ) + + def test_search_by_number(self): + fac = Facilities().search_by_number("1347") + self.assertEqual(fac.json_data(), data) + + self.assertRaises( + DataFailureException, + Facilities().search_by_number, "0" + ) diff --git a/uw_attest/utils.py b/uw_space/utils.py similarity index 64% rename from uw_attest/utils.py rename to uw_space/utils.py index e0642c0..0d521c6 100644 --- a/uw_attest/utils.py +++ b/uw_space/utils.py @@ -4,10 +4,8 @@ from dateutil.parser import parse from commonconf import override_settings -fdao_attest_override = override_settings( - RESTCLIENTS_ATTEST_DAO_CLASS='Mock') -fdao_attest_auth_override = override_settings( - RESTCLIENTS_ATTEST_AUTH_DAO_CLASS='Mock') +fdao_space_override = override_settings( + RESTCLIENTS_SPACE_DAO_CLASS='Mock') def str_to_datetime(s):