Ejemplo n.º 1
0
    def testFindAllAround(self):
        objs = Conversation.findAll(location=[-27.8727, -54.4951])
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))
Ejemplo n.º 2
0
    def testFindAllAroundRadiusByUser(self):
        objs = Conversation.findAll(location=[-27.8727, -54.4951], radius=20000, user_id=2)
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))
Ejemplo n.º 3
0
    def testFindAllPopularByUser(self):
        objs = Conversation.findAll(user_id=2, order_by='popular')
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))
Ejemplo n.º 4
0
    def testFindAllRecentByUser(self):
        objs = Conversation.findAll(user_id=2)
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))
Ejemplo n.º 5
0
    def testFindAllRecentByInterest(self):
        objs = Conversation.findAll(interest_id=6)
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))
Ejemplo n.º 6
0
def conversations():
    form = ConversationListForm(request)
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    total = Conversation.countAll(order_by=form.order,
                                  location=form.location,
                                  radius=form.radius,
                                  after=form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAll(order_by=form.order,
                                        location=form.location,
                                        radius=form.radius,
                                        offset=pg.offset,
                                        limit=pg.per_page,
                                        after=form.after)
        else:
            return json({'message': "Invalid interest or end of page list"},
                        404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Ejemplo n.º 7
0
    def testFindAllAfter(self):
        date = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
        objs = Conversation.findAll(after=date)
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))
Ejemplo n.º 8
0
    def testFindAllAroundByInterest(self):
        interest_id = 6
        objs = Conversation.findAll(interest_id=interest_id, location=[-27.8727, -54.4951])
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))
            self.assertTrue(obj.interest.id == interest_id)
Ejemplo n.º 9
0
    def testFindAllPopular(self):
        objs = Conversation.findAll(order_by='popular')
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))

        if len(objs) > 2:
            self.assertTrue(objs[0].score >= objs[1].score, 'First object should have a greater score')
Ejemplo n.º 10
0
    def testFindAllRecent(self):
        objs = Conversation.findAll()
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))

        if len(objs) > 2:
            self.assertTrue(objs[0].created_at >= objs[1].created_at, 'First object should be newer')
Ejemplo n.º 11
0
    def testFindAllAroundOrderByDistance(self):
        objs = Conversation.findAll(location=[-27.8727, -54.4951], order_by='distance')
        self.assertTrue(is_array(objs))
        self.assertTrue(len(objs) > 0)

        for obj in objs:
            self.assertTrue(isinstance(obj, Conversation))

        if len(objs) > 2:
            self.assertTrue(objs[0].distance <= objs[1].distance, 'First object should have a smaller distance')
Ejemplo n.º 12
0
def index(interest_id):
    form = ConversationIndexForm(request, url={'interest_id': interest_id})
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    total = Conversation.countAll(form.interest_id, form.order, form.location,
                                  form.radius, None, form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAll(form.interest_id, form.order, form.location,
                                        form.radius, pg.offset, pg.per_page, None, form.after)
        else:
            return json({'message': "Invalid interest or end of page list"}, 404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Ejemplo n.º 13
0
def conversations():
    form = ConversationListForm(request)
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    total = Conversation.countAll(order_by=form.order, location=form.location,
                                  radius=form.radius, after=form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAll(order_by=form.order, location=form.location,
                                        radius=form.radius, offset=pg.offset,
                                        limit=pg.per_page, after=form.after)
        else:
            return json({'message': "Invalid interest or end of page list"}, 404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Ejemplo n.º 14
0
def index(interest_id):
    form = ConversationIndexForm(request, url={'interest_id': interest_id})
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    total = Conversation.countAll(form.interest_id, form.order, form.location,
                                  form.radius, None, form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAll(form.interest_id, form.order,
                                        form.location, form.radius, pg.offset,
                                        pg.per_page, None, form.after)
        else:
            return json({'message': "Invalid interest or end of page list"},
                        404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))