Пример #1
0
class EmpresaModelTest(TestCase):
    def setUp(self):
        self.obj = EmpresaModel(
            ref_cad="12.5.12.01.001",
            name="INDUSTRIA STARK LTDA",
            atividade="ATIVIDADE MILITAR",
            endereco="RUA SHIELD, 199",
            quadra="10",
            lote="2",
            categoria_distrito="0",
            email="*****@*****.**",
            phone="055-19-3541-0000",
            responsavel="Anotny Stark",
            observacao="",
        )
        self.obj.save()

    def test_create(self):
        self.assertTrue(EmpresaModel.objects.exists())

    def test_created_at(self):
        self.assertIsInstance(self.obj.created_at, datetime)

    def test_distrito_verbose(self):
        distrito = dict(DISTRITO_CHOICES)[self.obj.categoria_distrito]
        self.assertEqual(distrito, "OUTROS")
Пример #2
0
class VistoriaModelTest(TestCase):
    def setUp(self):
        self.empresa = EmpresaModel(
            ref_cad="12.5.12.01.001",
            name="INDUSTRIA STARK LTDA",
            atividade="ATIVIDADE MILITAR",
            endereco="RUA SHIELD, 199",
            quadra="10",
            lote="2",
            email="*****@*****.**",
            phone="055-19-3541-0000",
            responsavel="Antony Stark",
            observacao="",
        )
        self.empresa.save()
        self.vistoria = VistoriaModel(
            empresa=self.empresa,
            imagem=SimpleUploadedFile('tiny.gif', TINY_GIF)
        )
        self.vistoria.save()

    def test_create(self):
        self.assertTrue(EmpresaModel.objects.exists())
        self.assertTrue(VistoriaModel.objects.exists())

    def test_created_at(self):
        self.assertIsInstance(self.vistoria.created_at, datetime)

    def test_comentario(self):
        self.assertEqual(self.vistoria.observacao, 'NENHUMA OBSERVAÇÃO')

    def test_empresa(self):
        self.assertEqual(self.vistoria.empresa.id, self.empresa.pk)
Пример #3
0
class visualizarVistoriaGet(TestCase):
    def setUp(self):
        self.username = '******'
        self.password = '******'
        self.client = Client()
        User.objects.create_user(
            self.username,
            '*****@*****.**',
            self.password)
        self.client.login(username=self.username,
                          password=self.password)
        self.empresa = EmpresaModel(
            ref_cad="12.5.12.01.001",
            name="INDUSTRIA STARK LTDA",
            atividade="ATIVIDADE MILITAR",
            endereco="RUA SHIELD, 199",
            quadra="10",
            lote="2",
            email="*****@*****.**",
            phone="055-19-3541-0000",
            responsavel="Antony Stark",
            observacao="",
        )
        self.empresa.save()
        self.imagem_mock = SimpleUploadedFile('tiny.gif', TINY_GIF)
        self.vistoria = VistoriaModel(
            empresa=self.empresa,
            imagem=self.imagem_mock
        )
        self.vistoria.save()
        self.resp = self.client.get(r('vistorias:vistorias_listar', self.vistoria.pk))

    def test_template_used(self):
        self.assertTemplateUsed(self.resp, 'vistorias_visualizar.html')

    def test_200_template_vistoria(self):
        self.assertEqual(200, self.resp.status_code)

    def test_html(self):
        tags = (
            ('Visualizar Vistorias', 2),
            ('readonly', 2),
            ('FATEC Araras', 2),

        )
        for text, count in tags:
            with self.subTest():
                self.assertContains(self.resp, text, count)

    def test_has_form(self):
        form = self.resp.context['form']
        self.assertIsInstance(form, VistoriaForm)

    def test_has_vistoria(self):
        vistoria = self.resp.context['vistoria']
        self.assertIsInstance(vistoria, VistoriaModel)
