Beispiel #1
0
    def test_parse_resource_uri(self):
        _in = "not a uri"
        self.assertRaises(ValueError, utils.parse_resource_uri, _in)

        _in = "/api/v1/prestataires/12/"
        out = "prestataire", "12"
        self.assertEqual(utils.parse_resource_uri(_in), out)

        _in = "/api/v1/familles/123"
        out = "famille", "123"
        self.assertEqual(utils.parse_resource_uri(_in), out)
Beispiel #2
0
    def add_favorite(self, resource_uri):
        """
        Favorite an object for the user.

        :param resource_uri:          the URI of the resource to favorite
        """
        object_type, object_id = parse_resource_uri(resource_uri)
        self.favorites.get_or_create(object_type=object_type.title(), object_id=int(object_id))
Beispiel #3
0
    def remove_favorite(self, resource_uri):
        """
        Unfavorite an object for the user.

        :param resource_uri:      the URI of the resource to unfavorite
        """
        object_type, object_id = parse_resource_uri(resource_uri)
        object_type = object_type.title()
        object_id = int(object_id)
        self.favorites.filter(object_type=object_type, object_id=object_id).delete()