"""Cell API tests.
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import unittest

import mock

from treadmill import admin
from treadmill.api import cell


class ApiCellTest(unittest.TestCase):
    """treadmill.api.cell tests."""

    def setUp(self):
        self.cell = cell.API()

    def tearDown(self):
        pass

    @mock.patch('treadmill.context.AdminContext.conn',
                mock.Mock(return_value=admin.Admin(None, None)))
    @mock.patch('treadmill.admin.Cell.list', mock.Mock(return_value=[]))
    def test_list(self):
        """Dummy test for treadmill.api.cell._list()"""
        self.cell.list()
        cell_admin = admin.Cell(None)
        self.assertTrue(cell_admin.list.called)

    @mock.patch('treadmill.context.AdminContext.conn',
                mock.Mock(return_value=admin.Admin(None, None)))
    @mock.patch('treadmill.admin.Cell.get',
                mock.Mock(return_value={'cell': 'ny-999-cell'}))
    def test_get(self):
        """Dummy test for treadmill.api.cell.get()"""
        cell_admin = admin.Cell(None)
        self.cell.get('some-cell')
        cell_admin.get.assert_called_with('some-cell')

    @mock.patch('treadmill.context.AdminContext.conn',
                mock.Mock(return_value=admin.Admin(None, None)))
    @mock.patch('treadmill.admin.Cell.get',
                mock.Mock(return_value={'cell': 'ny-999-cell'}))
    @mock.patch('treadmill.admin.Cell.create', mock.Mock())
    def test_create(self):
        """Dummy test for treadmill.api.cell.create()"""
        cell_admin = admin.Cell(None)
        self.cell.create('some-cell', {'location': 'ny',
                                       'treadmillid': 'treadmld',
                                       'version': 'v3'})
        cell_admin.get.assert_called_with('some-cell', dirty=True)


if __name__ == '__main__':
    unittest.main()

[((60, 4, 60, 19), 'unittest.main', 'unittest.main', ({}, {}), '()', False, 'import unittest\n'), ((21, 20, 21, 30), 'treadmill.api.cell.API', 'cell.API', ({}, {}), '()', False, 'from treadmill.api import cell\n'), ((32, 21, 32, 37), 'treadmill.admin.Cell', 'admin.Cell', ({(32, 32, 32, 36): 'None'}, {}), '(None)', False, 'from treadmill import admin\n'), ((28, 45, 28, 71), 'mock.Mock', 'mock.Mock', (), '', False, 'import mock\n'), ((41, 21, 41, 37), 'treadmill.admin.Cell', 'admin.Cell', ({(41, 32, 41, 36): 'None'}, {}), '(None)', False, 'from treadmill import admin\n'), ((38, 16, 38, 63), 'mock.Mock', 'mock.Mock', (), '', False, 'import mock\n'), ((52, 21, 52, 37), 'treadmill.admin.Cell', 'admin.Cell', ({(52, 32, 52, 36): 'None'}, {}), '(None)', False, 'from treadmill import admin\n'), ((48, 16, 48, 63), 'mock.Mock', 'mock.Mock', (), '', False, 'import mock\n'), ((49, 47, 49, 58), 'mock.Mock', 'mock.Mock', ({}, {}), '()', False, 'import mock\n'), ((27, 39, 27, 62), 'treadmill.admin.Admin', 'admin.Admin', ({(27, 51, 27, 55): 'None', (27, 57, 27, 61): 'None'}, {}), '(None, None)', False, 'from treadmill import admin\n'), ((36, 39, 36, 62), 'treadmill.admin.Admin', 'admin.Admin', ({(36, 51, 36, 55): 'None', (36, 57, 36, 61): 'None'}, {}), '(None, None)', False, 'from treadmill import admin\n'), ((46, 39, 46, 62), 'treadmill.admin.Admin', 'admin.Admin', ({(46, 51, 46, 55): 'None', (46, 57, 46, 61): 'None'}, {}), '(None, None)', False, 'from treadmill import admin\n')]