def test_individual_with_multiple_documents(self):
        self.page.double_click_marker()
        self.page.save()

        DeviceIndividual.detach(self.D.id, self.I.id, '2000-12-12T12:10:00+00:00')

        dev_2 = {
            "deviceManufacturerID": "DummyDevId2",
            "deviceType": "Type2",
            "deviceManufacturer": "Manufacturer2",
            "dateCreated": "2000-09-29T14:00:00+03:00",
            "dateEdited": "2000-09-29T14:00:00+03:00"
        }
        self.D_2 = device.create(**dev_2)

        DeviceIndividual.attach(self.D_2.id, self.I.id, '2000-12-12T12:15:00+00:00')

        self.A_2 = document.create(
            [gathering.Gathering("2000-12-12T12:20:00+00:00", [25.00, 63.00]),
             gathering.Gathering("2000-12-12T12:25:00+00:00", [25.01, 63.01])],
            self.D_2.id)

        self.page.navigate()
        self.page.change_individual_selection(self.I.id)
        self.assertEquals(1, self.page.number_of_private_clusters_on_map())
        self.assertEquals(1, self.page.number_of_completely_public_clusters_on_map())
        
        self.page.click_private_cluster()
        self.page.save_and_change('None')
        self.page.change_individual_selection(self.I.id)

        self.assertEquals(0, self.page.number_of_private_clusters_on_map())
        self.assertEquals(2, self.page.number_of_completely_public_clusters_on_map())
    def testGetAllAttachedIndividuals(self):
        self.assertEquals(0, len(DeviceIndividual.find()))

        DeviceIndividual.attach(self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")
        DeviceIndividual.detach(self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")
        DeviceIndividual.attach(self.D.id, self.I2.id, "2015-09-29T14:00:00+03:00")

        self.assertEquals(2, len(DeviceIndividual.get_attachments_of_device(self.D.id)))
        self.assertEquals(self.I2.id, DeviceIndividual.get_active_attachment_of_device(self.D.id)["individualID"])
 def testAttachOne(self):
     self.assertEquals(0, len(DeviceIndividual.find()))
     DeviceIndividual.attach(self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")
     self.assertEquals(1, len(DeviceIndividual.find()))
     self.assertEquals(self.I.id, DeviceIndividual.get_active_attachment_of_device(self.D.id)["individualID"])
     self.assertEquals(self.I.id, DeviceIndividual.get_active_attachment_of_device(self.D.id)["individualID"])
     self.assertEquals("2015-09-29T14:00:00+03:00", DeviceIndividual.get_active_attachment_of_individual(self.I.id)["attached"])
     self.assertEquals("2015-09-29T14:00:00+03:00", DeviceIndividual.get_active_attachment_of_individual(self.I.id)["attached"])
 def testAttachTwiceDoesNotAttachAgain(self):
     self.assertEquals(0, len(DeviceIndividual.find()))
     DeviceIndividual.attach(    self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")
     self.assertEquals(1, len(DeviceIndividual.find()))
     with self.assertRaises(AlreadyHasDevice):
         DeviceIndividual.attach(self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")
     self.assertEquals(1, len(DeviceIndividual.find()))
Пример #5
0
 def get_attached_individualid(self):
     '''
     Return currently attached individuals id or None for not currently attached
     :return: ID or None
     '''
     attachment = DeviceIndividual.get_active_attachment_of_device(self.id)
     if attachment is None:
         return None
     return attachment['individualID']
    def setUp(self):
        DeviceIndividual.delete_all()
        self.D = device.create(**{
            "deviceManufacturerID": "ABCD1234567",
            "deviceType": "Type",
            "deviceManufacturer": "Manufacturer",
            "dateCreated": "2015-09-29T14:00:00+03:00",
            "dateEdited": "2015-09-29T14:00:00+03:00"
        })
        self.D2 = device.create(**{
            "deviceManufacturerID": "ABCD1234568",
            "deviceType": "Type",
            "deviceManufacturer": "Manufacturer",
            "dateCreated": "2015-09-29T14:00:00+03:00",
            "dateEdited": "2015-09-29T14:00:00+03:00"
        })

        self.I = individual.create("Lintu1", "test")
        self.I2 = individual.create("Lintu2", "test")
    def setUp(self):
        dev = {
            "deviceManufacturerID": "DummyDevId",
            "deviceType": "Type",
            "deviceManufacturer": "Manufacturer",
            "dateCreated": "2015-09-29T14:00:00+03:00",
            "dateEdited": "2015-09-29T14:00:00+03:00"
        }
        self.D = device.create(**dev)
        self.A = document.create(
            [gathering.Gathering("2000-12-12T12:00:00+00:00", [23.00, 61.00]),
             gathering.Gathering("2000-12-12T12:05:00+00:00", [23.01, 61.01])],
            self.D.id)
        self.page = ChoosePage()

        self.I = individual.create('Tipuliini', 'dummytaxon')
        DeviceIndividual.attach(self.D.id, self.I.id, '2000-12-12T11:55:00+00:00')

        self.page.navigate()
        self.page.change_individual_selection(self.I.id)  
    def test_2birds1doc(self):
        self.add_individual()
        DeviceIndividual.detach(self.D.id, self.I.id,   "2000-12-12T12:15:00+00:00")
        DeviceIndividual.attach(self.D.id, self.I_2.id, "2000-12-12T12:20:00+00:00")
        self.A.gatherings += [
            gathering.Gathering("2000-12-12T12:25:00+00:00", [24.00, 62.00]),
            gathering.Gathering("2000-12-12T12:30:00+00:00", [24.01, 62.01])]
        self.A.update()
        self.page.navigate()
        self.page.change_individual_selection(self.I.id)

        self.assertEquals(1, self.page.number_of_private_clusters_on_map())
        self.page.change_individual_selection(self.I_2.id)
        self.assertEquals(1, self.page.number_of_private_clusters_on_map())
        self.assertEquals(0, self.page.number_of_completely_public_clusters_on_map())
        self.page.double_click_marker()
        self.assertEquals(0, self.page.number_of_private_clusters_on_map())
        self.assertEquals(1, self.page.number_of_completely_public_clusters_on_map())
        self.page.save_and_change(self.I.id)

        self.assertEquals(1, self.page.number_of_private_clusters_on_map())
        self.page.change_individual_selection(self.I_2.id)
        self.assertEquals(0, self.page.number_of_private_clusters_on_map())
        self.assertEquals(1, self.page.number_of_completely_public_clusters_on_map())
Пример #9
0
    def get_all_gatherings(self, extras_originatingDevice=False):
        attachments = DeviceIndividual.get_attachments_of_individual(self.id)

        gatherings = []
        for a in attachments:
            timerange = (a["attached"], a["removed"])
            doc = document.find(deviceID=a["deviceID"])[0]
            relevant_gatherings = list(self._filter_gatherings_by_timerange(
                doc.gatherings, timerange))
            for rg in relevant_gatherings:
                if extras_originatingDevice:
                    rg.extras['originatingDevice'] = a['deviceID']
                gatherings.append(rg)

        return gatherings
Пример #10
0
    def test_removes(self):
        self.A.attach_to(self.indiv.id, "2015-10-10T10:10:10+00:00" )
        attID = DeviceIndividual.get_active_attachment_of_device(self.A.id)['id']

        # https://github.com/jgorset/django-respite/issues/38
        response = self.c.put(
            path=_URL + "attachments/" + attID, 
            data=urlencode({
                "id": attID,
                "individualID" : self.indiv.id,
                "deviceID" : self.A.id,
                "attached" : "2015-10-10T10:10:10+00:00",
                "removed" :  "2015-10-10T10:10:11+00:00"
            }), 
            content_type='application/x-www-form-urlencoded')

        self.assertEquals(None, self.A.get_attached_individualid())
Пример #11
0
    def set_gatherings(self, new_gatherings):
        # new_gatherings is parsed json (a list of dicts), not a list of Gathering objects

        totime = _timestamp_to_datetime
        atts = DeviceIndividual.get_attachments_of_individual(self.id)

        for a in atts:
            start = totime(a['attached'])
            end = totime(a['removed']) if ('removed' in a and a['removed']) else timezone.now()

            doc = document.find(deviceID=a['deviceID'])[0]

            # list of dicts
            relevant_new = [g for g in new_gatherings if 
                    (start <= totime(g['dateBegin']) <= end) and
                    g['extras']['originatingDevice'] == a['deviceID']]

            # list of Gathering objects
            relevant_old = [g for g in doc.gatherings if
                    (start <= totime(g.dateBegin) <= end)]

            # nothing to update?
            if (not relevant_new) and (not relevant_old):
                continue

            if len(relevant_new) != len(relevant_old):
                logger.warn('number of old gatherings different from number of new gatherings in choose/setIndividualGatherings. old: %d, new: %d' % 
                    (len(relevant_new), len(relevant_old)))

            # remove old gatherings
            for g in relevant_old:
                try:
                    doc.gatherings.remove(g)
                except ValueError:
                    pass

            # insert new gatherings
            doc.gatherings += [
                gathering.from_lajistore_json(**g) for g in relevant_new]

            doc.update()
 def testAttachToAnotherIndividualDoesNotAttach(self):
     DeviceIndividual.attach(    self.D.id, self.I.id,  "2015-09-29T14:00:00+03:00")
     self.assertEquals(1, len(DeviceIndividual.find()))
     with self.assertRaises(DeviceAlreadyAttached):
         DeviceIndividual.attach(self.D.id, self.I2.id, "2015-09-29T14:00:00+03:00")
     self.assertEquals(1, len(DeviceIndividual.find()))
Пример #13
0
 def attach_to(self, individualid, timestamp):
     '''
     Attaches this device to an individual
     '''
     DeviceIndividual.attach(self.id, individualid, timestamp)
Пример #14
0
 def detach_from(self, individualid, timestamp):
     '''
     Removes this device from an individual
     '''
     DeviceIndividual.detach(self.id, individualid, timestamp)
Пример #15
0
 def get_attachments(self):
     return DeviceIndividual.get_attachments_of_device(self.id)
 def testDeleteAllWorks(self):
     DeviceIndividual.attach(self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")
     self.assertEquals(1, len(DeviceIndividual.find()))
     DeviceIndividual.delete_all()
     self.assertEquals(0, len(DeviceIndividual.find()))
 def testNoAttachments(self):
     self.assertEquals(0, len(DeviceIndividual.find()))
 def testDeletedDevicesDontMessThingsUp(self):
     DeviceIndividual.attach(self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")
     self.D.delete()
     self.assertEquals(0, len(DeviceIndividual.find()))
 def tearDown(self):
     self.D.delete()
     self.D2.delete()
     self.I.delete()
     self.I2.delete()
     DeviceIndividual.delete_all()
Пример #20
0
 def clear_db(self):
     document.delete_all()
     device.delete_all()
     individual.delete_all()
     DeviceIndividual.delete_all()
     news.delete_all()
    def testAttachDetachTwo(self):
        self.assertEquals(0, len(DeviceIndividual.find()))

        DeviceIndividual.attach(self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")
        DeviceIndividual.attach(self.D2.id, self.I2.id, "2015-09-29T14:00:00+03:00")

        self.assertEquals(2, len(DeviceIndividual.find()))
        self.assertEquals(self.I.id, DeviceIndividual.get_active_attachment_of_device(self.D.id)["individualID"])
        self.assertEquals(self.D.id, DeviceIndividual.get_active_attachment_of_individual(self.I.id)["deviceID"])
        self.assertEquals(self.I2.id, DeviceIndividual.get_active_attachment_of_device(self.D2.id)["individualID"])
        self.assertEquals(self.D2.id, DeviceIndividual.get_active_attachment_of_individual(self.I2.id)["deviceID"])

        DeviceIndividual.detach(self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")

        self.assertEquals(None, DeviceIndividual.get_active_attachment_of_device(self.D.id))
        self.assertEquals(None, DeviceIndividual.get_active_attachment_of_individual(self.I.id))
        self.assertEquals(self.I2.id, DeviceIndividual.get_active_attachment_of_device(self.D2.id)["individualID"])
        self.assertEquals(self.D2.id, DeviceIndividual.get_active_attachment_of_individual(self.I2.id)["deviceID"])

        DeviceIndividual.detach(self.D2.id, self.I2.id, "2015-09-29T14:00:00+03:00")

        self.assertEquals(None, DeviceIndividual.get_active_attachment_of_device(self.D2.id))
        self.assertEquals(None, DeviceIndividual.get_active_attachment_of_individual(self.I2.id))
        self.assertEquals(2, len(DeviceIndividual.find()))
 def testDeletedIndividualsDontStopNewAttachments(self):
     DeviceIndividual.attach(self.D.id, self.I.id, "2015-09-29T14:00:00+03:00")
     self.I.delete();
     DeviceIndividual.attach(self.D.id, self.I2.id, "2015-09-29T14:00:00+03:00")
     self.assertEquals(self.I2.id, DeviceIndividual.get_active_attachment_of_device(self.D.id)['individualID'])
Пример #23
0
 def tearDown(self):
     DeviceIndividual.delete_all()