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
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
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
def test_view_notebook(self): nb = models.Notebook(owner=self.user1, title='atitle') nb.save() # login c = self.client logged_in = c.login(username='******', password='******') assert logged_in # check we can get a notebook via its guid response = c.get('/notebook/%s/' % nb.guid) assert response.status_code == 200
def new_notebook(request): """Create a new Notebook. Set notebook default type, and start instance. """ engine_type_id = request.GET.get("engine_type", "") nb = notebook_models.Notebook(owner=request.user) nb.save() engine_type = backend_models.EngineType.objects.get(id=engine_type_id) access_id = rpc.allocateEngine(engine_type.backend.address, engine_type.name) default_engine = backend_models.NotebookBackendRecord( notebook=nb, engine_type=engine_type, access_id=access_id) default_engine.save() redirect = "/notebook/%s" % nb.guid return HttpResponseRedirect(redirect)
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
def test_view_notebook(): nb = models.Notebook(owner=f['user1'], title='atitle') nb.save() # login c = Client() logged_in = c.login(username='******', password='******') assert logged_in # check we can get a notebook via its guid response = c.get('/notebook/%s/' % nb.guid) assert response.status_code == 200 # and that non existant notebooks raise 404 response = c.get('/notebook/doesnotexist/') assert response.status_code == 404 nb.delete() #clean up
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
def test_a_new_notebook_is_assigned_a_guid(self): nb = models.Notebook(owner=self.user1) nb.save() assert nb.guid is not None
def test_a_new_notebook_is_assigned_a_guid(): nb = models.Notebook(owner=f['user1']) nb.save() assert nb.guid is not None