Skip to content

Commit

Permalink
Add tests for pool balance. rockstor#967
Browse files Browse the repository at this point in the history
  • Loading branch information
Mchakravartula committed Oct 21, 2015
1 parent 90d81fb commit 4ddf985
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/rockstor/storageadmin/tests/test_pool_balance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""
Copyright (c) 2012-2013 RockStor, Inc. <http://rockstor.com>
This file is part of RockStor.
RockStor is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
RockStor is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from rest_framework import status
from rest_framework.test import APITestCase
import mock
from mock import patch
from storageadmin.tests.test_api import APITestMixin

class PoolBalanceTests(APITestMixin, APITestCase):
fixtures = ['fix1.json']
BASE_URL = '/api/pools'

@classmethod
def setUpClass(cls):
super(PoolBalanceTests, cls).setUpClass()

# post mocks

cls.patch_balance_status = patch('storageadmin.views.pool_balance.balance_status')
cls.mock_balance_status = cls.patch_balance_status.start()
cls.mock_balance_status.return_value = {'status': 'finished','percent_done':'100' }


@classmethod
def tearDownClass(cls):
super(PoolBalanceTests, cls).tearDownClass()

def test_get(self):

# get base URL
# 'pool1' is the pool already created and exits in fix1.json
response = self.client.get('%s/pool1/balance' %self.BASE_URL)
self.assertEqual(response.status_code,
status.HTTP_200_OK, msg=response.data)

def test_post_requests(self):

# invalid pool
data = {'force': 'true'}
response = self.client.post('%s/invalid/balance' % self.BASE_URL, data=data)
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR, msg=response.data)

e_msg = ('Pool(invalid) does not exist')
self.assertEqual(response.data['detail'], e_msg)

# Invalid scrub command
data = {'force': 'true'}
pool_name = 'pool1'
response = self.client.post('%s/pool1/balance/invalid' % self.BASE_URL, data=data)
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR, msg=response.data)

e_msg = ('Unknown balance command: invalid')
self.assertEqual(response.data['detail'], e_msg)

# happy path
data = {'force': 'true'}
pool_name = 'pool1'
response = self.client.post('%s/pool1/balance' % self.BASE_URL, data=data)
self.assertEqual(response.status_code,
status.HTTP_200_OK, msg=response.data)


# happy path
data = {'force': 'true'}
pool_name = 'pool1'
response = self.client.post('%s/pool1/balance/status' % self.BASE_URL, data=data)
self.assertEqual(response.status_code,
status.HTTP_200_OK, msg=response.data)


0 comments on commit 4ddf985

Please sign in to comment.