Exemplo n.º 1
0
def test_search():
    #XXX Turn off Nose doctests?
    #"""
    #Add 2 Cells into 2 different Notebooks,
    #one with correct search terms,
    #and the other without, test that
    #only the Notebook with the correct search
    #terms appears in the results.
    #"""
    nb1 = models.Notebook(owner=f['user1'])
    nb1.save()
    nb2 = models.Notebook(owner=f['user1'])
    nb2.save()

    cell1 = models.Cell(guid=str(uuid.uuid4()).replace("-", ""),
                        notebook=nb1,
                        owner=nb1.owner,
                        content="foo=1\nbar=foo+foo")
    cell1.save()

    cell2 = models.Cell(guid=str(uuid.uuid4()).replace("-", ""),
                        notebook=nb2,
                        owner=nb2.owner,
                        content="baz=1\nbar=baz+baz")
    cell2.save()

    guids = [result["nbid"] for result in search.search("foo")]
    assert nb1.guid in guids
    assert nb2.guid not in guids
Exemplo n.º 2
0
    def test_view_search(self):
        nb1 = models.Notebook(owner=self.user1)
        nb1.save()

        nb1_record = backend_models.NotebookBackendRecord(
            notebook=nb1, engine_type=self.engine_type)
        nb1_record.save()

        nb2 = models.Notebook(owner=self.user2, title="Foo is Foo")
        nb2.save()
        nb2_record = backend_models.NotebookBackendRecord(
            notebook=nb2, engine_type=self.engine_type)
        nb2_record.save()

        nb3 = models.Notebook(owner=self.user2)
        nb3.save()
        nb3_record = backend_models.NotebookBackendRecord(
            notebook=nb3, engine_type=self.engine_type)
        nb3_record.save()

        cell1 = models.Cell(guid=unicode(uuid.uuid4()).replace("-", ""),
                            notebook=nb1,
                            owner=nb1.owner,
                            content="foo=1\nbar=foo+foo")
        cell1.save()

        cell2 = models.Cell(guid=unicode(uuid.uuid4()).replace("-", ""),
                            notebook=nb2,
                            owner=nb2.owner,
                            content="foo=1\nbar=foo+foo")
        cell2.save()

        cell3 = models.Cell(guid=unicode(uuid.uuid4()).replace("-", ""),
                            notebook=nb3,
                            owner=nb3.owner,
                            content="baz=1\nfump=baz+baz")
        cell3.save()

        c = Client()
        logged_in = c.login(username='******', password='******')
        assert logged_in
        response = c.get('/search', {'q': 'foo'})
        resp = json.loads(response.content)
        assert resp["query"] == "foo"
        result_nbid = resp["results"][0][0]
        result_title = resp["results"][0][1]
        assert nb2.title == result_title
        assert nb1.guid != result_nbid  #incorrect notebook owner
        assert nb2.guid == result_nbid  #contains search term
        assert nb3.guid != result_nbid  #no search terms
Exemplo n.º 3
0
 def save_notebook_metadata(self, orderlist, cellsdata):
     #print 'save_notebook_metadata'
     #print orderlist, cellsdata
     nb = models.Notebook.objects.get(guid=self.id)
     for cellid, data in cellsdata.items():
         cells = models.Cell.objects.filter(guid=cellid)
         content = data["content"]
         style = data["cellstyle"]
         props = data["props"]
         if len(cells) > 0:
             cell = cells[0]
             #print 'lenCELLS > 0', cell
             cell.content = content
             cell.type = u"text"
             cell.style = style
             cell.props = props
             cell.save()
         else:
             #print 'NO CELLS'
             cell = models.Cell(guid=cellid,
                                notebook=nb,
                                owner=nb.owner,
                                content=content,
                                type=u"text",
                                style=style,
                                props=props)
             nb.cell_set.add(cell)
     #print 'save orderlist'
     nb.orderlist = orderlist
     nb.save()
     return
