Example #1
0
 def test_update_account(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('account/account'),
                  headers={'Content-type': 'application/json'}):
         account = vivialconnect.Account.find(6242736)
     with HTTMock(self.response_content,
                  body=self.load_fixture('account/account'),
                  headers={'Content-type': 'application/json'}):
         account.save()
 def test_update_message(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('message/message'),
                  headers={'Content-type': 'application/json'}):
         message = vivialconnect.Message.find(6242736)
     with HTTMock(self.response_content,
                  body=self.load_fixture('message/message'),
                  headers={'Content-type': 'application/json'}):
         message.save()
 def test_get_attachments(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('message/message'),
                  headers={'Content-type': 'application/json'}):
         message = vivialconnect.Message.find(6242736)
     with HTTMock(self.response_content,
                  body=self.load_fixture('message/attachments'),
                  headers={'Content-type': 'application/json'}):
         attachments = message.attachments()
     self.assertEqual(2, len(attachments))
    def test_get_attachment(self):
        with HTTMock(self.response_content,
                     body=self.load_fixture('message/message'),
                     headers={'Content-type': 'application/json'}):
            message = vivialconnect.Message.find(6242736)

        with HTTMock(self.response_content,
                     body=self.load_fixture('message/attachment'),
                     headers={'Content-type': 'application/json'}):
            attachment = message.attachment(6242737)

        self.assertEqual("image/gif", attachment.content_type)
        self.assertEqual(1024, attachment.size)
        self.assertEqual("what.gif", attachment.file_name)
        self.assertEqual("abcdee", attachment.key_name)
        self.assertEqual(6242737, attachment.message_id)
 def test_create_message(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('message/message'),
                  headers={'Content-type': 'application/json'}):
         message = vivialconnect.Message({'id': 6242736})
         message.save()
     self.assertEqual("This is message", message.body)
    def test_modifications(self):
        fixture = self.load_fixture('connector/connectors')
        fixture_data = json.loads(fixture.decode())
        p1_numbers = self.get_path(fixture_data, 'connectors.0.phone_numbers')
        p2_numbers = self.get_path(fixture_data, 'connectors.1.phone_numbers')
        with HTTMock(self.response_content,
                     body=fixture,
                     headers={'Content-type': 'application/json'}):
            connectors = vivialconnect.Connector.find()
            self.assertEqual(len(connectors), 2)
            c1 = connectors[0]
            c2 = connectors[1]

        self.assertSequenceEqual([p.attributes for p in c1.phone_numbers],
                                 p1_numbers)
        self.assertSequenceEqual([p.attributes for p in c2.phone_numbers],
                                 p2_numbers)

        num = c1.phone_numbers[0]
        del c1.phone_numbers[0]
        del c2.phone_numbers[1]
        self.assertSequenceEqual([p.attributes for p in c1.phone_numbers],
                                 p1_numbers[1:])
        self.assertSequenceEqual([p.attributes for p in c2.phone_numbers],
                                 p2_numbers[:1])
        c1.name = "Some Other name"
        c2.name = "Another different name"
        c1.phone_numbers.insert(0, num)
        self.assertSequenceEqual([p.attributes for p in c1.phone_numbers],
                                 p1_numbers)
        self.assertSequenceEqual([p.attributes for p in c2.phone_numbers],
                                 p2_numbers[:1])
 def test_get_aggregated_logs_with_log_type(self):
     with HTTMock(
             self.response_content,
             body=self.load_fixture("log/log_aggregated_log_type"),
             headers={"Conent-type": "application/json"},
     ):
         params = {
             "start_time": "20181101T145548Z",
             "end_time": "20181205T155548Z",
             "optional_query_parameters": {
                 "log_type": "user.login"
             },
         }
         logs = vivialconnect.Log.get_aggregated_logs(**params)
     self.assertIn("log_items", logs)
     self.assertIn("last_key", logs)
     log_item = logs["log_items"][0]
     # Check log item structure
     self.assertIn("account_id", log_item)
     self.assertIn("account_id_log_type", log_item)
     self.assertIn("log_timestamp", log_item)
     self.assertIn("aggregate_key", log_item)
     self.assertIn("log_count", log_item)
     self.assertIn("log_type", log_item)
     # Check content
     self.assertTrue("4", log_item["account_id"])
     self.assertTrue("4-user.login", log_item["account_id_log_type"])
     self.assertTrue("minutes", log_item["aggregate_key"])
     self.assertTrue(201811281404, log_item["log_timestamp"])
     self.assertTrue("user.login", log_item["log_type"])
     # Check the amount of items
     self.assertEqual(len(logs["log_items"]), 2)
 def test_resurrection(self):
     fixture = self.load_fixture('connector/connector_with_phone_number')
     phone_data = self.get_path(json.loads(fixture.decode()),
                                'connector.phone_numbers.0')
     with HTTMock(self.response_content,
                  body=fixture,
                  headers={'Content-type': 'application/json'}):
         connector = vivialconnect.Connector.find(424242)
     connector.phone_numbers.append(phone_data)
     connector.name = 'Some other name'
     connector.phone_numbers.append(phone_data)
     self.assertEqual(3, len(connector.phone_numbers))
     with HTTMock(self.response_content,
                  body=fixture,
                  headers={'Content-type': 'application/json'}):
         connector = vivialconnect.Connector.find(424242)
     self.assertEqual(1, len(connector.phone_numbers))
 def test_get_connector(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture("connector/connector"),
                  headers={'Content-type': 'application/json'}):
         connector = vivialconnect.Connector.find(424242)
     self.assertEqual(424242, connector.id)
     self.assertEqual(True, connector.active)
     self.assertEqual("TestConnector", connector.name)
 def test_create_attachment(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('message/attachment'),
                  headers={'Content-type': 'application/json'}):
         attachment = vivialconnect.Attachment(6242737)
         attachment.size = 1024
         attachment.content_type = 'image/gif'
         attachment.file_name = 'what.gif'
         attachment.key_name = 'abcdee'
         attachment.save()
 def test_create_connector(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('connector/connector'),
                  headers={'Content-type': 'application/json'}):
         connector = vivialconnect.Connector({
             'id': 424242,
             'name': 'TestConnector'
         })
         connector.save()
     self.assertEqual(424242, connector.id)
     self.assertEqual("TestConnector", connector.name)
 def test_parse_callback(self):
     fixture = self.load_fixture('connector/connector_with_callback')
     cb_data = self.get_path(json.loads(fixture), 'connector.callbacks.0')
     with HTTMock(self.response_content,
                  body=fixture,
                  headers={'Content-type': 'application/json'}):
         connector = vivialconnect.Connector.find(424242)
     self.assertEqual(1, len(connector.callbacks))
     self.assertIsInstance(connector.callbacks[0],
                           vivialconnect.ConnectorCallback)
     self.validate_with_dict(connector.callbacks[0], cb_data)
 def test_parse_phone_number(self):
     fixture = self.load_fixture('connector/connector_with_phone_number')
     phone_data = self.get_path(json.loads(fixture.decode()),
                                'connector.phone_numbers.0')
     with HTTMock(self.response_content,
                  body=fixture,
                  headers={'Content-type': 'application/json'}):
         connector = vivialconnect.Connector.find(424242)
     self.assertEqual(1, len(connector.phone_numbers))
     self.assertIsInstance(connector.phone_numbers[0],
                           vivialconnect.ConnectorNumber)
     self.validate_with_dict(connector.phone_numbers[0], phone_data)
    def test_get_message(self):
        with HTTMock(self.response_content,
                     body=self.load_fixture('message/message'),
                     headers={'Content-type': 'application/json'}):
            message = vivialconnect.Message.find(6242736)

        self.assertEqual("This is message", message.body)
        self.assertEqual("received", message.status)
        self.assertEqual("inbound", message.direction)
        self.assertEqual("+12223334444", message.from_number)
        self.assertEqual("+12223335555", message.to_number)
        self.assertEqual(0, message.num_media)
