def test_no_optional_fields(self): """ Test that options are an empty dict and args are full when optional fields are not set. """ fake_search = search.SearchView() search_params, options = fake_search._parse_args({'non-optional': 'field'}) self.assertEqual(search_params, {'non-optional': 'field'}) self.assertEqual(options, {})
def test_get_with_invalid_filters(self, mock_parse): """ InvalidValue should be raised if param 'filters' is not json. """ mock_parse.return_value = ({'mock': 'query'}, 'tuple') search_view = search.SearchView() mock_request = mock.MagicMock() mock_request.GET = http.QueryDict('filters=invalid json') self.assertRaises(exceptions.InvalidValue, search_view.get, mock_request)
def test_post_missing_criteria(self): """ Test that POST search when the user has not passed the required criteria. """ request = mock.MagicMock() # Simulate an empty POST body request.body = "{}" view = search.SearchView() try: view.post(request) self.fail('A MissingValue Exception should have been raised.') except exceptions.MissingValue, e: self.assertEqual(e.property_names, ['criteria'])