Пример #4
0
class editarEmpresa_accept_blank_Post(TestCase):
    def setUp(self):
        self.username = '******'
        self.password = '******'
        self.client = Client()
        User.objects.create_user(self.username, '*****@*****.**',
                                 self.password)
        self.client.login(username=self.username, password=self.password)
        self.obj = EmpresaModel(ref_cad="12.5.12.01.001",
                                area_lote="50 metros",
                                area_construida="50 metros",
                                name="INDUSTRIA STARK LTDA",
                                atividade="ATIVIDADE MILITAR",
                                cnpj="62.823.257/0001-09",
                                endereco="",
                                quadra="10",
                                lote="2",
                                categoria_distrito="0",
                                email="",
                                phone="",
                                responsavel="",
                                observacao="")
        self.obj.save()
        d = {
            'ref_cad': '12.5.12.01.002',
            'area_lote': "50 metros",
            'area_construida': "50 metros",
            'name': 'Ozark',
            'categoria_atividade': 'comercio',
            'atividade': 'lavagem de dinheiro',
            'cnpj': '62.823.257/0001-09',
            'endereco': 'Rua Belo Horizonte',
            'quadra': '102',
            'lote': '20',
            'categoria_distrito': '1',
            'email': '*****@*****.**',
            'phone': '055-19-3541-0000',
            'responsavel': 'desconhecido',
            'observacao': ''
        }

        self.resp = self.client.post(r('empresas:editar', self.obj.pk), d)

    def test_data_changed_name(self):
        q = EmpresaModel.objects.filter(pk=1)
        self.assertEqual(q[0].name, 'OZARK')

    def test_data_changed_email(self):
        q = EmpresaModel.objects.filter(pk=1)
        self.assertEqual(q[0].email, '*****@*****.**')

    def test_data_changed_categoria_atividade(self):
        q = EmpresaModel.objects.filter(pk=1)
        self.assertEqual(q[0].categoria_atividade, 'comercio')
Пример #5
0
class Test_VistoriaForm_Test(TestCase):
    def setUp(self):
        self.empresa = EmpresaModel(
            ref_cad="12.5.12.01.001",
            name="INDUSTRIA STARK LTDA",
            atividade="ATIVIDADE MILITAR",
            endereco="RUA SHIELD, 199",
            quadra="10",
            lote="2",
            email="*****@*****.**",
            phone="055-19-3541-0000",
            responsavel="Antony Stark",
            observacao="",
        )
        self.empresa.save()
        self.mocked_img = SimpleUploadedFile('tiny.gif', TINY_GIF)
        self.vistoria = {
            'observacao':"aaa",
            'empresa':self.empresa.id
        }
        self.imagem = {
            'imagem':self.mocked_img
        }
        self.form = VistoriaForm(self.vistoria, self.imagem)
        self.form.is_valid()
        self.form.save()

    def test_valid_form(self):
        self.assertEqual(True, self.form.is_valid())

    def test_create(self):
        self.assertTrue(EmpresaModel.objects.exists())
        self.assertTrue(VistoriaModel.objects.exists())

    def test_saved_image(self):
        self.assertEqual(self.mocked_img, self.form.cleaned_data['imagem'])

    def test_observacao_upper(self):
        self.assertEqual('AAA', self.form.cleaned_data['observacao'])

    def test_method_read_only_true(self):
        self.form.read_only()
        fields = list(self.form.fields)
        for field in fields:
            with self.subTest():
                self.assertEqual(self.form.fields[field].widget.attrs['readonly'], True)

    def test_method_read_only_false(self):
        self.form.read_only(False)
        fields = list(self.form.fields)
        for field in fields:
            with self.subTest():
                self.assertEqual(self.form.fields[field].widget.attrs['readonly'], False)
Пример #6
0
class editarEmpresaPostFail(TestCase):
    def setUp(self):
        self.username = '******'
        self.password = '******'
        self.client = Client()
        User.objects.create_user(self.username, '*****@*****.**',
                                 self.password)
        self.client.login(username=self.username, password=self.password)
        self.obj = EmpresaModel(ref_cad="12.5.12.01.001",
                                area_lote="50 metros",
                                area_construida="50 metros",
                                name="INDUSTRIA STARK LTDA",
                                atividade="ATIVIDADE MILITAR",
                                endereco="RUA SHIELD, 199",
                                quadra="10",
                                lote="2",
                                email="*****@*****.**",
                                phone="055-19-3541-0000",
                                responsavel="Anotny Stark")
        self.obj.save()
        d = {
            'ref_cad': '12.5.12.01.002',
            'area_lote': "55 metros",
            'area_construida': "55 metros",
            'atividade': 'lavagem de dinheiro',
            'endereco': 'Rua elo Horizonte',
            'quadra': '102',
            'lote': '20',
            'email': '*****@*****.**',
            'phone': '055-19-3541-0000',
            'responsavel': 'desconhecido'
        }
        self.resp = self.client.post(r('empresas:editar', self.obj.pk), d)

    def test_template_home(self):
        self.assertTemplateUsed(self.resp, 'empresas_editar.html')

    def test_200_template_empresa(self):
        self.assertEqual(200, self.resp.status_code)

    def test_data_not_changed_name(self):
        q = EmpresaModel.objects.filter(pk=1)
        self.assertEqual(q[0].name, 'INDUSTRIA STARK LTDA')

    def test_data_not_changed_email(self):
        q = EmpresaModel.objects.filter(pk=1)
        self.assertEqual(q[0].email, '*****@*****.**')

    def test_data_not_changed_categoria_atividade(self):
        q = EmpresaModel.objects.filter(pk=1)
        self.assertEqual(q[0].categoria_atividade, 'prestacao')
