def testOverdue(self): # Scrapers that haven't been run for longer than the run interval # should appear in the list of scrapers to be run overdue = Scraper(last_run=datetime.datetime.now() - datetime.timedelta(7), run_interval=86400) overdue.save() self.assertEqual(1, self.scrapers.count())
def test_short_name_several_same_long_name(self): long_title = u'I think this is a very very very very very very very long title' short_name = SlugifyUniquely(long_title, Scraper, 'short_name') self.assertEqual(u'i_think_this_is_a_very_very_very_very_very_very_ve', short_name) scraper1 = Scraper() scraper1.title = long_title scraper1.save() self.assertEqual(short_name, scraper1.short_name) short_name = SlugifyUniquely(long_title, Scraper, 'short_name') self.assertEqual(u'i_think_this_is_a_very_very_very_very_very_very_1', short_name) scraper2 = Scraper() scraper2.title = long_title scraper2.save() self.assertEqual(short_name, scraper2.short_name) short_name = SlugifyUniquely(long_title, Scraper, 'short_name') self.assertEqual(u'i_think_this_is_a_very_very_very_very_very_very_2', short_name)
def testNotOverdue(self): # Scrapers that haven't been run for less than the run interval # should not appear in the list of scrapers to be run not_overdue = Scraper(title=u'Not Overdue', last_run=datetime.datetime.now(), run_interval=86400) not_overdue.save() self.assertEqual(0, self.scrapers.count())
def testNeverRun(self): # Published scrapers that have never been run should # appear in the list of scrapers to be run never_run = Scraper(title=u'Never Run', last_run=None, run_interval=86400) never_run.save() self.assertEqual(1, self.scrapers.count())
def test_live_tutorials(self): # make some dummy tutorials ix = 0 for lang in ['ruby', 'python', 'php']: ix = ix + 1 for i in range(ix): scraper = Scraper(title=unicode(lang + str(i)), language=lang, istutorial=True) scraper.save() # check the pages render right ix = 0 for lang in ['ruby', 'python', 'php']: ix = ix + 1 response = self.client.get(reverse('tutorials', kwargs={'language':lang})) self.assertEqual(response.status_code, 200) tutorials = response.context['tutorials'] # print "***TUT:", tutorials self.assertEqual(tutorials.keys(), [lang]) self.assertEqual(ix, len(tutorials[lang]))
def test_live_tutorials(self): # make some dummy tutorials ix = 0 for lang in ['ruby', 'python', 'php']: ix = ix + 1 for i in range(ix): scraper = Scraper(title=unicode(lang + str(i)), language=lang, istutorial=True) scraper.save() # check the pages render right ix = 0 for lang in ['ruby', 'python', 'php']: ix = ix + 1 response = self.client.get( reverse('tutorials', kwargs={'language': lang})) self.assertEqual(response.status_code, 200) tutorials = response.context['tutorials'] # print "***TUT:", tutorials self.assertEqual(tutorials.keys(), [lang]) self.assertEqual(ix, len(tutorials[lang]))
def test_scraper_name(self): self.assertEqual( 'test_scraper', unicode(Scraper(title='Test Scraper', short_name='test_scraper')) )
def add_to_vault(request, wiki_type, language, id): """ Create a new scraper with the specific type and language, put it in the vault (if the current user is allowed and then we're done) """ from codewiki.models import Vault, Scraper, View, UserCodeRole name = request.GET.get('name', None) if not name: return HttpResponseForbidden("A name is required") vault = get_object_or_404(Vault, pk=id) if not request.user in vault.members.all(): return HttpResponseForbidden("You cannot access this vault") if wiki_type == 'scraper': scraper = Scraper() else: scraper = View() scraper.title = name scraper.language = language scraper.privacy_status = 'private' scraper.vault = vault scraper.generate_apikey() scraper.save() # Make sure we update the access rights vault.update_access_rights() scraper.commit_code(blankstartupcode[wiki_type][language], "Created", request.user) response_url = reverse('editor_edit', kwargs={ 'wiki_type': wiki_type, 'short_name': scraper.short_name }) return HttpResponseRedirect(response_url)
def add_to_vault(request, wiki_type, language, id): """ Create a new scraper with the specific type and language, put it in the vault (if the current user is allowed and then we're done) """ from codewiki.models import Vault, Scraper, View, UserCodeRole name = request.GET.get('name', None) if not name: return HttpResponseForbidden("A name is required") vault = get_object_or_404(Vault, pk=id) if not request.user in vault.members.all(): return HttpResponseForbidden("You cannot access this vault") if wiki_type == 'scraper': scraper = Scraper() else: scraper = View() scraper.title = name scraper.language = language scraper.privacy_status = 'private' scraper.vault = vault scraper.generate_apikey() scraper.save() # Make sure we update the access rights vault.update_access_rights() scraper.commit_code(blankstartupcode[wiki_type][language], "Created", request.user) response_url = reverse('editor_edit', kwargs={'wiki_type': wiki_type, 'short_name' : scraper.short_name}) return HttpResponseRedirect(response_url)
def my_vault_contains_a_scraper_called_x(step, title): from codewiki.models import Vault, Scraper, UserCodeRole user = User.objects.get(username='******') vault = [v for v in user.vaults.all()][0] scraper = Scraper() scraper.title = title scraper.language = u'python' scraper.privacy_status = u'private' scraper.vault = vault scraper.generate_apikey() scraper.save() vault.update_access_rights() scraper.commit_code(u"import scraperwiki\n\n# Blank Python\n\n", u"Created", user)
def my_vault_contains_x_scrapers(step, num): from codewiki.models import Vault, Scraper, UserCodeRole user = User.objects.get(username='******') vault = [v for v in user.vaults.all()][0] num = 1 if num == 'a' else int(num) for i in range(num): scraper = Scraper() scraper.title = u'Private Scraper #%s' % (i + 1) scraper.language = u'python' scraper.privacy_status = u'private' scraper.vault = vault scraper.generate_apikey() scraper.save() vault.update_access_rights() scraper.commit_code(u"import scraperwiki\n\n# Blank Python\n\n", u"Created", user)