Skip to content

Commit

Permalink
review comments addressed.
Browse files Browse the repository at this point in the history
  • Loading branch information
chambridge committed Feb 16, 2018
1 parent 8f3d04e commit 27e886d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions quipucords/api/source/tests_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
from django.test import TestCase
from django.core.urlresolvers import reverse
from rest_framework import status
from api.models import (Credential, Source, ScanTask, ScanJob)
from api.models import (Credential, Source, ScanTask)
import api.messages as messages
from api.source.view import format_source
from api.serializers import SourceSerializer
from scanner.test_util import create_scan_job


def dummy_start():
"""Create a dummy method for testing."""
pass


# pylint: disable=too-many-instance-attributes,invalid-name,too-many-lines
# pylint: disable=too-many-instance-attributes,invalid-name,R0904,C0302
class SourceTest(TestCase):
"""Test the basic Source infrastructure."""

Expand Down Expand Up @@ -133,22 +134,19 @@ def test_format_source(self):
port=22)
source.save()
end = datetime.now()
scan_task = ScanTask(source=source,
scan_type=ScanTask.SCAN_TYPE_CONNECT,
status=ScanTask.COMPLETED,
systems_count=10,
systems_scanned=9,
systems_failed=1,
start_time=start,
end_time=end)
scan_job, scan_task = create_scan_job(source)

scan_task.status = ScanTask.COMPLETED
scan_task.systems_count = 10
scan_task.systems_scanned = 9
scan_task.systems_failed = 1
scan_task.start_time = start
scan_task.end_time = end
scan_task.save()
scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_CONNECT,
status=ScanTask.COMPLETED,
start_time=start,
end_time=end)
scan_job.save()
scan_job.sources.add(source)
scan_job.tasks.add(scan_task)

scan_job.status = ScanTask.COMPLETED
scan_job.start_time = start
scan_job.end_time = end
scan_job.save()

serializer = SourceSerializer(source)
Expand All @@ -163,6 +161,7 @@ def test_format_source(self):
'systems_count': 10,
'systems_scanned': 9,
'systems_failed': 1}}

self.assertEqual(out, expected)

#################################################
Expand Down
2 changes: 1 addition & 1 deletion quipucords/api/source/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def format_source(json_source):
scan_task_qs = ScanTask.objects.filter(
source__id=source_id,
scan_type=ScanTask.SCAN_TYPE_CONNECT)
if scan_task_qs:
if scan_task_qs.count() > 0:
scan_task = scan_task_qs.latest('start_time')
scan_job = ScanJob.objects.filter(
tasks__id=scan_task.id).latest('start_time')
Expand Down

0 comments on commit 27e886d

Please sign in to comment.