Пример #7
0
class vistorias_empresaGet(TestCase):
    def setUp(self):
        self.username = '******'
        self.password = '******'
        self.client = Client()
        User.objects.create_user(self.username, '*****@*****.**',
                                 self.password)
        self.client.login(username=self.username, password=self.password)
        self.obj = EmpresaModel(ref_cad="12.5.12.01.001",
                                name="INDUSTRIA STARK LTDA",
                                categoria_atividade="prestacao",
                                atividade="ATIVIDADE MILITAR",
                                endereco="RUA SHIELD, 199",
                                quadra="10",
                                lote="2",
                                email="*****@*****.**",
                                phone="055-19-3541-0000",
                                responsavel="Anotny Stark")
        self.obj.save()
        self.vistoria = VistoriaModel(empresa=self.obj,
                                      imagem=SimpleUploadedFile(
                                          'tiny.gif', TINY_GIF))
        self.vistoria.save()
        self.resp = self.client.get(
            r('empresas:empresas_vistorias', self.obj.pk))

    def test_template_home(self):
        self.assertTemplateUsed(self.resp, 'vistorias_listar_todas.html')

    def test_200_template_empresa(self):
        self.assertEqual(200, self.resp.status_code)

    def test_html(self):
        tags = (
            ('Cadastro de Vistorias', 2),
            ('INDUSTRIA', 1),
            ('STARK', 1),
        )
        for text, count in tags:
            with self.subTest():
                self.assertContains(self.resp, text, count)

    def test_has_form(self):
        form = self.resp.context['form']
        self.assertIsInstance(form, VistoriaForm)
Пример #8
0
class cadastroVistoriaPostValid(TestCase):
    def setUp(self):
        self.username = '******'
        self.password = '******'
        self.client = Client()
        User.objects.create_user(self.username, '*****@*****.**',
                                 self.password)
        self.client.login(username=self.username, password=self.password)
        self.obj = EmpresaModel(
            ref_cad="12.5.12.01.001",
            name="INDUSTRIA STARK LTDA",
            atividade="ATIVIDADE MILITAR",
            endereco="RUA SHIELD, 199",
            quadra="10",
            lote="2",
            email="*****@*****.**",
            phone="055-19-3541-0000",
            responsavel="Antony Stark",
            observacao="",
        )
        self.obj.save()
        self.imagem_mock = SimpleUploadedFile('tiny.gif', TINY_GIF)

        self.data = {}
        self.data['empresa'] = self.obj.pk
        self.data['observacao'] = "agendado próxima visita"
        self.data['imagem'] = self.imagem_mock

        self.resp = self.client.post(r('vistorias:vistorias_cadastrar'),
                                     self.data)

    def test_post(self):
        self.assertEqual(302, self.resp.status_code)

    def test_saved_data(self):
        self.assertTrue(EmpresaModel.objects.exists())
        self.assertTrue(VistoriaModel.objects.exists())

    def test_redirect_site(self):
        url = self.resp.url
        self.assertEqual('/vistorias/', url)
Пример #9
0
class editarEmpresaGet(TestCase):
    def setUp(self):
        self.username = '******'
        self.password = '******'
        self.client = Client()
        User.objects.create_user(self.username, '*****@*****.**',
                                 self.password)
        self.client.login(username=self.username, password=self.password)
        self.obj = EmpresaModel(ref_cad="12.5.12.01.001",
                                name="INDUSTRIA STARK LTDA",
                                cnpj="62.823.257/0001-09",
                                categoria_atividade="prestacao",
                                atividade="ATIVIDADE MILITAR",
                                endereco="RUA SHIELD, 199",
                                quadra="10",
                                lote="2",
                                email="*****@*****.**",
                                phone="055-19-3541-0000",
                                responsavel="Anotny Stark")
        self.obj.save()
        self.resp = self.client.get(r('empresas:editar', self.obj.pk))

    def test_template_home(self):
        self.assertTemplateUsed(self.resp, 'empresas_editar.html')

    def test_200_template_empresa(self):
        self.assertEqual(200, self.resp.status_code)

    def test_html(self):
        tags = (('Editar cadastro da Empresa', 2), )
        for text, count in tags:
            with self.subTest():
                self.assertContains(self.resp, text, count)

    def test_has_form(self):
        form = self.resp.context['form']
        self.assertIsInstance(form, EmpresaForm)