示例#1
0
    def test_coordinates_are_optionnal_for_grab(self):
        move = self.blend_move(type=MOVE_TYPE_DIPPED)
        payload = MovePayload(MOVE_TYPE_GRABBED)\
            .set_id(move.id)

        payload.patch(move.id, user=self.admin)
        self.assertEqual(move.type, MOVE_TYPE_GRABBED)

        payload.set_coordinates()\
            .patch(move.id, user=self.admin)
        self.assertEqual(move.type, MOVE_TYPE_GRABBED)
示例#2
0
    def test_must_include_coordinates_if_missing_from_last_move(self):
        move = self.blend_move(type=MOVE_TYPE_GRABBED)
        payload = MovePayload(MOVE_TYPE_DIPPED)\
            .set_id(move.id)

        payload.patch(move.id, user=self.admin, code=422)\
            .assertRaiseJsonApiError('/data/attributes/latitude')\
            .assertRaiseJsonApiError('/data/attributes/longitude')

        payload.set_coordinates()\
            .patch(move.id, user=self.admin)
        self.assertEqual(move.type, MOVE_TYPE_DIPPED)
示例#3
0
    def test_convert_to_dropped(self):
        move = self.blend_move(type=MOVE_TYPE_GRABBED)
        payload = MovePayload(MOVE_TYPE_DROPPED)\
            .set_id(move.id)

        payload.patch(move.id, user=self.admin, code=422)\
            .assertRaiseJsonApiError('/data/attributes/latitude')\
            .assertRaiseJsonApiError('/data/attributes/longitude')

        payload.set_coordinates()\
            .patch(move.id, user=self.admin)
        self.assertEqual(move.type, MOVE_TYPE_DROPPED)
        self.assertEqual(float(move.latitude), 43.78)
        self.assertEqual(float(move.longitude), 7.06)
示例#4
0
    def test_convert_to_grabbed(self):
        move = self.blend_move(type=MOVE_TYPE_DROPPED,
                               latitude=43.78,
                               longitude=7.06)
        payload = MovePayload(MOVE_TYPE_GRABBED)\
            .set_id(move.id)

        payload.patch(move.id, user=self.admin)
        self.assertEqual(move.type, MOVE_TYPE_GRABBED)
        self.assertEqual(float(move.latitude), 43.78)
        self.assertEqual(float(move.longitude), 7.06)

        payload.set_coordinates(None, None)\
            .patch(move.id, user=self.admin)
        self.assertEqual(move.type, MOVE_TYPE_GRABBED)
        self.assertIsNone(move.latitude)
        self.assertIsNone(move.longitude)
示例#5
0
    def test_convert_to_seen(self):
        move = self.blend_move(type=MOVE_TYPE_DROPPED,
                               latitude=43.78,
                               longitude=7.06)
        payload = MovePayload(MOVE_TYPE_SEEN)\
            .set_id(move.id)

        payload.patch(move.id, user=self.admin)
        self.assertEqual(move.type, MOVE_TYPE_SEEN)
        self.assertEqual(float(move.latitude), 43.78)
        self.assertEqual(float(move.longitude), 7.06)

        payload._set_attribute('latitude', 43.79)\
            .patch(move.id, user=self.admin)
        self.assertEqual(move.type, MOVE_TYPE_SEEN)
        self.assertEqual(float(move.latitude), 43.79)
        self.assertEqual(float(move.longitude), 7.06)

        payload.set_coordinates(None, None)\
            .patch(move.id, user=self.admin, code=422)\
            .assertRaiseJsonApiError('/data/attributes/latitude')\
            .assertRaiseJsonApiError('/data/attributes/longitude')