def test_model_data(self, base_mock): base_mock.configure_mock(endpoint='resource_endpoint') mdata = {'a': 1, 'b': 2} BaseResource.__init__(base_mock, model_data=mdata, resolwe=self.resolwe_mock) base_mock._update_fields.assert_called_once_with(mdata)
def test_slug_value_error(self, base_mock, getattr_mock): base_mock.configure_mock(endpoint="this_is_string") getattr_mock.return_value = MagicMock(**{'get.return_value': [123, 456]}) message = r"Slug '\w+' does not exist or you do not have access permission." with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, slug="a", resolwe=self.resolwe_mock) base_mock._update_fields.assert_not_called()
def test_slug_value_error(self, base_mock): base_mock.configure_mock(endpoint='resource_endpoint') message = r"Slug '\w+' does not exist or you do not have access permission." with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, slug="a", resolwe=self.resolwe_mock) base_mock._update_fields.assert_not_called()
def test_not_only_one_input(self, base_mock): message = "One and only one of slug, id or model_data must be given" with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, id=1, slug="a", resolwe=self.resolwe_mock) with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, id=1, model_data={'a': 1}, resolwe=self.resolwe_mock) with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, slug="a", model_data={'a': 1}, resolwe=self.resolwe_mock) with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, id=1, slug="a", model_data={'a': 1}, resolwe=self.resolwe_mock) with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, resolwe=self.resolwe_mock)
def test_slug_ok(self, base_mock): base_mock.configure_mock(endpoint='resource_endpoint') self.resolwe_mock.configure_mock(**{'api.resource_endpoint.get.return_value': [123]}) BaseResource.__init__(base_mock, slug="a", resolwe=self.resolwe_mock) base_mock._update_fields.assert_called_once_with(123) self.resolwe_mock.configure_mock( **{'api.resource_endpoint.get.return_value': [{'version': 1}, {'version': 2}]} ) BaseResource.__init__(base_mock, slug="a", resolwe=self.resolwe_mock) self.assertEqual(base_mock._update_fields.call_count, 2)
def test_not_only_one_input(self, base_mock): message = "Only one of slug, id or model_data allowed" with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, id=1, slug="a", resolwe=self.resolwe_mock) with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, id=1, model_data={'a': 1}, resolwe=self.resolwe_mock) with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, slug="a", model_data={'a': 1}, resolwe=self.resolwe_mock) with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, id=1, slug="a", model_data={'a': 1}, resolwe=self.resolwe_mock)
def test_wrong_type_input(self, base_mock): message = r"\w+ should be a\w? \w+." with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, id="bad_type_id", resolwe=self.resolwe_mock) with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, slug={'a': 1}, resolwe=self.resolwe_mock) with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, model_data="a", resolwe=self.resolwe_mock)
def test_init_all_ok(self, base_mock, getattr_mock, log_mock): BaseResource.__init__(base_mock, id=1, resolwe=self.resolwe_mock) self.assertEqual(log_mock.getLogger.call_count, 1)
def test_model_data(self, base_mock, getattr_mock): mdata = {'a': 1, 'b': 2} BaseResource.__init__(base_mock, model_data=mdata, resolwe=self.resolwe_mock) base_mock._update_fields.assert_called_once_with(mdata)
def test_slug_ok(self, base_mock, getattr_mock): base_mock.configure_mock(endpoint="this_is_string") getattr_mock.return_value = MagicMock(**{'get.return_value': [123]}) BaseResource.__init__(base_mock, slug="a", resolwe=self.resolwe_mock) base_mock._update_fields.assert_called_once_with(123)
def test_id_ok(self, base_mock, getattr_mock): BaseResource.__init__(base_mock, id=1, resolwe=self.resolwe_mock) self.assertEqual(base_mock._update_fields.call_count, 1)
def test_id_http_error(self, base_mock, getattr_mock): base_mock._update_fields.side_effect = slumber.exceptions.HttpNotFoundError message = r"ID '\d+' does not exist or you do not have access permission." with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, id=1, resolwe=self.resolwe_mock)
def test_id_ok(self, base_mock): base_mock.configure_mock(endpoint='resource_endpoint') BaseResource.__init__(base_mock, id=1, resolwe=self.resolwe_mock) self.assertEqual(base_mock._update_fields.call_count, 1)
def test_id_http_error(self, base_mock): base_mock.configure_mock(endpoint='resource_endpoint') base_mock._update_fields.side_effect = slumber.exceptions.HttpNotFoundError message = r"ID '\d+' does not exist or you do not have access permission." with six.assertRaisesRegex(self, ValueError, message): BaseResource.__init__(base_mock, id=1, resolwe=self.resolwe_mock)
def test_init_all_ok(self, base_mock, log_mock): base_mock.configure_mock(endpoint='resource_endpoint') BaseResource.__init__(base_mock, id=1, resolwe=self.resolwe_mock) self.assertEqual(log_mock.getLogger.call_count, 1)