Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardparis committed Oct 5, 2016
1 parent 5a9504a commit 3d1d5dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
12 changes: 3 additions & 9 deletions api/filters/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,9 @@ def test_create_storlet_ok(self, mock_is_valid_request):
response = storlet_list(request)
storlets = json.loads(response.content)
self.assertEqual(len(storlets), 2)

if storlets[0]['id'] == "1":
storlet1 = storlets[0]
storlet2 = storlets[1]
else:
storlet1 = storlets[1]
storlet2 = storlets[0]
self.assertEqual(storlet1['main'], 'com.example.FakeMain')
self.assertEqual(storlet2['main'], 'com.example.SecondMain')
sorted_list = sorted(storlets, key=lambda st: st['id'])
self.assertEqual(sorted_list[0]['main'], 'com.example.FakeMain')
self.assertEqual(sorted_list[1]['main'], 'com.example.SecondMain')

def test_create_storlets_are_sorted_by_id(self, mock_is_valid_request):
"""
Expand Down
21 changes: 20 additions & 1 deletion api/registry/tests_dynamic_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from registry.dynamic_policies.rules.rule import Rule
from registry.dynamic_policies.rules.rule_transient import TransientRule
from registry.dynamic_policies.metrics.bw_info import BwInfo
from registry.dynamic_policies.metrics.bw_info_ssync import BwInfoSSYNC
from registry.dynamic_policies.metrics.swift_metric import SwiftMetric

from httmock import urlmatch, HTTMock
Expand Down Expand Up @@ -167,7 +168,7 @@ def test_transient_action_set_is_triggered_200(self, mock_requests_delete, mock_
# metrics/bw_info
#

@mock.patch('registry.dynamic_policies.metrics.swift_metric.Thread.start')
@mock.patch('registry.dynamic_policies.metrics.bw_info.Thread.start')
def test_metrics_bw_info(self, mock_thread_start):
bw_info = BwInfo('exchange', 'queue', 'routing_key', 'method')
self.assertTrue(mock_thread_start.called)
Expand All @@ -176,13 +177,31 @@ def test_metrics_bw_info(self, mock_thread_start):
bw_info.notify(body)
self.assertEquals(bw_info.count["123456789abcedef"]["10.0.0.1"]["1"]["sda1"], "12")

#
# metrics/bw_info_ssync
#

@mock.patch('registry.dynamic_policies.metrics.bw_info.Thread.start')
def test_metrics_bw_info_ssync(self, mock_thread_start):
bw_info_ssync = BwInfoSSYNC('exchange', 'queue', 'routing_key', 'method')
self.assertTrue(mock_thread_start.called)
data = {"10.0.0.1": '4'} # ?
body = json.dumps(data)
bw_info_ssync.notify(body)
self.assertEquals(bw_info_ssync.count["10.0.0.1"], "4")

#
# metrics/swift_metric
#

@mock.patch('registry.dynamic_policies.metrics.swift_metric.Thread')
def test_metrics_swift_metric(self, mock_thread):
swift_metric = SwiftMetric('exchange', 'metric_id', 'routing_key')
data = {"controller": {"@timestamp": 123456789, "AUTH_bd34c4073b65426894545b36f0d8dcce": 3}}
body = json.dumps(data)
swift_metric.notify(body)
self.assertTrue(mock_thread.called)
self.assertIsNone(swift_metric.get_value())

@mock.patch('registry.dynamic_policies.metrics.swift_metric.socket.socket')
def test_metrics_swift_metric_send_data_to_logstash(self, mock_socket):
Expand Down

0 comments on commit 3d1d5dc

Please sign in to comment.