def test_larger_lhs(self):
        """Ensure a missing lhs returns rhs."""
        from sosbeacon.utils import get_latest_datetime

        lhs = datetime(2012, 9, 20, 3, 45)
        rhs = datetime(2012, 9, 20, 2, 45)

        result = get_latest_datetime(lhs, rhs)

        self.assertIs(lhs, result)
    def test_equal_inputs(self):
        """Ensure a missing lhs returns rhs."""
        from sosbeacon.utils import get_latest_datetime

        lhs = rhs = datetime(2012, 9, 20, 2, 59)

        result = get_latest_datetime(lhs, rhs)

        self.assertIs(rhs, result)
        self.assertIs(lhs, result)
    def test_no_rhs(self):
        """Ensure a missing lhs returns rhs."""
        from sosbeacon.utils import get_latest_datetime

        lhs = object()
        rhs = None

        result = get_latest_datetime(lhs, rhs)

        self.assertIs(lhs, result)
    def test_equal_inputs(self):
        """Ensure a missing lhs returns rhs."""
        from sosbeacon.utils import get_latest_datetime

        lhs = rhs = datetime(2012, 9, 20, 2, 59)

        result = get_latest_datetime(lhs, rhs)

        self.assertIs(rhs, result)
        self.assertIs(lhs, result)
    def test_larger_lhs(self):
        """Ensure a missing lhs returns rhs."""
        from sosbeacon.utils import get_latest_datetime

        lhs = datetime(2012, 9, 20, 3, 45)
        rhs = datetime(2012, 9, 20, 2, 45)

        result = get_latest_datetime(lhs, rhs)

        self.assertIs(lhs, result)
    def test_no_rhs(self):
        """Ensure a missing lhs returns rhs."""
        from sosbeacon.utils import get_latest_datetime

        lhs = object()
        rhs = None

        result = get_latest_datetime(lhs, rhs)

        self.assertIs(lhs, result)
Beispiel #7
0
    def merge(self, other):
        """Merge this StudentMarker entity with another StudentMarker."""
        self.first_name = other.first_name or self.first_name
        self.last_name = other.last_name or self.last_name

        self.last_broadcast = get_latest_datetime(self.last_broadcast,
                                                  other.last_broadcast)

        if not other.contacts:
            # All other info comes from contacts, so if there's no change bail.
            return self

        if not self.contacts:
            self.contacts = []

#        for new_hash, new_contact in other.contacts.iteritems():
        for i in range(len(other.contacts)):

            contact = self.contacts[i]
            if not contact:
                # New contact
                self.contacts[i] = other.contacts[i]
                contact = other.contacts[i]
            else:
                # Update existing contact.
                contact['acked'] = max(contact.get('acked'),
                                       other.contacts[i].get('acked'))

                contact['acked_at'] = max(contact.get('acked_at'),
                                          other.contacts[i].get('acked_at'))

                contact['sent'] = max(contact.get('sent'),
                                      other.contacts[i].get('sent'))

            # Update overall information.
            self.acknowledged = max(self.acknowledged,
                                    contact.get('acked'))

            self.acknowledged_at = max(self.acknowledged_at,
                                       contact.get('acked_at'))

            #self.all_acknowledged = min(self.all_acknowledged,
            #                            contact.get('acked'))

            #self.all_acknowledged_at = None if not self.all_acknowledged else max(
            #    self.all_acknowledged_at, contact.get('acked_at'))

            #self.last_broadcast = max(self.last_broadcast,
            #                          contact.get('sent'))
        return self