Exemplo n.º 4
0
def save(request, nbid):
    """Save cell data
    TODO think about moving saving logic into model/model manager 
    """
    nb = notebook_models.Notebook.objects.get(owner=request.user, guid=nbid)
    orderlist = request.POST.get('orderlist')
    cellsdata = json.loads(request.POST.get('cellsdata'))

    for cellid, data in cellsdata.items():
        cells = notebook_models.Cell.objects.filter(guid=cellid, notebook=nb)
        content = data["content"]
        style = data["cellstyle"]
        props = data["props"]
        if len(cells) > 0:
            cell = cells[0]
            cell.content = content
            cell.type = u"text"
            cell.style = style
            cell.props = props
            cell.save()
        else:
            cell = notebook_models.Cell(guid=cellid,
                                        notebook=nb,
                                        owner=nb.owner,
                                        content=content,
                                        type=u"text",
                                        style=style,
                                        props=props)
            nb.cell_set.add(cell)
    nb.orderlist = orderlist
    nb.save()
    resp = {'resp': 'ok'}
    jsobj = json.dumps(resp)
    return HttpResponse(jsobj, mimetype="application/json")
Exemplo n.º 5
0
    def test_notebook_last_modified_by_returns_last_cell_modifier(self):
        nb = models.Notebook(owner=self.user1)
        nb.save()
        assert nb.last_modified_by() == self.user1

        cell = models.Cell(guid=str(uuid.uuid4()).replace("-", ""),
                           notebook=nb,
                           owner=self.user2)
        cell.save()
        assert nb.last_modified_by() == self.user2
        nb.delete()  #clean up
Exemplo n.º 6
0
    def test_search(self):
        #XXX Turn off Nose doctests?
        #"""
        #Add 2 Cells into 2 different Notebooks,
        #one with correct search terms,
        #and the other without, test that
        #only the Notebook with the correct search
        #terms appears in the results.
        #"""
        nb1 = models.Notebook(owner=self.user1)
        nb1.save()
        nb1_record = backend_models.NotebookBackendRecord(
            notebook=nb1, engine_type=self.engine_type)
        nb1_record.save()

        nb2 = models.Notebook(owner=self.user1)
        nb2.save()
        nb2_record = backend_models.NotebookBackendRecord(
            notebook=nb2, engine_type=self.engine_type)
        nb2_record.save()

        cell1 = models.Cell(guid=unicode(uuid.uuid4()).replace("-", ""),
                            notebook=nb1,
                            owner=nb1.owner,
                            content="foo=1\nbar=foo+foo")
        cell1.save()

        cell2 = models.Cell(guid=unicode(uuid.uuid4()).replace("-", ""),
                            notebook=nb2,
                            owner=nb2.owner,
                            content="baz=1\nbar=baz+baz")
        cell2.save()

        guids = [result["nbid"] for result in search.search(u"foo")]
        assert nb1.guid in guids
        assert nb2.guid not in guids
Exemplo n.º 7
0
    def test_adding_a_cell_to_a_notebook_updates_the_last_modified_time(self):
        nb = models.Notebook(owner=self.user1)
        nb.save()
        first_time = nb.last_modified_time()

        print nb.created_time

        cell = models.Cell(guid=str(uuid.uuid4()).replace("-", ""),
                           notebook=nb,
                           owner=nb.owner)
        cell.save()

        print nb.cell_set.all()
        print cell.last_modified

        second_time = nb.last_modified_time()
        assert second_time > first_time
        nb.delete()  #clean up
Exemplo n.º 8
0
 def save_cell(self, id, content, type, style, props):
     id, content, type, style, props = [
         unicode(w) for w in [id, content, type, style, props]
     ]
     nb = self.get_notebook()
     #cell, created = models.Cell.objects.get_or_create(guid=id, owner=nb.owner)
     cells = models.Cell.objects.filter(guid=id)
     if len(cells) == 0:
         cell = models.Cell(guid=id, owner=nb.owner)
     else:
         cell = cells[0]
     cell.content = content
     cell.type = type
     cell.style = style
     cell.props = props
     if len(cells) == 0:
         nb.cell_set.add(cell)
         nb.save()
     else:
         cell.save()