def test_simple(self, mock_send_data): mock_send_data.return_value = {'id': 1, 'name': 'asdf'} queryset = RestQuerySet(model=RestTestQueryModel) new_instance = queryset.create(id=1, name="Test") self.assertEqual(new_instance.id, mock_send_data.return_value['id']) self.assertEqual(new_instance.name, mock_send_data.return_value['name'])
def test_creation_from_instance(self, mock_send_data): name = 'test' mock_send_data.return_value = {'id': 1, 'name': name} instance = RestTestQueryModel(name=name) queryset = RestQuerySet(model=RestTestQueryModel) new_instance = queryset.create(instance) mock_send_data.assert_called_with('POST', {'id': None, 'name': name}) self.assertEqual(new_instance.id, mock_send_data.return_value['id']) self.assertEqual(new_instance.name, mock_send_data.return_value['name'])
def test_invalid_return(self, mock_send_data): mock_send_data.return_value = {'name': 'asdf'} queryset = RestQuerySet(model=RestTestQueryModel) with self.assertRaises(APIException): queryset.create(id=1, name="Test")