Example #1
0
 def list(self, d):
     page, max, offset = tools.paging_params(self.request)
     readable_id = self.request.get('readable_id')
     quotes = Quote.Fetch(self.user, readable_id=readable_id, limit=max, offset=offset)
     self.set_response({
         'quotes': [q.json() for q in quotes]
     }, success=True)
Example #2
0
 def random_batch(self, d):
     '''
     Return a random batch, optionally filtered
     '''
     BATCH_SIZE = 50
     sample_keys = Quote.Fetch(self.user, limit=500, keys_only=True)
     if len(sample_keys) > BATCH_SIZE:
         sample_keys = random.sample(sample_keys, BATCH_SIZE)
     quotes = ndb.get_multi(sample_keys)
     self.set_response({'quotes': [q.json() for q in quotes]}, success=True)
Example #3
0
    def test_evernote_webhook(self, get_note_mocked):
        EN_NOTE_GUID = "1000-0815-aefe-b8a0-8888"
        EN_USER_ID = "1001"
        EN_NOTEBOOK_ID = "ffff-0000"

        self.u.evernote_id = EN_USER_ID
        self.u.set_integration_prop('evernote_notebook_ids', EN_NOTEBOOK_ID)
        self.u.put()

        # Test article clip
        # Mock return from Evernote service
        get_note_mocked.return_value = (EN_NOTE_GUID, MEDIUM_TITLE,
                                        MEDIUM_FULL_CONTENT, MEDIUM_URL)

        self.get_json("/api/integrations/evernote/webhook", {
            'reason': 'create',
            'guid': EN_NOTE_GUID,
            'notebookGuid': EN_NOTEBOOK_ID,
            'userId': self.u.evernote_id
        },
                      headers=self.api_headers)
        readables = Readable.Fetch(self.u)
        self.assertEqual(len(readables), 1)
        r = readables[0]
        self.assertEqual(r.title, MEDIUM_TITLE)
        self.assertEqual(r.url, MEDIUM_URL)

        # Test quote/excerpt clip
        get_note_mocked.return_value = (EN_NOTE_GUID, CRONY_TITLE, CRONY_QUOTE,
                                        CRONY_URL)

        self.get_json("/api/integrations/evernote/webhook", {
            'reason': 'create',
            'guid': EN_NOTE_GUID,
            'notebookGuid': EN_NOTEBOOK_ID,
            'userId': self.u.evernote_id
        },
                      headers=self.api_headers)
        quotes = Quote.Fetch(self.u)
        self.assertEqual(len(quotes), 1)
        q = quotes[0]
        self.assertEqual(q.source, CRONY_TITLE)
        self.assertEqual(q.content, CRONY_QUOTE)
Example #4
0
    def test_quote_readable_matching(self):
        volley = [
            ('1000', "Crony Beliefs", "Kevin Simler", "CRONY BELIEFS (SIMLER)",
             "I contend that the best way to understand all the crazy beliefs out there ā€” aliens, conspiracies, and all the rest ā€” is to analyze them as crony beliefs. Beliefs that have been \"hired\" not for the legitimate purpose of accurately modeling the world, but rather for social and political kickbacks."
             ),
            ('1001', "Thinking in Systems: A Primer", "Donna H. Meadows",
             "THINKING IN SYSTEMS A PRIMER (MEADOWS)", "XXX."),
        ]

        for v in volley:
            source_id, title, author, exp_slug, content = v
            r = Readable.CreateOrUpdate(self.u,
                                        source_id,
                                        title=title,
                                        author=author,
                                        source="test")
            r.put()
            Readable.put_sd_batch([r])

            self.assertEqual(r.slug, exp_slug)

            author_names = author.split(' ')
            source = "%s (%s, %s)" % (title, author_names[-1], author_names[0])
            q = Quote.Create(self.u, source, content)
            q.put()
            self.assertIsNotNone(q.readable)
            self.assertEqual(q.readable, r.key)
            self.assertEqual(q.source_slug(), exp_slug)
            r = Readable.GetByTitleAuthor(self.u, author, title)
            self.assertIsNotNone(r)
            self.assertEqual(r.source_id, source_id)

        # Create another quote with no readable to link to
        q = Quote.Create(self.u, "xxx", "content...")
        q.put()

        self.assertIsNone(q.readable)

        # Fetch quotes for readable
        quotes = Quote.Fetch(self.u, readable_id=r.key.id())
        self.assertEqual(len(quotes), 1)
        self.assertEqual(quotes[0].source, source)
Example #5
0
    def test_quote_readable_matching(self):
        volley = [
            ('1000', CRONY_TITLE, CRONY_AUTHOR, "CRONY BELIEFS (SIMLER)",
             CRONY_QUOTE),
            ('1001', "Thinking in Systems: A Primer", "Donna H. Meadows",
             "THINKING IN SYSTEMS A PRIMER (MEADOWS)", "XXX."),
        ]

        for v in volley:
            source_id, title, author, exp_slug, content = v
            r = Readable.CreateOrUpdate(self.u,
                                        source_id,
                                        title=title,
                                        author=author,
                                        source="test")
            r.put()
            Readable.put_sd_batch([r])

            self.assertEqual(r.slug, exp_slug)

            author_names = author.split(' ')
            source = "%s (%s, %s)" % (title, author_names[-1], author_names[0])
            q = Quote.Create(self.u, source, content)
            q.put()
            self.assertIsNotNone(q.readable)
            self.assertEqual(q.readable, r.key)
            self.assertEqual(q.source_slug(), exp_slug)
            r = Readable.GetByTitleAuthor(self.u, author, title)
            self.assertIsNotNone(r)
            self.assertEqual(r.source_id, source_id)

        # Create another quote with no readable to link to
        q = Quote.Create(self.u, "xxx", "content...")
        q.put()

        self.assertIsNone(q.readable)

        # Fetch quotes for readable
        quotes = Quote.Fetch(self.u, readable_id=r.key.id())
        self.assertEqual(len(quotes), 1)
        self.assertEqual(quotes[0].source, source)