Exemple #1
0
    def get_request(self):
        "return MessageRequest"

        mc = MessageChannels(name=super(MessageDbRequestTest, self).get_input_collapse_key())
        mc.id = self.collapse_key_id
        mc.save()

        for key, data in self.get_input_data().items():
            md = MessageData(data=data)
            if type(key) is int:
                md.id = key
            else:
                md.name = key
            md.save()
            mc.message.add(md)
        mc.save()

        mg = MessageGroups(name="test_all_db")
        mg.save()

        ad = AndroidDevice()
        ad.id = 1000
        ad.device_id = "test_send_message_db_01"
        ad.registration_id = self.get_input_registration_id()
        ad.save()

        dci = DeviceChannelInfo()
        dci.device = ad
        dci.channel = mc
        dci.save()

        return msg_db.MessageRequest(dci, self.get_input_delay_while_idle())
Exemple #2
0
    def get_message(self):
        self.collapse_key = "col_key"
        self.registration_id = "reg_id"
        self.data_in = {"key1": "data1", "key2": "data2"}
        self.delay_while_idle = False

        mc = MessageChannels(name=self.collapse_key)
        mc.id = 100
        mc.save()

        for key, data in self.data_in.items():
            md = MessageData(data=data)
            if type(key) is int:
                md.id = key
            else:
                md.name = key
            md.save()
            mc.message.add(md)
        mc.save()

        mg = MessageGroups(name="test_all_db")
        mg.save()

        ad = AndroidDevice()
        ad.id = 1000
        ad.device_id = "test_send_message_db_01"
        ad.registration_id = self.registration_id
        ad.save()

        dci = DeviceChannelInfo()
        dci.device = ad
        dci.channel = mc
        dci.save()

        self.dci_id = dci.id

        message_request = msg_db.MessageRequest(dci, self.delay_while_idle)
        message_response = msg_db.MessageResponse(dci)

        return message_request, message_response
Exemple #3
0
    def test_create_channel(self):
        # empty
        m = MessageChannels(name="empty")
        m.save()
        self.assertEqual(MessageChannels.objects.get(pk=m.pk).name, "empty")

        # duplicate
        with self.assertRaises(IntegrityError):
            m = MessageChannels(name="empty")
            m.save()

        connection._rollback()

        # some data
        some_data = MessageChannels(name="some_data")
        some_data.save()
        md = MessageData(data="aaa")
        md.save()
        some_data.message.add(md)
        md = MessageData(name="aaa", data="aaa2")
        md.save()
        some_data.message.add(md)
        some_data.save()
        self.assertEqual(len(MessageChannels.objects.get(pk=some_data.pk).message.all()), 2)
        self.assertEqual(MessageChannels.objects.get(pk=some_data.pk).name, "some_data")

        # too much data
        too_much_data = MessageChannels(name="too_much_data")
        too_much_data.save()
        try:
            for i in range(1, 1000):
                md = MessageData(data=("xy" * 5))
                md.save()
                too_much_data.message.add(md)
                too_much_data.full_clean()
                too_much_data.save()
            self.assertTrue(False, "Except ValidationError")  # pragma: no cover
        except ValidationError:
            self.assertTrue(True)

        #  change data
        change_data = MessageChannels(name="change_data")
        change_data.save()
        md = MessageData(data="aaa")
        md.save()
        pk_last_change = md.pk
        change_data.message.add(md)
        change_data.save()
        change_data = MessageChannels.objects.get(pk=change_data.pk)
        self.assertEqual(md.last_change, change_data.last_change)

        md = MessageData(data="bbb")  # add new
        md.save()
        change_data.message.add(md)
        change_data.save()
        change_data = MessageChannels.objects.get(pk=change_data.pk)
        self.assertEqual(md.last_change, change_data.last_change)

        md = MessageData.objects.get(pk=pk_last_change)
        md.data = "aaaAAA"
        md.save()
        self.assertEqual(md.last_change, change_data.last_change)

        # when missing change
        change_data = MessageChannels(name="change_data_missing")
        change_data.save()
        change_data = MessageChannels.objects.get(pk=change_data.pk)
        self.assertEqual(None, change_data.last_change)