def test_get(self): new_query = MagicMock(spec=ResolweQuery) query = MagicMock(spec=ResolweQuery, **{'_clone.return_value': new_query}) with self.assertRaises(ValueError): ResolweQuery.get(query, 1, 'slug') with self.assertRaises(ValueError): ResolweQuery.get(query, 1, name='Object name') new_query.__iter__.return_value = ['object'] result = ResolweQuery.get(query, 1) self.assertEqual(result, 'object') new_query.__iter__.return_value = [] with self.assertRaises(LookupError): ResolweQuery.get(query, 1) new_query.__iter__.return_value = ['object 1', 'object 2'] with self.assertRaises(LookupError): ResolweQuery.get(query, 1)
def test_get(self): new_query = MagicMock(spec=ResolweQuery) query = MagicMock(spec=ResolweQuery, **{"_clone.return_value": new_query}) with self.assertRaises(ValueError): ResolweQuery.get(query, 1, "slug") with self.assertRaises(ValueError): ResolweQuery.get(query, 1, name="Object name") new_query.__iter__.return_value = ["object"] result = ResolweQuery.get(query, 1) self.assertEqual(result, "object") new_query.__iter__.return_value = [] with self.assertRaises(LookupError): ResolweQuery.get(query, 1) new_query.__iter__.return_value = ["object 1", "object 2"] with self.assertRaises(LookupError): ResolweQuery.get(query, 1)