"""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()

[((1944, 1959), 'unittest.main', 'unittest.main', ([], {}), '()\n', (1957, 1959), False, 'import unittest\n'), ((381, 391), 'treadmill.api.cell.API', 'cell.API', ([], {}), '()\n', (389, 391), False, 'from treadmill.api import cell\n'), ((751, 767), 'treadmill.admin.Cell', 'admin.Cell', (['None'], {}), '(None)\n', (761, 767), False, 'from treadmill import admin\n'), ((596, 622), 'mock.Mock', 'mock.Mock', ([], {'return_value': '[]'}), '(return_value=[])\n', (605, 622), False, 'import mock\n'), ((1145, 1161), 'treadmill.admin.Cell', 'admin.Cell', (['None'], {}), '(None)\n', (1155, 1161), False, 'from treadmill import admin\n'), ((997, 1044), 'mock.Mock', 'mock.Mock', ([], {'return_value': "{'cell': 'ny-999-cell'}"}), "(return_value={'cell': 'ny-999-cell'})\n", (1006, 1044), False, 'import mock\n'), ((1647, 1663), 'treadmill.admin.Cell', 'admin.Cell', (['None'], {}), '(None)\n', (1657, 1663), False, 'from treadmill import admin\n'), ((1433, 1480), 'mock.Mock', 'mock.Mock', ([], {'return_value': "{'cell': 'ny-999-cell'}"}), "(return_value={'cell': 'ny-999-cell'})\n", (1442, 1480), False, 'import mock\n'), ((1529, 1540), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (1538, 1540), False, 'import mock\n'), ((525, 548), 'treadmill.admin.Admin', 'admin.Admin', (['None', 'None'], {}), '(None, None)\n', (536, 548), False, 'from treadmill import admin\n'), ((911, 934), 'treadmill.admin.Admin', 'admin.Admin', (['None', 'None'], {}), '(None, None)\n', (922, 934), False, 'from treadmill import admin\n'), ((1347, 1370), 'treadmill.admin.Admin', 'admin.Admin', (['None', 'None'], {}), '(None, None)\n', (1358, 1370), False, 'from treadmill import admin\n')]