def test_slo_detail_with_method_not_allowed(self): """ Test that POST requests to slo_detail() return METHOD_NOT_ALLOWED """ dsl_filter = 'bandwidth' slo_name = 'get_bw' target = 'AUTH_0123456789abcdef#1' request = self.factory.post('/filters/slo/' + dsl_filter + '/' + slo_name + '/' + target) response = slo_detail(request, dsl_filter, slo_name, target) self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
def test_slo_detail_when_does_not_exist(self): """ Test that a GET request to slo_detail() returns 404 if the slo does not exist """ dsl_filter = 'bandwidth' slo_name = 'get_bw' target = 'inexistent' request = self.factory.get('/filters/slo/' + dsl_filter + '/' + slo_name + '/' + target) response = slo_detail(request, dsl_filter, slo_name, target) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_update_slo_ok(self): """ Test that a PUT request to slo_detail() returns OK """ dsl_filter = 'bandwidth' slo_name = 'get_bw' target = 'AUTH_0123456789abcdef#2' new_value = '60' slo_data = {'value': new_value} request = self.factory.put('/filters/slo/' + dsl_filter + '/' + slo_name + '/' + target, slo_data, format='json') response = slo_detail(request, dsl_filter, slo_name, target) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # Verify the SLO was updated request = self.factory.get('/filters/slo/' + dsl_filter + '/' + slo_name + '/' + target) response = slo_detail(request, dsl_filter, slo_name, target) self.assertEqual(response.status_code, status.HTTP_200_OK) json_data = json.loads(response.content) self.assertEqual(json_data['value'], new_value)
def test_slo_detail_ok(self): """ Test that a GET request to slo_detail() returns OK """ # mock_get_project_list.return_value = {'0123456789abcdef': 'tenantA', 'abcdef0123456789': 'tenantB'} dsl_filter = 'bandwidth' slo_name = 'get_bw' target = 'AUTH_0123456789abcdef#2' request = self.factory.get('/filters/slo/' + dsl_filter + '/' + slo_name + '/' + target) response = slo_detail(request, dsl_filter, slo_name, target) self.assertEqual(response.status_code, status.HTTP_200_OK) json_data = json.loads(response.content) self.assertEqual(json_data['dsl_filter'], dsl_filter) self.assertEqual(json_data['slo_name'], slo_name) self.assertEqual(json_data['target'], target) self.assertEqual(json_data['value'], '20')
def test_delete_slo_ok(self): """ Test that a DELETE request to slo_detail() returns OK """ dsl_filter = 'bandwidth' slo_name = 'get_bw' target = 'AUTH_0123456789abcdef#2' request = self.factory.delete('/filters/slo/' + dsl_filter + '/' + slo_name + '/' + target) response = slo_detail(request, dsl_filter, slo_name, target) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) # Verify the SLO was deleted request = self.factory.get('/filters/slos') response = slo_list(request) self.assertEqual(response.status_code, status.HTTP_200_OK) json_data = json.loads(response.content) self.assertEqual(len(json_data), 5) # 6 --> 5