class ListResourceTest(unittest.TestCase): def setUp(self): self.r = ListResource(base_uri, auth) def testListResourceInit(self): uri = "%s/%s" % (base_uri, self.r.name) self.assertEquals(self.r.uri, uri) def testKeyValue(self): self.assertEquals(self.r.key, self.r.name.lower()) def testIterNoKey(self): self.r.request = Mock() self.r.request.return_value = Mock(), {} with self.assertRaises(StopIteration): advance_iterator(self.r.iter()) def testRequest(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]} advance_iterator(self.r.iter()) self.r.request.assert_called_with("GET", "https://api.twilio.com/2010-04-01/Resources", params={}) def testIterOneItem(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]} items = self.r.iter() advance_iterator(items) with self.assertRaises(StopIteration): advance_iterator(items) def testIterNoNextPage(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: []} with self.assertRaises(StopIteration): advance_iterator(self.r.iter()) def testKeyValue(self): self.r.key = "Hey" self.assertEquals(self.r.key, "Hey") def testInstanceLoading(self): instance = self.r.load_instance({"sid": "foo"}) self.assertIsInstance(instance, InstanceResource) self.assertEquals(instance.sid, "foo") def testInstanceLoading(self): instance = self.r.load_instance({"sid": "foo"}) self.assertIsInstance(instance, InstanceResource) self.assertEquals(instance.sid, "foo")
class ListResourceTest(unittest.TestCase): def setUp(self): self.r = ListResource(base_uri, auth) def testListResourceInit(self): uri = "%s/%s" % (base_uri, self.r.name) self.assertEquals(self.r.uri, uri) def testKeyValue(self): self.assertEquals(self.r.key, self.r.name.lower()) def testIterNoKey(self): self.r.request = Mock() self.r.request.return_value = Mock(), {} with self.assertRaises(StopIteration): self.r.iter().next() def testRequest(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]} self.r.iter().next() self.r.request.assert_called_with( "GET", "https://api.twilio.com/2010-04-01/Resources", params={}) def testIterOneItem(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]} items = self.r.iter() items.next() with self.assertRaises(StopIteration): items.next() def testIterNoNextPage(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: []} with self.assertRaises(StopIteration): self.r.iter().next() def testKeyValue(self): self.r.key = "Hey" self.assertEquals(self.r.key, "Hey") def testInstanceLoading(self): instance = self.r.load_instance({"sid": "foo"}) self.assertIsInstance(instance, InstanceResource) self.assertEquals(instance.sid, "foo") def testInstanceLoading(self): instance = self.r.load_instance({"sid": "foo"}) self.assertIsInstance(instance, InstanceResource) self.assertEquals(instance.sid, "foo")
class ListResourceTest(unittest.TestCase): def setUp(self): self.r = ListResource(base_uri, auth) def testListResourceInit(self): uri = "{}/{}".format(base_uri, self.r.name) self.assertEquals(self.r.uri, uri) def testKeyValue(self): self.assertEquals(self.r.key, self.r.name.lower()) def testKeyValue(self): self.r.key = "Hey" self.assertEquals(self.r.key, "Hey") def testInstanceLoading(self): instance = self.r.load_instance({"sid": "foo"}) self.assertIsInstance(instance, InstanceResource) self.assertEquals(instance.sid, "foo")
class ListResourceTest(unittest.TestCase): def setUp(self): self.r = ListResource(base_uri, auth) def testListResourceInit(self): uri = "%s/%s" % (base_uri, self.r.name) assert_equal(self.r.uri, uri) def testKeyValueLower(self): assert_equal(self.r.key, self.r.name.lower()) def testIterNoKey(self): self.r.request = Mock() self.r.request.return_value = Mock(), {} self.assertRaises(StopIteration, advance_iterator, self.r.iter()) def testRequest(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]} advance_iterator(self.r.iter()) self.r.request.assert_called_with( "GET", "https://api.twilio.com/2010-04-01/Resources", params={}) def testIterOneItem(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]} items = self.r.iter() advance_iterator(items) self.assertRaises(StopIteration, advance_iterator, items) def testIterNoNextPage(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: []} self.assertRaises(StopIteration, advance_iterator, self.r.iter()) def testKeyValue(self): self.r.key = "Hey" assert_equal(self.r.key, "Hey") def testInstanceLoading(self): instance = self.r.load_instance({"sid": "foo"}) assert_true(isinstance(instance, InstanceResource)) assert_equal(instance.sid, "foo") def testListResourceCreateResponse200(self): """We should accept 200 OK in response to a POST creating a resource.""" self.r.request = Mock() return_value = Mock() return_value.status_code = 200 self.r.request.return_value = return_value, {'sid': 'foo'} self.r.create_instance({}) self.r.request.assert_called_with( "POST", "https://api.twilio.com/2010-04-01/Resources", data={}) def testListResourceCreateResponse201(self): """We should accept 201 Created in response to a POST creating a resource.""" self.r.request = Mock() return_value = Mock() return_value.status_code = 201 self.r.request.return_value = return_value, {'sid': 'foo'} self.r.create_instance({}) self.r.request.assert_called_with( "POST", "https://api.twilio.com/2010-04-01/Resources", data={})
def test_equivalence(): p = ListResource(base_uri, auth) r1 = p.load_instance({"sid": "AC123"}) r2 = p.load_instance({"sid": "AC123"}) assert_equal(r1, r2)
class ListResourceTest(unittest.TestCase): def setUp(self): self.r = ListResource(base_uri, auth) def testListResourceInit(self): uri = "%s/%s" % (base_uri, self.r.name) assert_equal(self.r.uri, uri) def testKeyValueLower(self): assert_equal(self.r.key, self.r.name.lower()) def testIterNoKey(self): self.r.request = Mock() self.r.request.return_value = Mock(), {} self.assertRaises(StopIteration, advance_iterator, self.r.iter()) def testRequest(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]} advance_iterator(self.r.iter()) self.r.request.assert_called_with("GET", "https://api.twilio.com/2010-04-01/Resources", params={}) def testIterOneItem(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: [{'sid': 'foo'}]} items = self.r.iter() advance_iterator(items) self.assertRaises(StopIteration, advance_iterator, items) def testIterNoNextPage(self): self.r.request = Mock() self.r.request.return_value = Mock(), {self.r.key: []} self.assertRaises(StopIteration, advance_iterator, self.r.iter()) def testKeyValue(self): self.r.key = "Hey" assert_equal(self.r.key, "Hey") def testInstanceLoading(self): instance = self.r.load_instance({"sid": "foo"}) assert_true(isinstance(instance, InstanceResource)) assert_equal(instance.sid, "foo") def testListResourceCreateResponse200(self): """We should accept 200 OK in response to a POST creating a resource.""" self.r.request = Mock() return_value = Mock() return_value.status_code = 200 self.r.request.return_value = return_value, {'sid': 'foo'} self.r.create_instance({}) self.r.request.assert_called_with("POST", "https://api.twilio.com/2010-04-01/Resources", data={}) def testListResourceCreateResponse201(self): """We should accept 201 Created in response to a POST creating a resource.""" self.r.request = Mock() return_value = Mock() return_value.status_code = 201 self.r.request.return_value = return_value, {'sid': 'foo'} self.r.create_instance({}) self.r.request.assert_called_with("POST", "https://api.twilio.com/2010-04-01/Resources", data={})