Beispiel #1
0
    def test_json_to_python(self):
        """Test converting flattened public data to its Python equivalent.

        This should expand ids to ObjectId instances, and set the logged in
        user to the owner of any incoming Location objects.
        """

        # There seems to be a problem with Flask-Login setting the current_user proxy
        # in api/models.py, which we need t run this test.
        if False:
            self.login_test_user()

            location = {
                'address': '123 Main St.',
                'lat': '127.0',  # forgive numbers coming as strings
                'lng': -42,
                'name': 'nowhere',
                'id': str(ObjectId())
            }

            expanded = Location.from_json(location)

            # these should all be the same
            self.assertEqual(expanded['address'], location['address'])
            self.assertEqual(expanded['lat'], location['lat'])
            self.assertEqual(expanded['lng'], location['lng'])
            self.assertEqual(expanded['name'], location['name'])

            # owner should be set by the currently logged in location
            self.assertEqual(expanded['owner'], self.test_location.id)

            # id should be renamed from id to _id, and expanded
            self.assertTrue(expanded.has_key('_id'))
            self.assertFalse(expanded.has_key('id'))
            self.assertEqual(str(expanded['_id']), location['id'])
Beispiel #2
0
    def test_json_to_python(self):
        """Test converting flattened public data to its Python equivalent.

        This should expand ids to ObjectId instances, and set the logged in
        user to the owner of any incoming Location objects.
        """

        # There seems to be a problem with Flask-Login setting the current_user proxy
        # in api/models.py, which we need t run this test.
        if False:
            self.login_test_user()

            location = {
                    'address' : '123 Main St.',
                    'lat'     : '127.0',    # forgive numbers coming as strings
                    'lng'     : -42,
                    'name'    : 'nowhere',
                    'id'      : str(ObjectId())
                    }

            expanded = Location.from_json(location)

            # these should all be the same
            self.assertEqual(expanded['address'], location['address'])
            self.assertEqual(expanded['lat'], location['lat'])
            self.assertEqual(expanded['lng'], location['lng'])
            self.assertEqual(expanded['name'], location['name'])

            # owner should be set by the currently logged in location
            self.assertEqual(expanded['owner'], self.test_location.id)

            # id should be renamed from id to _id, and expanded
            self.assertTrue(expanded.has_key('_id'))
            self.assertFalse(expanded.has_key('id'))
            self.assertEqual(str(expanded['_id']), location['id'])
Beispiel #3
0
    def _location_from_json_or_400(self, data, required_id=None):
        """Parse the data into a valid location, or abort with a 404."""

        location = Location.from_json(data, required_id=required_id)
        if not location:
            abort(400)

        return location
Beispiel #4
0
    def _location_from_json_or_400(self, data, required_id=None):
        """Parse the data into a valid location, or abort with a 404."""

        location = Location.from_json(data, required_id=required_id)
        if not location:
            abort(400)

        return location