Skip to content

Commit

Permalink
Merge pull request #99 from department-of-veterans-affairs/90
Browse files Browse the repository at this point in the history
Upgrade dependencies.  Remove unused Docker-related files.  Update the README.
  • Loading branch information
kalbfled authored Aug 31, 2022
2 parents c745ca7 + 427552d commit aa6eecc
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 320 deletions.
3 changes: 3 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fileignoreconfig:
- filename: notifications_utils/sanitise_text.py
checksum: 96cf794e49031d454616ae36522a62082e68e3019ba4533084cebf6a6ce0ec0d
65 changes: 0 additions & 65 deletions Makefile

This file was deleted.

58 changes: 13 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,26 @@
# Notification - notifications-utils [BETA]
Shared python code for Notification
# notifications-utils

Provides logging utils etc.
Shared Python 3 code for Notification to provide logging utilities, etc. It has not been run against any version of python 2.x

## Installing
## Installing Dependencies

This is a [python](https://www.python.org/) application.
Run these commands from the project's root directory to install and activate a virtual environment and to install Python dependencies, including dependencies for running unit tests.

#### Python version
This is a python 3 application. It has not been run against any version of python 2.x
1. `python3 -m venv venv/`
2. `./scripts/bootstrap.sh`

brew install python3
If you encounter an error about Wheel failing to build, ensure you have the Python3 development libraries installed on your machine. On Linux, this is the package `libpython3-dev`.

#### Dependency management
## Unit Tests

This is done through [pip](https://pip.readthedocs.io) and [virtualenv](https://virtualenv.readthedocs.org/en/latest/). In practise we have used
[VirtualEnvWrapper](http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html) for our virtual environments.

Setting up a virtualenvwrapper for python3

mkvirtualenv -p /usr/local/bin/python3 notifications-utils


The boostrap script will set the application up. *Ensure you have activated the virtual environment first.*

./scripts/bootstrap.sh

This will

* Use pip to install dependencies.

#### Tests

The `./scripts/run_tests.sh` script will run all the tests. [py.test](http://pytest.org/latest/) is used for testing.

Running tests will also apply syntax checking, using [pycodestyle](https://pypi.python.org/pypi/pycodestyle).

Additionally code coverage is checked via pytest-cov:
The `./scripts/run_tests.sh` script runs all unit tests using [py.test](http://pytest.org/latest/) and applies syntax checking using [pycodestyle](https://pypi.python.org/pypi/pycodestyle).

## Versioning

After making changes in this repo, complete the following steps to see those changes in `notification-api`.
Note: to test locally before pushing, do steps #1 and #4 below and then follow instructions in the `notification-api` README.

1. Increment the version in `notifications_utils/version.py`.

2. Push this change.

3. Manually run `./scripts/push-tag.sh`, which will look at `version.py` and push a tag with that version.

4. In `notification-api`, update `requirements.txt` and `requirements-app.txt` to point at the newly generated tag.
With the virtual environment active, run `python setup.py --version` to see the current version **on the current branch**. Use `git tag` to add release tags to commits, and push the tags.

5. Push this change.
You can reference these release tags in requirements files in other repositories. See [notification-api](https://github.com/department-of-veterans-affairs/notification-api/blob/master/requirements-app.txt) for an example.

## Documentation
## E-mail Template Documentation

Documentation for the template used to render emails is in the [docs](./docs/README.md) folder.
Documentation for the template used to render e-mails is in the [docs](./docs/README.md) folder.
29 changes: 0 additions & 29 deletions docker/Dockerfile

This file was deleted.

16 changes: 0 additions & 16 deletions docker/Makefile

This file was deleted.

Binary file removed notifications_utils/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions notifications_utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def after_request(response):
handlers = get_handlers(app)
loglevel = logging.getLevelName(app.config['NOTIFY_LOG_LEVEL'])
loggers = [app.logger, logging.getLogger('utils')]
for l, handler in product(loggers, handlers):
l.addHandler(handler)
l.setLevel(loglevel)
for the_logger, handler in product(loggers, handlers):
the_logger.addHandler(handler)
the_logger.setLevel(loglevel)
logging.getLogger('boto3').setLevel(logging.WARNING)
logging.getLogger('s3transfer').setLevel(logging.WARNING)
app.logger.info("Logging configured")
Expand Down
18 changes: 9 additions & 9 deletions notifications_utils/recipients.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ def template_type(self, value):
@property
def has_errors(self):
return bool(
self.missing_column_headers or
self.duplicate_recipient_column_headers or
self.more_rows_than_can_send or
self.too_many_rows or
(not self.allowed_to_send_to) or
any(self.rows_with_errors)
self.missing_column_headers
or self.duplicate_recipient_column_headers
or self.more_rows_than_can_send
or self.too_many_rows
or not self.allowed_to_send_to
or any(self.rows_with_errors)
) # `or` is 3x faster than using `any()` here

@property
Expand Down Expand Up @@ -258,8 +258,8 @@ def missing_column_headers(self):
return set(
key for key in self.placeholders
if (
Columns.make_key(key) not in self.column_headers_as_column_keys and
not self.is_optional_address_column(key)
Columns.make_key(key) not in self.column_headers_as_column_keys
and not self.is_optional_address_column(key)
)
)

Expand Down Expand Up @@ -388,7 +388,7 @@ def validate_local_phone_number(number, column=None):

def validate_phone_number(number, column=None, international=False):

if(";" in number):
if ';' in number:
raise InvalidPhoneError('Not a valid number')

if (not international) or is_local_phone_number(number):
Expand Down
6 changes: 3 additions & 3 deletions notifications_utils/sanitise_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class SanitiseSMS(SanitiseText):
WELSH_NON_GSM_CHARACTERS = set('ÂâÊêÎîÔôÛûŴŵŶŷ')

ALLOWED_CHARACTERS = set(
'@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1bÆæßÉ !"#¤%&\'()*+,-./0123456789:;<=>?' +
'¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà' +
'@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1bÆæßÉ !"#¤%&\'()*+,-./0123456789:;<=>?'
'¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà'
# character set extension
'^{}\\[~]|€'
) | WELSH_NON_GSM_CHARACTERS
Expand All @@ -113,6 +113,6 @@ class SanitiseASCII(SanitiseText):
[chr(x) for x in range(32, 127)]
"""
ALLOWED_CHARACTERS = set(
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
)
2 changes: 1 addition & 1 deletion notifications_utils/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def __init__(
self.preview_mode = preview_mode
# set this again to make sure the correct either utils / downstream local jinja is used
# however, don't set if we are in a test environment (to preserve the above mock)
if("pytest" not in sys.modules):
if "pytest" not in sys.modules:
self.jinja_template = self.template_env.get_template('email_template.jinja2')

@property
Expand Down
17 changes: 8 additions & 9 deletions requirements_for_test.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
-r requirements.txt

flake8==3.7.8
flake8-print==3.1.4
freezegun==1.0.0
phonenumbers==8.12.12
pytest==5.1.2
pytest-cov==2.10.1
pytest-mock==1.10.4
pytest-xdist==1.29.0
requests-mock==1.8.0
flake8~=5.0.4
flake8-print~=5.0.0
freezegun~=1.2.2
pytest~=7.1.2
pytest-cov~=3.0.0
pytest-mock~=3.8.2
pytest-xdist~=2.5.0
requests-mock~=1.9.3
1 change: 1 addition & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#
# NOTE: This script expects to be run from the project root with ./scripts/bootstrap.sh.
# It is part of the Github CI workflow.

set -o pipefail

Expand Down
55 changes: 0 additions & 55 deletions scripts/push-tag.sh

This file was deleted.

8 changes: 4 additions & 4 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#
# Run project tests
#
# NOTE: This script expects to be run from the project root with
# ./scripts/run_tests.sh
# NOTE: This script expects to be run from the project root with ./scripts/run_tests.sh.
# It is part of the Github CI workflow.

# Use default environment vars for localhost if not already set
# Use default environment vars for localhost if not already set.

set -o pipefail

Expand All @@ -22,7 +22,7 @@ function display_result {
fi
}

flake8 .
flake8 --config .flake8 .
display_result $? 1 "Code style check"

## Code coverage
Expand Down
Loading

0 comments on commit aa6eecc

Please sign in to comment.