-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/corpus analysis #140
Open
flavioamieiro
wants to merge
10
commits into
develop
Choose a base branch
from
feature/corpus-analysis
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3af9bef
Remove mocks for GridFSDataRetriever wich no longer exists
flavioamieiro 0b716e9
Adapts `manage` helper function to the new settings scheme
flavioamieiro 8aac6ca
Adds 'properties' to Corpus model
flavioamieiro da84551
Makes sure TestWithMongo writes to mongo before running the test
flavioamieiro 8b1ef1a
WIP: adds CorpusFreqDist view with reading capability
flavioamieiro 1dc3ae1
Returns 404 if corpus does not have a freqdist yet
flavioamieiro 3a23140
Adds a function to queue a corpus freq dist task in the backend
flavioamieiro 9590252
Queue a FreqDist analysis for a corpus when a PUT request is received
flavioamieiro c199d1e
Sends a list of ObjectId's to the task
flavioamieiro fa253f9
Clarifies the name of the function that queues freqdist analysis for …
flavioamieiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[ | ||
{ | ||
"_id" : { "$oid": "5785005257bc3a1070d8cdbf" }, | ||
"corpus_id" : 2, | ||
"freqdist" : [ | ||
[ "á", 1 ], | ||
[ "non-ascii", 1 ], | ||
[ ".", 1 ], | ||
[ "char", 1 ], | ||
[ "file", 1 ], | ||
[ "test", 1 ], | ||
[ ":", 1 ], | ||
[ "with", 1 ] | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# -*- coding:utf-8 -*- | ||
# | ||
# Copyright 2012 NAMD-EMAP-FGV | ||
# | ||
# This file is part of PyPLN. You can get more information at: http://pypln.org/. | ||
# | ||
# PyPLN is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# PyPLN is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with PyPLN. If not, see <http://www.gnu.org/licenses/>. | ||
import json | ||
|
||
from django.contrib.auth.models import User | ||
from django.core.urlresolvers import reverse | ||
from mock import patch | ||
|
||
from pypln.web.core.models import Corpus, User | ||
from pypln.web.core.tests.utils import TestWithMongo | ||
|
||
__all__ = ["CorpusFreqDistViewTest"] | ||
|
||
|
||
class CorpusFreqDistViewTest(TestWithMongo): | ||
fixtures = ['users', 'corpora', 'documents', 'corpora_analysis'] | ||
|
||
def test_requires_login(self): | ||
response = self.client.get(reverse('corpus-freqdist', | ||
kwargs={'pk': 2})) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
def test_returns_404_for_inexistent_corpus(self): | ||
self.client.login(username="user", password="user") | ||
response = self.client.get(reverse('corpus-freqdist', | ||
kwargs={'pk': 9999})) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_returns_404_if_user_is_not_the_owner_of_the_corpus(self): | ||
self.client.login(username="user", password="user") | ||
corpus = Corpus.objects.filter(owner__username="admin")[0] | ||
response = self.client.get(reverse('corpus-freqdist', | ||
kwargs={'pk': corpus.id})) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_returns_404_if_corpus_has_no_freqdist_yet(self): | ||
self.client.login(username="admin", password="admin") | ||
corpus = Corpus.objects.filter(owner__username="admin")[0] | ||
response = self.client.get(reverse('corpus-freqdist', | ||
kwargs={'pk': corpus.id})) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_shows_corpus_freqdist_correctly(self): | ||
self.client.login(username="user", password="user") | ||
corpus = Corpus.objects.filter(owner__username="user")[0] | ||
response = self.client.get(reverse('corpus-freqdist', | ||
kwargs={'pk': corpus.id})) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.renderer_context['view'].get_object(), | ||
corpus) | ||
expected_data = corpus.properties['freqdist'] | ||
self.assertEqual(response.data['value'], expected_data) | ||
|
||
@patch('pypln.web.core.views.corpus_freqdist') | ||
def test_queue_freqdist_analysis_for_a_corpus_that_still_does_not_have_one(self,corpus_freqdist): | ||
""" | ||
This is a regression test. There used to be a bug that returned 404 | ||
before queueing the analysis if the corpus didn't have a freqdist | ||
analysis yet. | ||
""" | ||
self.user = User.objects.get(username="admin") | ||
self.client.login(username="admin", password="admin") | ||
|
||
corpus = self.user.corpus_set.all()[0] | ||
response = self.client.put(reverse('corpus-freqdist', | ||
kwargs={"pk": corpus.id})) | ||
|
||
self.assertFalse(corpus.properties.has_key("freqdist")) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue(corpus_freqdist.called) | ||
corpus_freqdist.assert_called_with(corpus) | ||
|
||
@patch('pypln.web.core.views.corpus_freqdist') | ||
def test_queue_freqdist_analysis_for_a_corpus_that_has_one(self,corpus_freqdist): | ||
self.user = User.objects.get(username="user") | ||
self.client.login(username="user", password="user") | ||
|
||
corpus = self.user.corpus_set.all()[0] | ||
response = self.client.put(reverse('corpus-freqdist', | ||
kwargs={"pk": corpus.id})) | ||
|
||
self.assertTrue(corpus.properties.has_key("freqdist")) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue(corpus_freqdist.called) | ||
corpus_freqdist.assert_called_with(corpus) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this have a verb-name, like
calculate_corpus_freqdist
? I thought the call on the view was strange because of this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I just pushed that change.