Skip to content

Commit

Permalink
Merge pull request #25 from fecgov/release/sprint-2
Browse files Browse the repository at this point in the history
Release/sprint 2
  • Loading branch information
mjtravers authored Jan 27, 2022
2 parents 896ae5c + b5732e1 commit 72048b4
Show file tree
Hide file tree
Showing 12 changed files with 478 additions and 192 deletions.
40 changes: 40 additions & 0 deletions .circleci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# CircleCI Configuration
## Environment Variables
There is a minimum acceptable percentage for unit test code coverage that defaults to 85%.
You can modify this minimum by setting the MIN_COVERAGE_PERCENT environment variable to a
different value.

# Using CircleCI local CLI

## Install circleci local
Install on Linux or Mac with:
```
curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh | bash
```

Details and instructions for other platforms in the [CircleCI Docs](https://circleci.com/docs/2.0/local-cli/)

## Validate the config.yml
Run this from the top level of the repo:
```
circleci config validate
```

## Run the CircleCI Job locally
You can run a CircleCI job locally and avoid the change/commit/wait loop you need to
do if you want to actually run the changes on Circle.
This can save a lot of time when trying to debug an issue in CI.
```
circleci local execute --job JOB_NAME
```

## Environment Variables
To run in the local CircleCI with specific environment variables, use the following pattern:

```
circleci local execute -e MIN_COVERAGE_PERCENT=15 --job unit-test
```

## CircleCI configuration
To get CircleCI to run tests, you have to configure the
project in the Circle web application https://app.circleci.com/
100 changes: 100 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# See: https://circleci.com/docs/2.0/orb-intro/
orbs:
# See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/python
python: circleci/[email protected]

# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
unit-test:
# These next lines defines a Docker executors: https://circleci.com/docs/2.0/executor-types/
# A list of available CircleCI Docker convenience images are available here: https://circleci.com/developer/images/image/cimg/python
docker:
- image: cimg/python:3.8

steps:
- checkout

- python/install-packages:
pkg-manager: pip
pip-dependency-file: requirements-test.txt

- run:
name: Run tests, save a coverage report, and save coverage percentage
command: |
pytest --cov=. --cov-report=html --cov-report=term | tee pytest.out
export NEW_PERCENT=$(cat pytest.out | grep TOTAL | awk '{print $4}' | grep -oE "[0-9]+" )
echo ${NEW_PERCENT} > htmlcov/total_percent.txt
echo Total code coverage percentage is ${NEW_PERCENT}%
- store_artifacts:
path: htmlcov

- run:
name: Compare the actual code coverage to the minimum target coverage
command: |
export NEW_PERCENT=$(cat htmlcov/total_percent.txt)
echo Comparing the current code coverage percentage of ${NEW_PERCENT}% to the target of ${MIN_COVERAGE_PERCENT-85}%
if [ "${NEW_PERCENT}" -lt ${MIN_COVERAGE_PERCENT-85} ]; then
echo The total code coverage percentage of ${NEW_PERCENT}% is below the minimum of ${MIN_COVERAGE_PERCENT-85}%
echo If you would like to modify the minimum coverage, set the MIN_COVERAGE_PERCENT environment variable
exit 1
fi
echo Coverage is good.
lint:
docker:
- image: cimg/python:3.8

steps:
- checkout

- python/install-packages:
pkg-manager: pip
pip-dependency-file: requirements-test.txt

- run:
name: Run lint
command: flake8 .


dependency-check:
docker:
- image: cimg/python:3.8

steps:
- checkout

- python/install-packages:
pkg-manager: pip
pip-dependency-file: requirements-test.txt

- run:
name: Run depency check
command: |
export today=$(date "+%Y-%m-%d")
# gather up the -i ignore IDs fro safety check
export ignores=$(
grep -vE "^\s*#" .safety.dependency.ignore | # print out any non-comment line
grep "[0-9]" | # filter out any line that doesn't have a number in it
awk -v "today=${today}" '{ if ($2 > today || $2 == "") print "-i", $1}' | # print any line with date after today
xargs echo # put all the output from previous command on one line
)
export command="safety check -r requirements.txt --full-report $ignores"
echo "----------------------------------------------------"
echo "If you need to modify the ignore list for the safety"
echo "check, edit .safety.dependency.ignore file"
echo "----------------------------------------------------"
eval $command
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
sample:
jobs:
- unit-test
- lint
- dependency-check
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/issue-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Issue template
about: Issue template for fecfile-validate
title: ''
labels: ''
assignees: ''

---

### Business Reason ###

As a [role], I will be able to [blank] so that I can [business reason]

### Acceptance Criteria ###

**If** [precedent]
**When** [action]
**Then** [result]
12 changes: 12 additions & 0 deletions .safety.dependency.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Any vulnerability ID numbers listed in this file will be ignored when
# running the safety dependency check. Each line should have the ID number
# and a date. The ID will be ignored by the CI pipeline check unitl the date
# in YYYY-MM-DD format listed for that line.
# If no date is listed, the exception will never expire. (NOT RECOMMENDED)
#
# test
# Example:
# 40104 2022-01-15
#
40104 2022-01-25 # gunicorn
40105 2022-01-25 # gunicorn
38 changes: 20 additions & 18 deletions api/tests.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import os
import json
import unittest

from validate import app


class BaseDatabaseTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
# app_step_3.config.update({
# 'DATABASE_NAME': TESTING_DATABASE_NAME
# })
# cls.db = sqlite3.connect(TESTING_DATABASE_NAME)
# cls.db.execute(CREATE_BOOK_TABLE_QUERY)
# cls.db.commit()
pass

# class BaseDatabaseTestCase(unittest.TestCase):
# @classmethod
# def setUpClass(cls):
# app_step_3.config.update({
# 'DATABASE_NAME': TESTING_DATABASE_NAME
# })
# cls.db = sqlite3.connect(TESTING_DATABASE_NAME)
# cls.db.execute(CREATE_BOOK_TABLE_QUERY)
# cls.db.commit()
@classmethod
def tearDownClass(cls):
# os.remove(TESTING_DATABASE_NAME)
pass

# @classmethod
# def tearDownClass(cls):
# os.remove(TESTING_DATABASE_NAME)

# def setUp(self):
# self.app = self.APP.test_client()
# self.db.execute("DELETE FROM book;")
# self.db.commit()
def setUp(self):
# self.app = self.APP.test_client()
# self.db.execute("DELETE FROM book;")
# self.db.commit()
pass


class Step3TestCase(BaseDatabaseTestCase):
APP = app

# noinspection SpellCheckingInspection
def test_validate_parameters(self):
# Preconditions
resp = self.app.get('/book')
Expand Down
Loading

0 comments on commit 72048b4

Please sign in to comment.