Skip to content
This repository has been archived by the owner on Sep 17, 2018. It is now read-only.

Commit

Permalink
Feature/scan lang (#6)
Browse files Browse the repository at this point in the history
* delete unnused test module mock db
* refactor tests structure and commands
* do not hardcode the lang when a webhook is received
* upgrade core version
* Bump version: 0.0.5 → 0.0.6
* change background scenario for tests
  • Loading branch information
alejandrogr authored Oct 26, 2017
1 parent 16eeff7 commit 7845434
Show file tree
Hide file tree
Showing 33 changed files with 171 additions and 212 deletions.
1 change: 0 additions & 1 deletion .env.required
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
BROKER_URI
DATABASE_URI
SCAN_PATH
SERVER_ADDRESS
GUNICORN_WORKERS
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ clean: ## remove all build, test, coverage and Python artifacts

.PHONY: test
test: ## run tests quickly with the default Python
python -m unittest discover -s tests/unit
py.test tests

.PHONY: test-all
test-all: ## run tests on every Python version with tox
Expand All @@ -51,9 +51,7 @@ lint: ## check style with flake8

.PHONY: coverage
coverage: ## check code coverage
coverage run --source=deeptracy_api -m unittest discover -s tests/unit
coverage report -m --fail-under 80
coverage xml -o coverage-reports/report.xml
py.test --cov=deeptracy_api tests --cov-fail-under 50

.PHONY: docs
docs: ## generate and shows documentation
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.5
0.0.6
2 changes: 1 addition & 1 deletion deeptracy_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import logging

__version__ = '0.0.5'
__version__ = '0.0.6'

root_log = logging.getLogger()
root_log.setLevel(logging.DEBUG)
Expand Down
4 changes: 2 additions & 2 deletions deeptracy_api/api/scan_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def post_scan():
return api_error_response('invalid payload'), 400

project_id = get_required_field(data, 'project_id')
lang = get_required_field(data, 'lang')
lang = data.get('lang', None)

scan = add_scan(project_id, lang, session)
scan = add_scan(project_id, session, lang=lang)
session.commit()

# when the scan is added to the database, a celery task is inserted for that scan to start the process
Expand Down
5 changes: 1 addition & 4 deletions deeptracy_api/webhook/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ def add_scan_for_project_with_repo(repo_url: str):

project = get_project_by_repo(repo_url, session)

# TODO: Do not hardcode the language, extract it from the project default_language
# https://github.com/BBVA/deeptracy/issues/8
lang = 'nodejs'
scan = add_scan(project.id, lang, session)
scan = add_scan(project.id, session)
session.commit()

celery = Celery('deeptracy', broker=BROKER_URI)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ celery==4.1.0
Flask==0.12.2
Flask-Cors==3.0.3
gunicorn==19.7.1
deeptracy_core==0.0.20
deeptracy_core==0.0.23
psycopg2==2.7.3.1
redis==2.10.6
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requests==2.18.4
flake8==2.6.0
tox==2.3.1
pytest==3.2.1
coverage==4.4.1
pytest-cov==2.5.1
behave==1.2.5
redis==2.10.6
SQLAlchemy==1.1.14
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.5
current_version = 0.0.6
commit = True
tag = False

Expand Down
13 changes: 0 additions & 13 deletions tests/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/acceptance/features/project-create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Create new projects
The API should be able to create new projects

Background: Database setup
Given an empty project table in database
Given an empty system

@only
Scenario Outline: Add a new project
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/features/project-delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Delete projects
The API should be able to delete existing projects

Background: Database setup
Given an empty project table in database
Given an empty system

Scenario: Delete project by id
When a project with id "0000001" exists in the database
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/features/project-read.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Read projects
The API should be able to read existing projects

Background: Database setup
Given an empty project table in database
Given an empty system


Scenario Outline: Get a project by id
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/features/project-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Update projects
The API should be able to update existing projects

Background: Database setup
Given an empty project table in database
Given an empty system

Scenario Outline: Updates an existing project
When a project with id "0000001" exists in the database
Expand Down
5 changes: 3 additions & 2 deletions tests/acceptance/features/scan.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Feature: Create new scans
The API should be able to create new scans

Background: Database setup
Given a database ready to receive scans
Given an empty system
And a database ready to receive scans

Scenario Outline: Create scan endpoint
When the user makes a "POST" request to "/api/1/scan/" endpoint with <payload>
Expand All @@ -15,6 +16,6 @@ Feature: Create new scans
Examples:
| payload | response_code | response | created |
| {"project_id":"123", "lang": "lang"} | 201 | {"project_id": "123", "lang": "lang", "state": "PENDING", "scan_analysis": [], "analysis_count": 0, "analysis_done": 0} | 1 |
| {"project_id":"123"} | 400 | {"error": {"msg": "missing lang"}} | 0 |
| {"project_id":"123"} | 201 | {"project_id": "123", "lang": null, "state": "PENDING", "scan_analysis": [], "analysis_count": 0, "analysis_done": 0} | 1 |
| {"lang": "lang"} | 400 | {"error": {"msg": "missing project_id"}} | 0 |
| {} | 400 | {"error": {"msg": "invalid payload"}} | 0 |
7 changes: 0 additions & 7 deletions tests/acceptance/steps/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
from sqlalchemy import text
from behave import given, then, when

from tests.acceptance.utils import clean_db


@given(u'an empty project table in database')
def step_impl(context):
clean_db(context)


@then(u'{created} projects are in the database')
def step_impl(context, created):
Expand Down
3 changes: 0 additions & 3 deletions tests/acceptance/steps/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@

from sqlalchemy import text
from behave import given, then
from tests.acceptance.utils import clean_db


@given(u'a database ready to receive scans')
def step_impl(context):
project_id = '123'
plugin_lang = 'lang'

clean_db(context)

sql = text('INSERT INTO project (id, repo) VALUES (:id, :repo)')
context.engine.execute(sql, id=project_id, repo='http://test.com')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
# limitations under the License.

from sqlalchemy import text
from behave import given


def clean_db(context):
@given(u'an empty system')
def step_impl(context):
sql = text('DELETE FROM scan')
context.engine.execute(sql)

Expand Down
13 changes: 0 additions & 13 deletions tests/unit/api/__init__.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/unit/api/exc/__init__.py

This file was deleted.

38 changes: 0 additions & 38 deletions tests/unit/api/exc/test_exceptions.py

This file was deleted.

31 changes: 0 additions & 31 deletions tests/unit/base_test.py

This file was deleted.

38 changes: 0 additions & 38 deletions tests/unit/mock_db.py

This file was deleted.

39 changes: 39 additions & 0 deletions tests/unit/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2017 BBVA
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""tests for DeeptracyException class"""

from unittest import TestCase

from deeptracy_api.api.exc.exceptions import APIError


class ScanBlueprintTestCase(TestCase):

def test_deeptracy_exception_holds_an_api_status_code(self):
"""Deeptracy exception class should holds an attribute
to save the api status code to return in case of that exception"""
status_code = 201
with self.assertRaises(APIError) as exc:
raise APIError('custom message', status_code=status_code)

self.assertEqual(exc.exception.status_code, status_code)

def test_deeptracy_exception_holds_a_message(self):
"""Deeptracy exception class should holds a message"""
msg = 'custom message'
with self.assertRaises(APIError) as exc:
raise APIError(msg)

self.assertTrue(msg in exc.exception.message)
Loading

0 comments on commit 7845434

Please sign in to comment.