class TestUserResource(unittest.TestCase): def setUp(self): self.service = Mock() self.proxy = LineSIPServiceProxy(self.service) self.items = [sentinel.item1, sentinel.item2] def test_when_searching_then_returns_sip_lines(self): self.service.find_all_by_protocol.return_value = self.items expected = SearchResult(items=self.items, total=len(self.items)) result = self.proxy.search({}) assert_that(result, equal_to(expected)) self.service.find_all_by_protocol.assert_called_once_with('sip') def test_when_getting_item_then_uses_service(self): expected = self.service.get.return_value result = self.proxy.get(sentinel.line_id) assert_that(result, equal_to(expected)) self.service.get.assert_called_once_with(sentinel.line_id) def test_when_creating_then_fixes_attributes_on_model(self): line = LineSIP(username='******') attributes = ['id', 'number', 'context', 'protocol', 'protocolid', 'callerid', 'device_id', 'provisioning_extension', 'configregistrar', 'device_slot'] self.proxy.create(line) created_line = self.service.create.call_args[0][0] assert_that(line.name, equal_to('myusername')) for attribute in attributes: assert_that(created_line, has_property(attribute, None)) def test_when_editing_then_fixes_username_on_model(self): line = LineSIP(username='******') self.proxy.edit(line) edited_line = self.service.edit.call_args[0][0] assert_that(edited_line.name, equal_to('myusername')) def test_when_deleting_line_then_deletes_using_service(self): self.proxy.delete(sentinel.line) self.service.delete.assert_called_once_with(sentinel.line)
def setUp(self): self.service = Mock() self.proxy = LineSIPServiceProxy(self.service) self.items = [sentinel.item1, sentinel.item2]