Example #15
0
 def test_get_logs(self):
     with HTTMock(
             self.response_content,
             body=self.load_fixture("log/log"),
             headers={"Conent-type": "application/json"},
     ):
         params = {
             "start_time": "20181101T145548Z",
             "end_time": "20181205T155548Z"
         }
         logs = vivialconnect.Log.get(**params)
     self.assertIn("log_items", logs)
     self.assertIn("last_key", logs)
     # Check the amount of items
     self.assertEqual(len(logs["log_items"]), 16)
Example #16
0
 def test_get_aggregated_logs(self):
     with HTTMock(
             self.response_content,
             body=self.load_fixture("log/log_aggregated"),
             headers={"Conent-type": "application/json"},
     ):
         params = {
             "start_time": "20181101T145548Z",
             "end_time": "20181205T155548Z"
         }
         logs = vivialconnect.Log.get_aggregated_logs(**params)
     self.assertIn("log_items", logs)
     self.assertIn("last_key", logs)
     # Check for keys in an log item
     log_item = logs["log_items"][0]
     self.assertIn("account_id", log_item)
     self.assertIn("account_id_log_type", log_item)
     self.assertIn("log_timestamp", log_item)
     self.assertIn("aggregate_key", log_item)
     self.assertIn("log_count", log_item)
     self.assertIn("log_type", log_item)
     # Check the amount of items
     self.assertEqual(len(logs["log_items"]), 7)
Example #17
0
 def test_get_account(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('account/account'),
                  headers={'Content-type': 'application/json'}):
         account = vivialconnect.Account.find(6242736)
     self.assertEqual("Vivial Connect", account.company_name)
Example #18
0
 def test_count_accounts(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('account/count'),
                  headers={'Content-type': 'application/json'}):
         count = vivialconnect.Account.count()
     self.assertEqual(3, count)
Example #19
0
 def test_get_accounts(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('account/accounts'),
                  headers={'Content-type': 'application/json'}):
         accounts = vivialconnect.Account.find()
     self.assertEqual(3, len(accounts))
 def test_get_connectors(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('connector/connectors'),
                  headers={'Content-type': 'application/json'}):
         connectors = vivialconnect.Connector.find()
     self.assertEqual(2, len(connectors))
 def test_get_messages(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('message/messages'),
                  headers={'Content-type': 'application/json'}):
         messages = vivialconnect.Message.find()
     self.assertEqual(2, len(messages))
 def test_count_messages(self):
     with HTTMock(self.response_content,
                  body=self.load_fixture('message/count'),
                  headers={'Content-type': 'application/json'}):
         count = vivialconnect.Message.count()
     self.assertEqual(2, count)