def test_with_place_holder(self, update_marker_pair_mock,
                               find_markers_for_methods_mock,
                               put_multi_mock):
        """Ensure the marker already pointed at is used as the base."""
        from sosbeacon.event.contact_marker import merge_markers

        self.marker3.place_holder = self.marker1.key

        all_students = self.marker1.students.keys()
        all_students.extend(self.marker2.students.keys())
        all_students.extend(self.marker3.students.keys())

        all_methods = self.marker1.methods[:]
        all_methods.extend(self.marker2.methods[:])
        all_methods.extend(self.marker3.methods[:])

        find_markers_for_methods_mock.return_value = (
            self.marker1, self.marker2, self.marker3)

        merge_markers(object(), object())

        self.assertEqual(sorted(all_students), sorted(self.marker1.students))
        self.assertEqual(sorted(all_methods), sorted(self.marker1.methods))

        self.assertEqual(self.marker1.key, self.marker2.place_holder)
        self.assertEqual(self.marker1.key, self.marker3.place_holder)

        self.assertEqual(2, update_marker_pair_mock.call_count)
Ejemplo n.º 2
0
    def post(self):
        import json

        event_urlsafe = self.request.get('event')
        if not event_urlsafe:
            logging.error('No event key given.')
            return

        # TODO: Use event id rather than key here for namespacing purposes?
        event_key = ndb.Key(urlsafe=event_urlsafe)
        event = event_key.get()
        if not event:
            logging.error('Event %s not found!', event_key)
            return

        if event.status == EVENT_STATUS_CLOSED:
            logging.error('Event %s closed!', event_key)
            return

        methods = self.request.get('methods')
        if not methods:
            logging.error('No methods given.')
            return
        methods = json.loads(methods)

        merge_markers(event_key, methods)
    def test_new_with_one_acked(self, update_marker_pair_mock,
                                find_markers_for_methods_mock,
                                put_multi_mock):
        """Ensure the new markers are merged, and the acked marker is used
        as the base.
        """
        from sosbeacon.event.contact_marker import merge_markers

        self.marker2.acknowledged = True
        self.marker2.last_viewed_date = 12345

        all_students = self.marker1.students.keys()
        all_students.extend(self.marker2.students.keys())
        all_students.extend(self.marker3.students.keys())

        all_methods = self.marker1.methods[:]
        all_methods.extend(self.marker2.methods[:])
        all_methods.extend(self.marker3.methods[:])

        find_markers_for_methods_mock.return_value = (
            self.marker1, self.marker2, self.marker3)

        merge_markers(object(), object())

        self.assertEqual(sorted(all_students), sorted(self.marker2.students))
        self.assertEqual(sorted(all_methods), sorted(self.marker2.methods))

        self.assertEqual(self.marker2.key, self.marker1.place_holder)
        self.assertEqual(self.marker2.key, self.marker3.place_holder)

        self.assertEqual(2, update_marker_pair_mock.call_count)
    def test_all_new(self, update_marker_pair_mock,
                     find_markers_for_methods_mock, put_multi_mock):
        """Ensure all of the new markers are merged."""
        from sosbeacon.event.contact_marker import merge_markers

        all_students = self.marker1.students.keys()
        all_students.extend(self.marker2.students.keys())
        all_students.extend(self.marker3.students.keys())

        all_methods = self.marker1.methods[:]
        all_methods.extend(self.marker2.methods[:])
        all_methods.extend(self.marker3.methods[:])

        find_markers_for_methods_mock.return_value = (
            self.marker1, self.marker2, self.marker3)

        merge_markers(object(), object())

        self.assertEqual(sorted(all_students), sorted(self.marker1.students))
        self.assertEqual(sorted(all_methods), sorted(self.marker1.methods))

        self.assertEqual(self.marker1.key, self.marker2.place_holder)
        self.assertEqual(self.marker1.key, self.marker3.place_holder)

        self.assertEqual(2, update_marker_pair_mock.call_count)
Ejemplo n.º 5
0
    def test_with_multiple_place_holders(self, update_marker_pair_mock,
                                         find_markers_for_methods_mock,
                                         put_multi_mock):
        """Ensure marker pointed at the most is used as the base."""
        from sosbeacon.event.contact_marker import merge_markers

        self.marker3.place_holder = self.marker1.key
        self.marker4.place_holder = self.marker1.key
        self.marker2.place_holder = self.marker3.key

        all_students = self.marker1.students.keys()
        all_students.extend(self.marker2.students.keys())
        all_students.extend(self.marker3.students.keys())
        all_students.extend(self.marker4.students.keys())

        all_methods = self.marker1.methods[:]
        all_methods.extend(self.marker2.methods[:])
        all_methods.extend(self.marker3.methods[:])
        all_methods.extend(self.marker4.methods[:])

        find_markers_for_methods_mock.return_value = (self.marker1,
                                                      self.marker2,
                                                      self.marker3,
                                                      self.marker4)

        merge_markers(object(), object())

        self.assertEqual(sorted(all_students), sorted(self.marker1.students))
        self.assertEqual(sorted(all_methods), sorted(self.marker1.methods))

        self.assertEqual(self.marker1.key, self.marker2.place_holder)
        self.assertEqual(self.marker1.key, self.marker3.place_holder)

        self.assertEqual(3, update_marker_pair_mock.call_count)
Ejemplo n.º 6
0
    def test_new_with_one_acked(self, update_marker_pair_mock,
                                find_markers_for_methods_mock, put_multi_mock):
        """Ensure the new markers are merged, and the acked marker is used
        as the base.
        """
        from sosbeacon.event.contact_marker import merge_markers

        self.marker2.acknowledged = True
        self.marker2.last_viewed_date = 12345

        all_students = self.marker1.students.keys()
        all_students.extend(self.marker2.students.keys())
        all_students.extend(self.marker3.students.keys())

        all_methods = self.marker1.methods[:]
        all_methods.extend(self.marker2.methods[:])
        all_methods.extend(self.marker3.methods[:])

        find_markers_for_methods_mock.return_value = (self.marker1,
                                                      self.marker2,
                                                      self.marker3)

        merge_markers(object(), object())

        self.assertEqual(sorted(all_students), sorted(self.marker2.students))
        self.assertEqual(sorted(all_methods), sorted(self.marker2.methods))

        self.assertEqual(self.marker2.key, self.marker1.place_holder)
        self.assertEqual(self.marker2.key, self.marker3.place_holder)

        self.assertEqual(2, update_marker_pair_mock.call_count)
Ejemplo n.º 7
0
    def test_all_new(self, update_marker_pair_mock,
                     find_markers_for_methods_mock, put_multi_mock):
        """Ensure all of the new markers are merged."""
        from sosbeacon.event.contact_marker import merge_markers

        all_students = self.marker1.students.keys()
        all_students.extend(self.marker2.students.keys())
        all_students.extend(self.marker3.students.keys())

        all_methods = self.marker1.methods[:]
        all_methods.extend(self.marker2.methods[:])
        all_methods.extend(self.marker3.methods[:])

        find_markers_for_methods_mock.return_value = (self.marker1,
                                                      self.marker2,
                                                      self.marker3)

        merge_markers(object(), object())

        self.assertEqual(sorted(all_students), sorted(self.marker1.students))
        self.assertEqual(sorted(all_methods), sorted(self.marker1.methods))

        self.assertEqual(self.marker1.key, self.marker2.place_holder)
        self.assertEqual(self.marker1.key, self.marker3.place_holder)

        self.assertEqual(2, update_marker_pair_mock.call_count)