Fix flake8 and bandit tests

* enable voting job on pep8 tox env
 * fix pep8 tox job
 * add db.sqlite3 in ignore file

Change-Id: If11fb74553a6f1cb986cbed17e0fc8386d08c032
This commit is contained in:
Guillaume Vincent 2018-06-20 09:37:55 +02:00 committed by David Moreau Simard
parent 36cac6e4af
commit a14228c902
10 changed files with 27 additions and 29 deletions

2
.gitignore vendored
View File

@ -91,6 +91,6 @@ ENV/
# Rope project settings
.ropeproject
.*/db.sqlite3
db.sqlite3
www/
data/

View File

@ -2,8 +2,7 @@
check:
jobs:
- tox-py35
- tox-pep8:
voting: false
- tox-pep8
gate:
jobs:
- tox-py35

View File

@ -16,7 +16,7 @@ class FileFactory(factory.DjangoModelFactory):
class Meta:
model = models.File
path = '/tmp/playbook.yml'
path = '/path/playbook.yml'
content = factory.SubFactory(FileContentFactory)

View File

@ -7,13 +7,13 @@ from ara.api.tests import factories
class FileTestCase(APITestCase):
def test_file_factory(self):
file_content = factories.FileContentFactory()
file = factories.FileFactory(path='/tmp/playbook.yml', content=file_content)
self.assertEqual(file.path, '/tmp/playbook.yml')
file = factories.FileFactory(path='/path/playbook.yml', content=file_content)
self.assertEqual(file.path, '/path/playbook.yml')
self.assertEqual(file.content.sha1, file_content.sha1)
def test_file_serializer(self):
serializer = serializers.FileSerializer(data={
'path': '/tmp/playbook.yml',
'path': '/path/playbook.yml',
'content': '# playbook'
})
serializer.is_valid()
@ -25,7 +25,7 @@ class FileTestCase(APITestCase):
content = '# playbook'
serializer = serializers.FileSerializer(data={
'path': '/tmp/1/playbook.yml',
'path': '/path/1/playbook.yml',
'content': content
})
serializer.is_valid()
@ -33,7 +33,7 @@ class FileTestCase(APITestCase):
file_content.refresh_from_db()
serializer2 = serializers.FileSerializer(data={
'path': '/tmp/2/playbook.yml',
'path': '/path/2/playbook.yml',
'content': content
})
serializer2.is_valid()
@ -46,7 +46,7 @@ class FileTestCase(APITestCase):
def test_create_file(self):
self.assertEqual(0, models.File.objects.count())
request = self.client.post('/api/v1/files/', {
'path': '/tmp/playbook.yml',
'path': '/path/playbook.yml',
'content': '# playbook'
})
self.assertEqual(201, request.status_code)
@ -69,24 +69,24 @@ class FileTestCase(APITestCase):
def test_update_file(self):
file = factories.FileFactory()
self.assertNotEqual('/tmp/new_playbook.yml', file.path)
self.assertNotEqual('/path/new_playbook.yml', file.path)
request = self.client.put('/api/v1/files/%s/' % file.id, {
"path": "/tmp/new_playbook.yml",
"path": "/path/new_playbook.yml",
'content': '# playbook'
})
self.assertEqual(200, request.status_code)
file_updated = models.File.objects.get(id=file.id)
self.assertEqual('/tmp/new_playbook.yml', file_updated.path)
self.assertEqual('/path/new_playbook.yml', file_updated.path)
def test_partial_update_file(self):
file = factories.FileFactory()
self.assertNotEqual('/tmp/new_playbook.yml', file.path)
self.assertNotEqual('/path/new_playbook.yml', file.path)
request = self.client.patch('/api/v1/files/%s/' % file.id, {
"path": "/tmp/new_playbook.yml",
"path": "/path/new_playbook.yml",
})
self.assertEqual(200, request.status_code)
file_updated = models.File.objects.get(id=file.id)
self.assertEqual('/tmp/new_playbook.yml', file_updated.path)
self.assertEqual('/path/new_playbook.yml', file_updated.path)
def test_delete_file(self):
file = factories.FileFactory()

View File

@ -1,6 +1,5 @@
from rest_framework.test import APITestCase
from ara.api import serializers, models
from ara.api.tests import factories

View File

@ -15,7 +15,7 @@ class PlaybookTestCase(APITestCase):
serializer = serializers.PlaybookSerializer(data={
'ansible_version': '2.4.0',
'file': {
'path': '/tmp/playbook.yml',
'path': '/path/playbook.yml',
'content': '# playbook'
}
})
@ -28,7 +28,7 @@ class PlaybookTestCase(APITestCase):
serializer = serializers.PlaybookSerializer(data={
'ansible_version': '2.4.0',
'file': {
'path': '/tmp/playbook.yml',
'path': '/path/playbook.yml',
'content': '# playbook'
},
'parameters': {'foo': 'bar'}
@ -65,7 +65,7 @@ class PlaybookTestCase(APITestCase):
request = self.client.post('/api/v1/playbooks/', {
"ansible_version": "2.4.0",
'file': {
'path': '/tmp/playbook.yml',
'path': '/path/playbook.yml',
'content': '# playbook'
}
})

View File

@ -12,11 +12,11 @@ class PlaybookFileTestCase(APITestCase):
self.client.post('/api/v1/playbooks/', {
'ansible_version': '2.4.0',
'file': {
'path': '/tmp/playbook.yml',
'path': '/path/playbook.yml',
'content': '# playbook'
},
'files': [{
'path': '/tmp/host',
'path': '/path/host',
'content': '# host'
}],
})
@ -27,7 +27,7 @@ class PlaybookFileTestCase(APITestCase):
playbook = factories.PlaybookFactory()
self.assertEqual(1, models.File.objects.all().count())
self.client.post('/api/v1/playbooks/%s/files/' % playbook.id, {
'path': '/tmp/playbook.yml',
'path': '/path/playbook.yml',
'content': '# playbook'
})
self.assertEqual(2, models.File.objects.all().count())
@ -39,11 +39,11 @@ class PlaybookFileTestCase(APITestCase):
number_file_contents = models.FileContent.objects.all().count()
content = '# playbook %s' % time.time()
self.client.post('/api/v1/playbooks/%s/files/' % playbook.id, {
'path': '/tmp/1/playbook.yml',
'path': '/path/1/playbook.yml',
'content': content
})
self.client.post('/api/v1/playbooks/%s/files/' % playbook.id, {
'path': '/tmp/2/playbook.yml',
'path': '/path/2/playbook.yml',
'content': content
})
self.assertEqual(number_playbooks + 2, models.File.objects.all().count())

View File

@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU General Public License
# along with ARA. If not, see <http://www.gnu.org/licenses/>.
from rest_framework.decorators import api_view, detail_route
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.reverse import reverse

View File

@ -1,15 +1,15 @@
import logging
import os
import random
import sys
from envparse import env
from django.utils.crypto import get_random_string
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def get_secret_key(secret_key):
if not secret_key:
return "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$^&*(-_=+)") for i in range(50)])
return get_random_string(length=50)
return secret_key

View File

@ -57,4 +57,4 @@ max-line-length = 120
ignore = E123,E125,E741
enable-extensions=H106,H203
show-source = True
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,ara/api/migrations