Exemplo n.º 1
0
    def test_silo_detail_import_done(self):
        # Create Silo, Read and CeleryTask
        read_type = factories.ReadType(read_type="CSV")
        read = factories.Read(
            owner=self.user, type=read_type,
            read_name="TEST SILO DONE", description="unittest"
        )
        silo = factories.Silo(owner=self.user, public=False)
        silo.reads.add(read)
        factories.CeleryTask(content_object=read,
                             task_status=CeleryTask.TASK_FINISHED)

        # Check view
        request = self.factory.get(self.silo_detail_url)
        request.user = self.user

        response = siloDetail(request, silo.pk)
        self.assertContains(
            response,
            '<a href="/show_read/{}" target="_blank">{}</a>'.format(
                read.id, read.read_name)
        )
        self.assertNotContains(
            response, '<span class="btn-sm btn-danger">Import Failed</span>')
        self.assertNotContains(
            response, '<span class="btn-sm btn-warning">Import running</span>')
        self.assertNotContains(
            response, '<h4 style="color:#ff3019">Import process failed</h4>')
        self.assertNotContains(response, '<h4>Import process running</h4>')
Exemplo n.º 2
0
    def test_new_silodata(self):
        read_type = ReadType.objects.get(read_type="CSV")
        upload_file = open('test.csv', 'rb')
        read = Read.objects.create(owner=self.user,
                                   type=read_type,
                                   read_name="TEST CSV IMPORT",
                                   description="unittest",
                                   create_date='2015-06-24 20:33:47',
                                   file_data=SimpleUploadedFile(
                                       upload_file.name, upload_file.read()))
        params = {
            "read_id": read.pk,
            "new_silo": "Test CSV Import",
        }
        request = self.factory.post(self.upload_csv_url, data=params)
        request.user = self.user
        request._dont_enforce_csrf_checks = True
        response = uploadFile(request, read.pk)
        self.assertEqual(response.status_code, 302)
        self.assertIn("/silo_detail/", response.url)

        silo = Silo.objects.get(name="Test CSV Import")
        request = self.factory.get(self.silo_detail_url)
        request.user = self.user

        response = siloDetail(request, silo.pk)
        self.assertEqual(response.status_code, 200)

        #now delete that silo data cause this uses the custom database
        LabelValueStore.objects.filter(First_Name="Bob",
                                       Last_Name="Smith",
                                       silo_id="1",
                                       read_id="1").delete()
        LabelValueStore.objects.filter(First_Name="John",
                                       Last_Name="Doe",
                                       silo_id="1",
                                       read_id="1").delete()
        LabelValueStore.objects.filter(First_Name="Joe",
                                       Last_Name="Schmoe",
                                       silo_id="1",
                                       read_id="1").delete()
        LabelValueStore.objects.filter(First_Name="جان",
                                       Last_Name="ډو",
                                       silo_id="1",
                                       read_id="1").delete()
Exemplo n.º 3
0
    def test_silo_detail_import_failed(self):
        # Create Silo, Read and CeleryTask
        read_type = factories.ReadType(read_type="CSV")
        read = factories.Read(
            owner=self.user, type=read_type,
            read_name="TEST SILO FAIL", description="unittest"
        )
        silo = factories.Silo(owner=self.user, public=False)
        silo.reads.add(read)
        task = factories.CeleryTask(content_object=read, task_status=CeleryTask.TASK_FAILED)

        # Check view
        request = self.factory.get(self.silo_detail_url)
        request.user = self.user

        response = siloDetail(request, silo.pk)
        self.assertContains(response, "<a href=\"/show_read/"+str(read.id)+"\" target=\"_blank\">"+read.read_name+"</a>")
        self.assertContains(response, "<span class=\"btn-sm btn-danger\">Import Failed</span>")
        self.assertContains(response, "<h4 style=\"color:#ff3019\">Import process failed</h4>")