Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions green_metric_tests/greencheck_test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const request = require('supertest');
const expect = require('chai').expect;

describe('Greencheck API', () => {
it('Has the correct URL property', () => {
request('https://django:8000')
.get('/greencheck/climateaction.tech')
.expect(200)
.expect('Content-Type', 'application/json')
.expect(function(res) {
if (!res.body.hasOwnProperty('url')) throw new Error("Expected 'url' key!");
})
.end(function(err, res){
if (err) throw err;
})
});
});
16 changes: 16 additions & 0 deletions green_metric_tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "green_metric_tests",
"version": "1.0.0",
"description": "Integration tests for the Greencheck API, intended for use with the Green Metrics Tool from Green Code Berlin. (https://www.green-coding.io/projects/green-metrics-tool/)",
"main": "index.js",
"scripts": {
"test": "mocha '**/*.spec.js'"
},
"author": "James Camilleri",
"license": "SEE LICENSE IN ../LICENCE",
"dependencies": {
"chai": "^4.2.0",
"mocha": "^10.4.0",
"supertest": "^7.0.0"
}
}
78 changes: 78 additions & 0 deletions usage_scenario.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
name: Greencheck Test
author: James Camilleri <jcamilleri@scottlogic.com>
description: Scenario to test the Greencheck endpoint of the Green Web Foundation Greencheck API

version: "3.5"

networks:
greencheck-network:

services:
mariadb:
image: mariadb:10.3
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: just-for-github-actions
MYSQL_DATABASE: greencheck
networks:
- greencheck-network

rabbitmq:
image: rabbitmq:3.9
env:
RABBITMQ_USERNAME: "guest"
RABBITMQ_PASSWORD: "guest"
ports:
- 5672:5672
options: '--hostname "rmq" --health-cmd "rabbitmqctl status" --health-interval 10s --health-timeout 10s --health-retries 3 --health-start-period 60s'
networks:
- greencheck-network

django:
depends_on:
- mariadb
build:
context: .
args:
PIPENV_CFG: --dev
command:
- cp -a . .
- python -m pip install --upgrade pipenv wheel
- pipenv install --deploy --dev --verbose
ports:
- "8000:8000"
restart: on-failure
volumes:
- .:/app
stdin_open: true
tty: true
networks:
- greencheck-network

test-container:
container_name: test-container
image: node
depends_on: django
setup-commands:
- cp ./green_metric_tests/greencheck_test.spec.js .
- cp ./green_metric_tests/package.json .
- npm install
networks:
- greencheck-network

flow:
- name: Greencheck API Test
container: test-container
commands:
- type: console
command: npm test
note: Starting test
read-notes-stdout: true
- type: console
command: sleep 30
note: Idling
- type: console
command: npm test
note: Starting test again