예제 #1
0
 def test_get_count_without_order_filter(self):
     for content in range(0, 10):
         SBContent(content="this is content number 2-%d" % content,
                   to_be_deleted=True).save()
     queryset = NeoQuerySet(SBContent)\
         .filter("WHERE res.to_be_deleted=False")
     self.assertEqual(queryset.count(), 50)
예제 #2
0
def get_parent_object(object_uuid):
    try:
        query = "MATCH (a:Comment {object_uuid:'%s'})<-[:HAS_A]-" \
                "(b:SBContent) RETURN b" % object_uuid
        res, col = db.cypher_query(query)
        return SBContent.inflate(res[0][0])
    except IndexError:
        return None
예제 #3
0
def get_flag_parent(object_uuid):
    try:
        query = "MATCH (a:Flag {object_uuid:'%s'})-[:FLAG_ON]->" \
                "(b:SBContent) RETURN b" % (object_uuid)
        res, col = db.cypher_query(query)
        try:
            content = SBContent.inflate(res[0][0])
        except ValueError:
            # This exception was added while initially implementing the fxn and
            # may not be possible in production. What happened was multiple
            # flags/votes got associated with a piece of content causing an
            # array to be returned instead of a single object which is handled
            # above. This should be handled now but we should verify that
            # the serializers ensure this singleness prior to removing this.
            content = SBContent.inflate(res[0][0][0])
        return content
    except (IndexError):
        return None
예제 #4
0
 def test_get_count_with_order_filter_distinct_reversed(self):
     for content in range(0, 15):
         SBContent(content="this is content number 2-%d" % content,
                   to_be_deleted=True).save()
     queryset = NeoQuerySet(SBContent, distinct=True, descending=True)\
         .order_by('ORDER BY res.created')\
         .filter("WHERE res.to_be_deleted=True")
     self.assertEqual(queryset.count(), 15)
     self.assertEqual(queryset[:1][0].content,
                      "this is content number 2-14")
예제 #5
0
 def test_get_list_with_filter(self):
     for content in range(0, 3):
         SBContent(content="this is content number 2-%d" % content,
                   to_be_deleted=True).save()
     queryset = NeoQuerySet(SBContent) \
         .filter("WHERE res.to_be_deleted=True")\
         .order_by('ORDER BY res.created')
     query_res = list(queryset)
     self.assertEqual(queryset.count(), 3)
     self.assertEqual(query_res[0].content, "this is content number 2-0")
     self.assertEqual(query_res[1].content, "this is content number 2-1")
     self.assertEqual(query_res[2].content, "this is content number 2-2")
예제 #6
0
 def public_content(self, request, username=None):
     filter_by = request.query_params.get('filter', "")
     try:
         additional_params = get_filter_params(filter_by, SBContent())
     except (IndexError, KeyError, ValueError):
         return Response(errors.QUERY_DETERMINATION_EXCEPTION,
                         status=status.HTTP_400_BAD_REQUEST)
     query = '(res:SBPublicContent)-[:OWNED_BY]->(a:Pleb ' \
             '{username: "******"})' % username
     queryset = NeoQuerySet(SBContent, query=query).filter(
         'WHERE res.to_be_deleted=false %s' % additional_params)
     return self.get_paginated_response(
         self.serializer_class(self.paginate_queryset(queryset),
                               many=True,
                               context={
                                   'request': request
                               }).data)
예제 #7
0
 def get_comment_on(cls, object_uuid):
     from sb_base.neo_models import SBContent
     query = 'MATCH (c:Comment {object_uuid:"%s"})<-[:HAS_A]-(o) ' \
             'RETURN o' % object_uuid
     res, _ = db.cypher_query(query)
     return SBContent.inflate(res.one)
예제 #8
0
 def setUp(self):
     query = 'MATCH (a) OPTIONAL MATCH (a)-[r]-() DELETE a, r'
     db.cypher_query(query)
     for content in range(0, 50):
         SBContent(content="this is content number %d" % content).save()