Ejemplo n.º 1
0
 def test_start_import(self):
     ''' begin loading books '''
     import_job = goodreads_import.create_job(self.user, self.csv, False,
                                              'unlisted')
     MockTask = namedtuple('Task', ('id'))
     mock_task = MockTask(7)
     with patch('bookwyrm.goodreads_import.import_data.delay') as start:
         start.return_value = mock_task
         goodreads_import.start_import(import_job)
     import_job.refresh_from_db()
     self.assertEqual(import_job.task_id, '7')
Ejemplo n.º 2
0
    def test_import_data(self):
        ''' resolve entry '''
        import_job = goodreads_import.create_job(self.user, self.csv, False,
                                                 'unlisted')
        book = models.Edition.objects.create(title='Test Book')

        with patch('bookwyrm.models.import_job.ImportItem.get_book_from_isbn'
                   ) as resolve:
            resolve.return_value = book
            with patch('bookwyrm.goodreads_import.handle_imported_book'):
                goodreads_import.import_data(import_job.id)

        import_item = models.ImportItem.objects.get(job=import_job, index=0)
        self.assertEqual(import_item.book.id, book.id)
Ejemplo n.º 3
0
    def test_create_job(self):
        ''' creates the import job entry and checks csv '''
        import_job = goodreads_import.create_job(self.user, self.csv, False,
                                                 'public')
        self.assertEqual(import_job.user, self.user)
        self.assertEqual(import_job.include_reviews, False)
        self.assertEqual(import_job.privacy, 'public')

        import_items = models.ImportItem.objects.filter(job=import_job).all()
        self.assertEqual(len(import_items), 3)
        self.assertEqual(import_items[0].index, 0)
        self.assertEqual(import_items[0].data['Book Id'], '42036538')
        self.assertEqual(import_items[1].index, 1)
        self.assertEqual(import_items[1].data['Book Id'], '52691223')
        self.assertEqual(import_items[2].index, 2)
        self.assertEqual(import_items[2].data['Book Id'], '28694510')
Ejemplo n.º 4
0
def import_data(request):
    ''' ingest a goodreads csv '''
    form = forms.ImportForm(request.POST, request.FILES)
    if form.is_valid():
        include_reviews = request.POST.get('include_reviews') == 'on'
        privacy = request.POST.get('privacy')
        try:
            job = goodreads_import.create_job(
                request.user,
                TextIOWrapper(request.FILES['csv_file'],
                              encoding=request.encoding),
                include_reviews,
                privacy,
            )
        except (UnicodeDecodeError, ValueError):
            return HttpResponseBadRequest('Not a valid csv file')
        goodreads_import.start_import(job)
        return redirect('/import_status/%d' % (job.id, ))
    return HttpResponseBadRequest()
Ejemplo n.º 5
0
    def test_create_retry_job(self):
        ''' trying again with items that didn't import '''
        import_job = goodreads_import.create_job(self.user, self.csv, False,
                                                 'unlisted')
        import_items = models.ImportItem.objects.filter(
            job=import_job).all()[:2]

        retry = goodreads_import.create_retry_job(self.user, import_job,
                                                  import_items)
        self.assertNotEqual(import_job, retry)
        self.assertEqual(retry.user, self.user)
        self.assertEqual(retry.include_reviews, False)
        self.assertEqual(retry.privacy, 'unlisted')

        retry_items = models.ImportItem.objects.filter(job=retry).all()
        self.assertEqual(len(retry_items), 2)
        self.assertEqual(retry_items[0].index, 0)
        self.assertEqual(retry_items[0].data['Book Id'], '42036538')
        self.assertEqual(retry_items[1].index, 1)
        self.assertEqual(retry_items[1].data['Book Id'], '52691223')