예제 #1
0
 def setUp(self):
     self.resource = Messages("uri", ("username", "token"))
예제 #2
0
 def setUp(self):
     self.resource = Messages("uri", ("username", "token"))
예제 #3
0
class TestMessage(unittest.TestCase):
    def setUp(self):
        self.resource = Messages("uri", ("username", "token"))

    def test_list(self):
        with patch.object(self.resource, "get_instances") as mock:
            self.resource.list(limit=50, page=3)
            mock.assert_called_with({
                "limit": 50,
                "page": 3,
                "search": False,
            })

    def test_list_search(self):
        with patch.object(self.resource, "get_instances") as mock:
            self.resource.list(limit=10, page=3, search=True, sessionId=123)
            mock.assert_called_with({
                "limit": 10,
                "page": 3,
                "search": True,
                "sessionId": 123
            })

    def test_create(self):
        with patch.object(self.resource, "create_instance") as mock:
            self.resource.create(text="mock text",
                                 contacts="888, 999",
                                 sendingTime=12345)
            mock.assert_called_with({
                "text": "mock text",
                "contacts": "888, 999",
                "sendingTime": 12345
            })

    def test_create_from(self):
        with patch.object(self.resource, "create_instance") as mock:
            self.resource.create(
                text="mock",
                phones="999123, 999999",
                from_="SENDER_ID",
            )
            mock.assert_called_with({
                "text": "mock",
                "phones": "999123, 999999",
                "from": "SENDER_ID",
            })

    def test_create_dummy(self):
        with patch.object(self.resource, "request") as mock:
            json_price = '{"total":1, "price":0}'
            mock.return_value = (Mock(), json_price)

            result = self.resource.create(text="mock",
                                          phones="999999",
                                          dummy=1)

            mock.assert_called_with("POST",
                                    self.resource.uri,
                                    data={
                                        "text": "mock",
                                        "dummy": 1,
                                        "phones": "999999",
                                    })
            assert result == json_price

    def test_price(self):
        with patch.object(self.resource, "request") as mock:
            json_price = '{"total":1, "price":0}'
            mock.return_value = (Mock(), json_price)

            result = self.resource.price(text="mock",
                                         phones="999999",
                                         from_="5550000")

            mock.assert_called_with("GET",
                                    "%s/%s" % (self.resource.uri, "price"),
                                    params={
                                        "text": "mock",
                                        "from": "5550000",
                                        "phones": "999999",
                                    })
            assert result == json_price

    def test_delete(self):
        with patch.object(self.resource, "delete_instance") as mock:
            self.resource.delete(999)
            mock.assert_called_with(999)
예제 #4
0
class TestMessage(unittest.TestCase):

    def setUp(self):
        self.resource = Messages("uri", ("username", "token"))

    def test_list(self):
        with patch.object(self.resource, "get_instances") as mock:
            self.resource.list(
                limit=50,
                page=3
            )
            mock.assert_called_with({
                "limit": 50,
                "page": 3,
                "search": False,
            })

    def test_list_search(self):
        with patch.object(self.resource, "get_instances") as mock:
            self.resource.list(
                limit=10,
                page=3,
                search=True,
                sessionId=123
            )
            mock.assert_called_with({
                "limit": 10,
                "page": 3,
                "search": True,
                "sessionId": 123
            })

    def test_create(self):
        with patch.object(self.resource, "create_instance") as mock:
            self.resource.create(
                text="mock text",
                contacts="888, 999",
                sendingTime=12345
            )
            mock.assert_called_with({
                "text": "mock text",
                "contacts": "888, 999",
                "sendingTime": 12345
            })

    def test_create_from(self):
        with patch.object(self.resource, "create_instance") as mock:
            self.resource.create(
                text="mock",
                phones="999123, 999999",
                from_="SENDER_ID",
            )
            mock.assert_called_with({
                "text": "mock",
                "phones": "999123, 999999",
                "from": "SENDER_ID",
            })

    def test_create_dummy(self):
        with patch.object(self.resource, "request") as mock:
            json_price = '{"total":1, "price":0}'
            mock.return_value = (Mock(), json_price)

            result = self.resource.create(
                text="mock",
                phones="999999",
                dummy=1
            )

            mock.assert_called_with(
                "POST",
                self.resource.uri,
                data={
                    "text": "mock",
                    "dummy": 1,
                    "phones": "999999",
                }
            )
            assert result == json_price

    def test_price(self):
        with patch.object(self.resource, "request") as mock:
            json_price = '{"total":1, "price":0}'
            mock.return_value = (Mock(), json_price)

            result = self.resource.price(
                text="mock",
                phones="999999",
                from_="5550000"
            )

            mock.assert_called_with(
                "GET",
                "%s/%s" % (self.resource.uri, "price"),
                params={
                    "text": "mock",
                    "from": "5550000",
                    "phones": "999999",
                }
            )
            assert result == json_price

    def test_delete(self):
        with patch.object(self.resource, "delete_instance") as mock:
            self.resource.delete(999)
            mock.assert_called_with(999)