Esempio n. 1
0
	def test_it_correctly_runs_command(self, call_mock):
		command = Command({'to': 'test', 'hop': 'go'})
		context = MagicMock()
		context.args = ['foo', 'bar']
		expected = 'test foo bar'
		result = command.run(context)
		call_mock.assert_called_with(expected, shell=True)
Esempio n. 2
0
	def test_it_correctly_runs_command(self, call_mock):
		command = Command({'to': 'test', 'hop': 'go'})
		context = MagicMock()
		context.args = ['foo', 'bar']
		expected = 'test foo bar'
		try:
			result = command.run(context)
		except SystemExit as e:
			self.assertTrue(isinstance(e.code, MagicMock))
		call_mock.assert_called_with(expected, shell=True)
Esempio n. 3
0
	def test_run_command_returns_correct_exit_codes(self):
		command = Command({'to': 'ls &> /dev/null', 'hop': 'go'})
		context = MagicMock()
		try:
			command.run(context)
		except SystemExit as e:
			self.assertEquals(e.code, 0)
		context.args = ['foo', 'bar']
		try:
			command.run(context)
		except SystemExit as e:
			self.assertNotEquals(e.code, 0)
Esempio n. 4
0
	def test_it_correctly_generates_the_clickObject(self, click_command, pass_context):
		command = Command({'to': 'foo', 'hop': 'bar'})
		test_func = MagicMock()
		test_func.return_value = 'test_command'
		pass_context.return_value = 'test_function'
		click_command.return_value = test_func
		result = command.setClickObject()
		self.assertEquals(result, 'test_command')
		pass_context.assert_called_with(command.run)
		test_func.assert_called_with('test_function')
		click_command.assert_called_with(
			name = command.getName(),
			help = command.data.get('description'),
			context_settings = {
				'allow_extra_args': True,
				'allow_interspersed_args': True,
			}
		)
Esempio n. 5
0
	def test_it_returns_the_value_of_self_clickObject(self):
		data = {'to': 'foo', 'hop': 'bar'}
		command = Command(data)
		command.clickObject = 'test'
		result = command.getClickObject()
		self.assertEquals(result, 'test')
Esempio n. 6
0
	def test_it_returns_the_correct_name(self):
		data = {'to': 'foo', 'hop': 'test hopping groups'}
		command = Command(data)
		result = command.getName()
		self.assertEquals(result, 'groups')
Esempio n. 7
0
	def test_it_returns_None_with_no_name_set(self):
		data = {'to': 'foo', 'hop': None}
		command = Command(data)
		result = command.getName()
		self.assertEquals(result, None)
Esempio n. 8
0
	def test_it_returns_the_correct_group_array(self):
		data = {'to': 'foo', 'hop': 'test hopping groups'}
		command = Command(data)
		result = command.getGroups()
		self.assertEquals(result, ['test', 'hopping'])
Esempio n. 9
0
	def test_it_returns_empty_an_array_when_groups_not_set(self):
		data = {'to': 'foo', 'hop': None}
		command = Command(data)
		result = command.getGroups()
		self.assertEquals(result, [])
Esempio n. 10
0
	def test_isValid_fails_when_to_data_None(self):
		data = {'to': None, 'hop': 'bar'}
		command = Command(data)
		self.assertFalse(command.isValid())
Esempio n. 11
0
	def test_isValid_fails_when_hop_data_None(self):
		data = {'to': 'foo', 'hop': None}
		command = Command(data)
		self.assertFalse(command.isValid())
Esempio n. 12
0
	def test_isValid_passes(self):
		data = {'to': 'foo', 'hop': 'bar'}
		command = Command(data)
		self.assertTrue(command.isValid())