-
Notifications
You must be signed in to change notification settings - Fork 36
Testing
Contents
How to run tests and get coverage reports for GWELLS
Commands assume you are running the docker backend image, if not run
docker-compose up -d
Backend testing is done using django.test
tools, and coverage reports are generated using coverage v4.4.2
- Backend tests can be manually run by running
make test-django
- Coverage reports can be generated by running
make django-coverage
- A detailed HTML Report can be generated with
make django-coverage-html
These generated files are gitignored.
class TestWellLocationsSearch(APITestCase):
fixtures = ['gwells-codetables', 'wellsearch-codetables', 'wellsearch', 'registries', 'registries-codetables', 'aquifers']
def test_well_locations(self):
# Basic test to ensure that the well location search returns a non-error response
url = reverse('well-locations-v1')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_old_drilling_company_filter(self):
# Make sure old drilling_company query string filtering still works
url = reverse('well-locations-v1')
response = self.client.get(url, {
'drilling_company': 'bf5d31ea-8a5a-4363-8a5e-6c00eed03058'
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 5)
As of February 7th, 2024
Statements | Missed | Skipped | Percentage |
---|---|---|---|
11,777 | 3054 | 0 | 74% |
Frontend tests are done through the vue-cli-service
library
- Test
npm run test:unit
- Test with Coverage printouts:
npm run coverage:test
Update code snapshots
npm run test:unit:update
Assumes Docker Desktop is running containers
- Test
make test-vue
- Test with Coverage printouts:
make vue-coverage
Update code snapshots
make test-vue-update
const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(VueRouter)
const router = new VueRouter()
describe('ActivitySubmissionForm.vue', () => {
it('renders components based on the activity selected (Yield exists on construction report', () => {
const wrapper = shallowMount(ActivitySubmissionForm, {
localVue,
router,
propsData: {
sections: { wellYield: true },
currentStep: null,
form: {},
activityType: 'CON',
formSteps: {
CON: ['wellYield']
},
formIsFlat: true
}
})
expect(wrapper.vm.showSection('wellYield')).toBe(true)
})
As of February 7th, 2024
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---|---|---|---|---|---|
All Files | 51.71 | 18.45 | 21.67 | 52.27 |
Running the tests through the following methods will load all the necessary environment variables locally into your terminal shell. These values don't persist outside of your shell. These commands will run all tests.
- Have your Docker images running.
- In your .envrc file, you need to populate the
GWELLS_API_TEST_CLIENT_SECRET
secret. This is obtainable from OpenShift under[-tools]
->Secrets
->apitest-secrets
.- Optionally you can populate the
GWELLS_API_TEST_USER
andGWELLS_API_TEST_PASSWORD
keys using OpenShift secrets or your own IDIR.- If these two fields are not populated, the terminal will prompt for input.
- Optionally you can populate the
- Run one of the following commands to run all the test suites:
- From api-tests:
./run_local_all.sh
- From root:
make api-tests-local
- add the argument
TEST_FILE="your filename"
to run only one test suite
- add the argument
- From api-tests:
Do not commit these secrets (even accidentally!).
- Develop your API Tests in Postman
- Export the collection (this results in a json file)
- Create an accompanying Bash script
- The pipeline will run your tests and report back in Jenkins
When you're developing new Postman collections, please create an accompanying bash script to run them easily! This will help with loading in env variables, running all test suites at once, and reducing errors.
When creating your bash script, use the file structure
local_*.sh
This will ensure your tests are picked up by thelocal_run_all.sh
script
Add this section of script to the top of your new bash script. It will check if the GWELLS_API_TEST_USER
Environment variable is present, if it is not it will load in all the environment variables to your terminal from the .envrc
file. This helps to make all tests run standalone while reducing the setup.
# Load ENVs to environment if not already present
if [ -z "$GWELLS_API_TEST_USER" ] && [ -f "./.envrc" ]; then
source ./.envrc
set -e
fi
You can also ensure that all necessary environment variables are loaded before running the test suites by adding:
ENV_VARS=(
# ...All Envs needed for your tests
)
for env_var in ${ENV_VARS[@]}
do
if [ -z ${!env_var+x} ]; then
echo "$env_var is unset"
exit
fi
done
- Working on GWELLS (full workflow from writing code to deploying to prod)
- Water terminologies
- Testing
- Swagger Documentation
- Restore a database backup manually
- (Archived) Manual Syncing of DEV to TEST to PROD
- (Archived) Setup GWells data migration for local dev test
- Update PostGres Oracle Foreign Data Wrapper image
- Increase PostgreSQL Database storage
- (Archived) Regular Corruption of the PostgreSQL DB
- (Archived) Recovering from a corrupt PostgreSQL Database