Ejemplo n.º 1
0
class EntryViewTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_list_view_entry(self):
        self.insert_test_data()
        view = EntryListView.as_view()
        request = self.request_factory.get(
            reverse('entry_list')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 5)
        entry = Entry()
        entry.name = 'Entry test'
        entry.save()
        response = view(request)
        self.assertEqual(response.context_data['object_list'].count(), 6)

    def test_list_view_entry_filter(self):
        self.insert_test_data()
        request = self.request_factory.get(reverse('entry_list'),
                                   data={'name__icontains': 'Telefonia'}
        )
        request.user = self.user
        view = EntryListView.as_view()
        response = view(request)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.context_data['object_list']), 1)

    def test_create_view_entry(self):
        self.insert_test_data()
        self.assertEqual(Entry.objects.all().count(), 5)
        data = {
            'name': 'Entry test'
        }
        view = EntryCreateView.as_view()
        request = self.request_factory.post(
            reverse('entry_create'),data
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Entry.objects.all().count(), 6)
Ejemplo n.º 2
0
class StudioViewTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_list_view_studio(self):
        """
        Tests data: List
        """
        view = StudioListView.as_view()
        request = self.request_factory.get(
            reverse('studio_list')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 0)

        studio = Studio()
        studio.name = 'Client Test'
        studio.save()
        response = view(request)
        self.assertEqual(response.context_data['object_list'].count(), 1)

    def test_create_view_studio(self):
        """
        Tests data: Create
        """
        self.assertEqual(Studio.objects.all().count(), 0)

        data = {
            'name': 'Studio test',
        }
        view = StudioCreateView.as_view()
        request = self.request_factory.post(
            reverse('studio_create'), data
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Studio.objects.all().count(), 1)

    def test_update_view_brand(self):
        """
        Tests data: Update
        """
        self.assertEqual(Studio.objects.all().count(), 0)
        studio = Studio()
        studio.name = 'studio test'
        studio.save()

        request = self.request_factory.get(reverse('studio_edit',
                                                   kwargs={'pk': studio.id})
        )
        request.user = self.user
        view = StudioUpdateView.as_view()
        response = view(request, pk=studio.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Studio.objects.all().count(), 1)
        self.assertEqual(studio.name, 'studio test')
        #Post
        data = {
            'pk':  studio.id,
            'name': "actualizado",
        }

        url_kwargs = {'pk': studio.id}
        url = reverse('client_edit', kwargs=url_kwargs)
        request = self.request_factory.post(url, data=data)
        request.user = self.user
        view = StudioUpdateView.as_view()
        response = view(request, **data)

        client = Studio.objects.get(pk=1)
        self.assertEqual(client.name, 'actualizado')
        self.assertEqual(response.status_code, 302)

    def test_delete_view_brand(self):
        """
        Tests data: Delete
        """
        studio = Studio()
        studio.name = 'studio test'
        studio.save()
        studio = Studio.objects.get(pk=1)
        self.assertEqual(Studio.objects.all().count(), 1)

        kwargs = {'pk': studio.id}
        url = reverse('studio_delete', kwargs=kwargs)
        request = self.request_factory.post(url, kwargs)
        request.user = self.user
        response = StudioDeleteView.as_view()(request, **kwargs)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Studio.objects.all().count(), 0)
Ejemplo n.º 3
0
 def setUp(self):
     self.request_factory = RequestFactory()
     self.insert_data_helper = InsertDataHelper()
     self.date = datetime.datetime.now().utcnow().replace(tzinfo=utc)
Ejemplo n.º 4
0
class CommercialViewTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.date = datetime.datetime.now().utcnow().replace(tzinfo=utc)

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_basic_data(self):
        """
        Tests data test insert correct
        """
        self.insert_test_data()
        self.assertTrue(Brand.objects.all().count() > 0)
        self.assertTrue(Entry.objects.all().count() > 0)
        self.assertTrue(Project.objects.all().count() > 0)
        self.assertTrue(Commercial.objects.all().count() > 0)

    @override_settings(APPLICATION_CACHE=False)
    def test_list_view_commercial(self):
        """
        Tests List
        """
        self.insert_test_data()
        view = CommercialListView.as_view()
        request = self.request_factory.get(
            reverse('commercial_list')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context_data['object_list']), 4)
        commercial = Commercial()
        commercial.brand = Brand.objects.latest('id')
        commercial.save()
        response = view(request)
        self.assertEqual(len(response.context_data['object_list']), 5)

    @override_settings(APPLICATION_CACHE=False)
    def test_list_view_commercial_filter(self):
        """
        Tests Filter
        """
        self.insert_test_data()
        request = self.request_factory.get(reverse('commercial_list'),
                                   data={'name__icontains': 'Navidad'}
        )
        request.user = self.user
        view = CommercialListView.as_view()
        response = view(request)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.context_data['object_list']), 1)

    @override_settings(APPLICATION_CACHE=False)
    def test_create_view_commercial(self):
        """
        Tests Create
        """
        self.insert_test_data()
        self.assertEqual(Commercial.objects.all().count(), 4)
        data = {
            'name': 'Commercial test',
            'brand': Brand.objects.filter(name='Sprite')[0].id,
            'id_realized': '02/07/2014'
        }
        view = CommercialCreateView.as_view()
        request = self.request_factory.post(
            reverse('commercial_create'), data
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Commercial.objects.all().count(), 5)
        self.assertEqual(CommercialDateDetail.objects.all().count(), 1)

    @override_settings(APPLICATION_CACHE=False)
    def test_update_view_commercial(self):
        """
        Tests data: Update
        """
        from datetime import datetime
        self.insert_test_data()
        self.assertEqual(Commercial.objects.all().count(), 4)
        commercial = Commercial.objects.get(pk=1)

        request = self.request_factory.get(reverse('commercial_edit',
                                                   kwargs={'pk': commercial.id})
        )
        request.user = self.user
        view = CommercialUpdateView.as_view()
        response = view(request, pk=commercial.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Commercial.objects.all().count(), 4)
        self.assertEqual(commercial.name, 'Coca Cola Navidad')

        #Post
        data = {
            'pk':  commercial.id,
            'name': "actualizado",
            'brand': Brand.objects.get(id=1).id,
            'realized': '2014-08-08',
        }

        url_kwargs = {'pk': commercial.id}
        url = reverse('commercial_edit', kwargs=url_kwargs)
        request = self.request_factory.post(url, data=data)
        request.user = self.user
        view = CommercialUpdateView.as_view()
        response = view(request, **data)

        commercial = Commercial.objects.get(pk=1)
        self.assertEqual(commercial.name, 'actualizado')
        self.assertEqual(response.status_code, 302)

    @override_settings(APPLICATION_CACHE=False)
    def test_delete_view_brand(self):
        """
        Tests data: Delete
        """
        self.insert_test_data()
        self.assertEqual(Commercial.objects.all().count(), 4)
        commercial = Commercial.objects.get(pk=1)

        kwargs = {'pk': commercial.id}
        url = reverse('commercial_delete', kwargs=kwargs)
        request = self.request_factory.post(url, kwargs)
        request.user = self.user
        response = CommercialDeleteView.as_view()(request, **kwargs)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Commercial.objects.all().count(), 3)

    @override_settings(APPLICATION_CACHE=False)
    def test_data_list(self):
        """
       Tests List
       """
        self.insert_test_data()
        view = CommercialDataListView.as_view()
        request = self.request_factory.get(
            reverse('commercial_data_list')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len( content.get('commercial')), 4)
        commercial = Commercial()
        commercial.brand = Brand.objects.latest('id')
        commercial.save()
        response = view(request)
        content = json.loads(response._container[0])
        self.assertEqual(len( content.get('commercial')), 5)

    @override_settings(APPLICATION_CACHE=False)
    def test_create_json(self):
        self.insert_test_data()
        self.assertEqual(Commercial.objects.all().count(), 4)
        data = {
            'brand': 1,
            'name': u'test'
        }

        view = CommercialCreateDataJson.as_view()
        request = self.request_factory.post(
            reverse('panel_model_save_profile'), data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), "success")
        self.assertEqual(Commercial.objects.all().count(), 5)
Ejemplo n.º 5
0
class BrandViewTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_basic_data(self):
        """
        Tests data test insert correct
        """
        self.insert_test_data()
        self.assertTrue(Brand.objects.all().count() > 0)
        self.assertTrue(Entry.objects.all().count() > 0)

    def test_list_view_brand(self):
        """
        Tests data: List
        """
        self.insert_test_data()
        view = BrandListView.as_view()
        request = self.request_factory.get(
            reverse('brand_list')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 9)
        brand = Brand()
        brand.entry = Entry.objects.latest('id')
        brand.name = 'Brand Test'
        brand.save()
        response = view(request)
        self.assertEqual(response.context_data['object_list'].count(), 10)

    def test_list_view_brand_filter(self):
        """
        Tests data: Filter
        """
        self.insert_test_data()
        request = self.request_factory.get(reverse('brand_list'),
                                   data={'name__icontains': 'Sprite'})
        request.user = self.user
        view = BrandListView.as_view()
        response = view(request)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.context_data['object_list']), 1)

    def test_create_view_brand(self):
        """
        Tests data: Create
        """
        self.insert_test_data()
        self.assertEqual(Brand.objects.all().count(), 9)
        data = {
            'name': 'Brand test',
            'entry': Entry.objects.filter(name='Bancos')[0].id
        }
        view = BrandCreateView.as_view()
        request = self.request_factory.post(
            reverse('brand_create'), data
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Brand.objects.all().count(), 10)

    def test_update_view_brand(self):
        """
        Tests data: Update
        """
        self.insert_test_data()
        self.assertEqual(Brand.objects.all().count(), 9)
        brand = Brand.objects.get(pk=1)

        request = self.request_factory.get(reverse('brand_edit',
                                         kwargs={'pk': brand.id})
        )
        request.user = self.user
        view = BrandUpdateView.as_view()
        response = view(request, pk=brand.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Brand.objects.all().count(), 9)
        self.assertEqual(brand.name, 'Coca Cola')
        #Post
        data = {
            'pk':  brand.id,
            'name': "actualizado",
            'entry': Entry.objects.get(id=1).id
        }

        url_kwargs = {'pk': brand.id}
        url = reverse('brand_edit', kwargs=url_kwargs)
        request = self.request_factory.post(url, data=data)
        request.user = self.user
        view = BrandUpdateView.as_view()
        response = view(request, **data)

        brand = Brand.objects.get(pk=1)
        self.assertEqual(brand.name, 'actualizado')
        self.assertEqual(response.status_code, 302)

    def test_delete_view_brand(self):
        """
        Tests data: Delete
        """
        self.insert_test_data()
        self.assertEqual(Brand.objects.all().count(), 9)
        brand = Brand.objects.get(pk=1)

        kwargs = {'pk': brand.id}
        url = reverse('brand_delete', kwargs=kwargs)
        request = self.request_factory.post(url, kwargs)
        request.user = self.user
        response = BrandDeleteView.as_view()(request, **kwargs)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Brand.objects.all().count(), 8)
Ejemplo n.º 6
0
 def setUp(self):
     self.search = Search()
     self.insert_data_helper = InsertDataHelper()
     self.insert_test_data()
Ejemplo n.º 7
0
class RepresentationViewTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_project(self):
        project = Project()
        project.line_productions = Project.LINE_PHOTO
        project.code = '1'
        project.commercial = Commercial.objects.latest('created')
        project.version = '0'
        project.start_productions = '2014-08-1'
        project.end_productions = '2014-08-2'
        project.save()
        return project

    def test_data_required(self):
        self.assertTrue(len(Model.objects.all()) > 0)

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_event_list(self):
        """
        Tests List
        """
        view = RepresentationEventsDataList.as_view()
        request = self.request_factory.get(
            reverse('representation_data_event')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len( content.get('events')), 4)

    def test_character_list(self):
        """
        Tests List
        """
        view = RepresentationCharacterDataList.as_view()
        request = self.request_factory.get(
            reverse('representation_data_character')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len( content.get('character')), 5)

    def test_save_representation_method(self):
        self.assertEqual(len(Representation.objects.all()), 0)
        representation_save_process = RepresentationSaveProcess()
        project = self.insert_project()
        representation_save_process.representation = representation_save_process.get_representation()
        type_event = TypeEvent.objects.get(pk=2)

        representation_save_process.data_line = {
            'ppi': '2014-08-06',
            'ppg': '2014-08-21',
            'type_event': type_event.id
        }

        model_1 = Model.objects.get(pk=1)
        model_2 = Model.objects.get(pk=2)

        representation_save_process.data_models = [
            {
                'profile': 'perfil',
                'budget_cost': '1000',
                'character': {'id': 1, 'name': 'Extra'},
                'currency': {'symbol': '$', 'id': 2},
                'model': {'id': model_1.id},
                'model_name': 'jonathan carrasco'
            },
            {
                'profile': 'perfil2',
                'budget_cost': '200',
                'character': {'id': 1, 'name': 'Extra'},
                'currency': {'symbol': '$', 'id': 2},
                'model': {'id': model_2.id},
                'model_name': 'jonathan carrasco'
            }
        ]


        representation = representation_save_process.save_representation(project)
        representation_save_process.save_detail_model_representation(representation)

        self.assertEqual(len(Representation.objects.all()), 1)
        self.assertEqual(len(RepresentationDetailModel.objects.filter(representation=representation)), 2)
Ejemplo n.º 8
0
class GroupsTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.client = Client()
        self.insert_data = InsertDataHelper()
        self.insert_default_data()

    def insert_default_data(self):
        self.insert_data.run()
        self.user = User.objects.get(is_superuser=True)

    def create_group(self):
        group = Group()
        group.name = 'testGroup'
        group.save()

    def test_list_groups(self):
        view = AdminGroupListView.as_view()
        request = self.request_factory.get(
            reverse('admin_group_list')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 2)
        self.create_group()
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 3)

    def test_create_group(self):
        """
         Tests data: Create
         """
        self.assertEqual(Group.objects.all().count(), 2)
        data = {
            'name': 'groupTestCreate',
            'permission1': Permission.objects.get(pk=1).id,
            'permission2': Permission.objects.get(pk=2).id,
            'permission3': Permission.objects.get(pk=3).id
        }

        view = AdminGroupCreateView.as_view()
        request = self.request_factory.post(
            reverse('admin_group_create'), data
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Group.objects.all().count(), 3)
        group = Group.objects.get(name='groupTestCreate')
        self.assertEqual(group.permissions.all().count(), 3)

    def test_update_Group(self):
        group = Group.objects.get(pk=1)
        self.assertEqual(group.permissions.all().count(), 0)
        data = {
            'pk': group.id,
            'name': 'groupTestUpdate',
            'permission1': Permission.objects.get(pk=1).id,
            'permission2': Permission.objects.get(pk=2).id,
            'permission3': Permission.objects.get(pk=3).id
        }

        url_kwargs = {'pk': group.id}

        view = AdminGroupEditView.as_view()
        request = self.request_factory.post(
            reverse('admin_group_edit', kwargs=url_kwargs), data
        )
        request.user = self.user
        response = view(request, **data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Group.objects.all().count(), 2)
        group = Group.objects.get(name='groupTestUpdate')
        self.assertEqual(group.permissions.all().count(), 3)

    def test_delete_group(self):
        self.assertEqual(Group.objects.all().count(), 2)
        group = Group.objects.get(pk=1)
        data = {
            'deleteGroup': group.id,
        }

        view = AdminGroupDeleteView.as_view()
        request = self.request_factory.post(
            reverse('admin_group_delete'), data
        )
        request.user = self.user
        response = view(request, **data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Group.objects.all().count(), 1)
Ejemplo n.º 9
0
class CastingViewTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_project(self):
        project = Project()
        project.line_productions = Project.LINE_PHOTO
        project.code = '1'
        project.commercial = Commercial.objects.latest('created')
        project.version = '0'
        project.start_productions = '2014-08-1'
        project.end_productions = '2014-08-2'
        project.save()
        return project

    def test_data_required(self):
        self.assertTrue(len(TypeCasting.objects.all()) > 0)

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_character_data_list(self):
        """
        Tests List
        """
        view = CastingCharacterDataList.as_view()
        request = self.request_factory.get(
            reverse('casting_data_character')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len( content.get('character')), 2)

    def test_save_casting_method(self):
        self.assertEqual(len(Casting.objects.all()), 0)
        casting_save_process = CastingSaveProcess()
        project = self.insert_project()
        casting_save_process.casting = casting_save_process.get_casting()
        casting_save_process.data_line = {
            'ppi': '2014-07-01',
            'ppg': '2014-07-01',
            'type_casting': [
                {'id': 2, 'name': 'Archivo'},
                {'id': 3, 'name': 'Scouting'},
                {'id': 4, 'name': 'Callback'}
            ]
        }

        casting_save_process.data_models = [
            {
                'profile': 'perfil1',
                'scene': '1',
                'character':
                    {
                        'id': 0,
                        'name': 'Secundario'
                    },
                'feature': 'carracteristica 1',
                'budget': '100',
                'cant': 2,
                'type': [
                    {'id': 3, 'name': 'Scouting'},
                    {'id': 4, 'name': 'Callback'}
                ]
            },
            {
                'profile': 'perfil2',
                'scene': '',
                'character': {'id': 1, 'name': 'Principal'},
                'feature': 'test',
                'budget': '100',
                'cant': 2,
                'type': [
                    {'id': 3, 'name': 'Scouting'}
                ]
            }
        ]


        casting = casting_save_process.save_casting(project)
        casting_save_process.save_detail_model_casting(casting)

        self.assertEqual(len(Casting.objects.all()), 1)
        self.assertEqual(len(CastingDetailModel.objects.filter(casting=casting)), 2)
Ejemplo n.º 10
0
class BrandViewTest(TestCase):
    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_basic_data(self):
        """
        Tests data test insert correct
        """
        self.insert_test_data()
        self.assertTrue(Brand.objects.all().count() > 0)
        self.assertTrue(Entry.objects.all().count() > 0)

    def test_list_view_brand(self):
        """
        Tests data: List
        """
        self.insert_test_data()
        view = BrandListView.as_view()
        request = self.request_factory.get(reverse('brand_list'))
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 9)
        brand = Brand()
        brand.entry = Entry.objects.latest('id')
        brand.name = 'Brand Test'
        brand.save()
        response = view(request)
        self.assertEqual(response.context_data['object_list'].count(), 10)

    def test_list_view_brand_filter(self):
        """
        Tests data: Filter
        """
        self.insert_test_data()
        request = self.request_factory.get(reverse('brand_list'),
                                           data={'name__icontains': 'Sprite'})
        request.user = self.user
        view = BrandListView.as_view()
        response = view(request)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.context_data['object_list']), 1)

    def test_create_view_brand(self):
        """
        Tests data: Create
        """
        self.insert_test_data()
        self.assertEqual(Brand.objects.all().count(), 9)
        data = {
            'name': 'Brand test',
            'entry': Entry.objects.filter(name='Bancos')[0].id
        }
        view = BrandCreateView.as_view()
        request = self.request_factory.post(reverse('brand_create'), data)
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Brand.objects.all().count(), 10)

    def test_update_view_brand(self):
        """
        Tests data: Update
        """
        self.insert_test_data()
        self.assertEqual(Brand.objects.all().count(), 9)
        brand = Brand.objects.get(pk=1)

        request = self.request_factory.get(
            reverse('brand_edit', kwargs={'pk': brand.id}))
        request.user = self.user
        view = BrandUpdateView.as_view()
        response = view(request, pk=brand.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Brand.objects.all().count(), 9)
        self.assertEqual(brand.name, 'Coca Cola')
        #Post
        data = {
            'pk': brand.id,
            'name': "actualizado",
            'entry': Entry.objects.get(id=1).id
        }

        url_kwargs = {'pk': brand.id}
        url = reverse('brand_edit', kwargs=url_kwargs)
        request = self.request_factory.post(url, data=data)
        request.user = self.user
        view = BrandUpdateView.as_view()
        response = view(request, **data)

        brand = Brand.objects.get(pk=1)
        self.assertEqual(brand.name, 'actualizado')
        self.assertEqual(response.status_code, 302)

    def test_delete_view_brand(self):
        """
        Tests data: Delete
        """
        self.insert_test_data()
        self.assertEqual(Brand.objects.all().count(), 9)
        brand = Brand.objects.get(pk=1)

        kwargs = {'pk': brand.id}
        url = reverse('brand_delete', kwargs=kwargs)
        request = self.request_factory.post(url, kwargs)
        request.user = self.user
        response = BrandDeleteView.as_view()(request, **kwargs)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Brand.objects.all().count(), 8)
Ejemplo n.º 11
0
class ProjectViewTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def insert_project(self):
        project = Project()
        project.line_productions = Project.LINE_PHOTO
        project.code = '1'
        project.commercial = Commercial.objects.latest('created')
        project.version = '0'
        project.start_productions = '2014-08-1'
        project.end_productions = '2014-08-2'
        project.save()
        return project

    def test_basic_data(self):
        """
        Tests data test insert correct
        """
        self.assertTrue(Commercial.objects.all().count() > 0)
        self.assertTrue(Client.objects.all().count() > 0)

    def _test_list_view_project(self):
        """
        Tests data: List
        """
        view = ProjectListView.as_view()
        request = self.request_factory.get(
            reverse('project_list')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 4)

        self.insert_project()
        response = view(request)
        self.assertEqual(response.context_data['object_list'].count(), 5)

    def _test_list_view_project_filter_casting(self):
        """
        Tests data: Filter
        """
        request = self.request_factory.get(reverse('project_list'),
                                           data={'line_productions': Project.LINE_CASTING})
        request.user = self.user
        view = ProjectListView.as_view()
        response = view(request)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.context_data['project_list']), 4)

    def _test_list_view_project_filter_photo(self):
        """
        Tests data: Filter
        """
        self.insert_project()
        request = self.request_factory.get(reverse('project_list'),
                                           data={'line_productions': Project.LINE_PHOTO})
        request.user = self.user
        view = ProjectListView.as_view()
        response = view(request)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.context_data['project_list']), 1)

    def _test_list_view_project_filter_range_dates(self):
        """
        Tests data: Filter
        """
        self.insert_project()
        request = self.request_factory.get(reverse('project_list'),
                                           data={'start_date__gte': '01/07/2014',
                                                 'finish_date__lte': '02/07/2014'})
        request.user = self.user
        view = ProjectListView.as_view()
        response = view(request)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.context_data['project_list']), 1)

    def _test_minimal_create_project(self):
        self.assertEqual(Project.objects.all().count(), 4)
        url = reverse('project_save')

        commercial = Commercial.objects.get(pk=1)

        data = {
            'duty': {},
            'models': [],
            'commercial': {
                'dates': [
                    {
                        'date': '15/08/2014',
                        'id': 107
                    },
                    {
                        'date': '06/08/2014',
                        'id': 108
                    }
                ],
                'id': commercial.id,
                'name': 'new commercial'
            },
            'deliveries': [],
            'project':
                {
                    'start_productions': '07/08/2014',
                    'line_productions': 1,
                    'commercial': commercial.id,
                    'end_productions': '04/08/2014'
                },
            'client': {},
            'line': {},
            'payment': {
                'conditions': []
            },
            'resources': []
        }


        view = ProjectSaveJsonView.as_view()
        request = self.request_factory.post(
            url, data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), 'success')
        self.assertEqual(Project.objects.all().count(), 5)

    def _test_full_create_project(self):
        self.assertEqual(Project.objects.all().count(), 4)
        url = reverse('project_save')

        commercial = Commercial.objects.get(pk=1)
        client_director = Client.objects.get(pk=3)
        client_agency = Client.objects.get(pk=2)
        client_productor = Client.objects.get(pk=1)

        data = {
            'duty': {
                'duration_month': 3,
                'broadcasts': [
                    {
                        'id': 2,
                        'name': 'Web'
                    },
                    {
                        'id': 4,
                        'name': 'Cable'
                    }
                ],
                'type_contract': {
                    'id': 1,
                    'name':'Uso de imagen'
                }, 'countries': [
                    {
                        'nationality': 'Peruana',
                        'cities': [],
                        'id': 1,
                        'name': u'Per\xfa'
                    },
                    {
                        'nationality': 'Ucraniano',
                        'cities': [],
                        'id': 6,
                        'name': 'Ucrania'
                    },
                    {
                        'nationality': 'Argentino',
                        'cities': [],
                        'id': 7,
                        'name':'Argentina'
                    }
                ]
            },
            'models': [
                {
                    'profile': 'perfil',
                    'scene': '1',
                    'character': {'id': 1, 'name': 'Principal'},
                    'feature': 'carracteristicas',
                    'budget': '100',
                    'cant': 2,
                    'type': [
                        {'id': 1, 'name': 'Especifico'},
                        {'id': 2, 'name': 'Archivo'}
                    ]
                },
                {
                    'profile': 'perfil test',
                    'scene': '1',
                    'character': {'id': 0, 'name': 'Secundario'},
                    'feature': 'features',
                    'budget': '200',
                    'cant': 3,
                    'type': [
                        {'id': 2, 'name': 'Archivo'}
                    ]
                }
            ],
            'commercial': {
                'dates': [
                    {'date': '15/08/2014'},
                    {'date': '06/08/2014'}
                ], 'name': 'new commercial',
                'id': commercial.id
            },
            'deliveries': [
                {'date': '01/08/2014'},
                {'date': '02/08/2014'},
                {'date': '12/08/2014'}
            ],
            'project':
                {
                    'end_productions': '07/08/2014',
                    'budget_cost': '800',
                    'line_productions': 1,
                    'commercial': commercial.id,
                    'budget': '1000',
                    'currency': 2,
                    'observations':'Mis observaciones',
                    'start_productions': '01/08/2014'
                },
            'client': {
                'director': client_director.id,
                'agency': client_agency.id,
                'productor': client_productor.id
            },
            'line': {},
            'payment':
                {
                    'client': client_director.id,
                    'conditions': ['condicion1', 'condicion2']
                },
            'resources': []
        }


        view = ProjectSaveJsonView.as_view()
        request = self.request_factory.post(
            url, data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), 'success')
        self.assertEqual(Project.objects.all().count(), 5)

    def _test_save_duty_none(self):
        self.assertEqual(Project.objects.all().count(), 4)
        url = reverse('project_save')

        commercial = Commercial.objects.get(pk=1)
        client_director = Client.objects.get(pk=3)
        client_agency = Client.objects.get(pk=2)
        client_productor = Client.objects.get(pk=1)

        data = {
            'duty': {},
            'models': [
                {
                    'profile': 'perfil',
                    'scene': '1',
                    'character': {'id': 1, 'name': 'Principal'},
                    'feature': 'carracteristicas',
                    'budget': '100',
                    'cant': 2,
                    'type': [
                        {'id': 1, 'name': 'Especifico'},
                        {'id': 2, 'name': 'Archivo'}
                    ]
                },
                {
                    'profile': 'perfil test',
                    'scene': '1',
                    'character': {'id': 0, 'name': 'Secundario'},
                    'feature': 'features',
                    'budget': '200',
                    'cant': 3,
                    'type': [
                        {'id': 2, 'name': 'Archivo'}
                    ]
                }
            ],
            'commercial': {
                'dates': [
                    {'date': '15/08/2014'},
                    {'date': '06/08/2014'}
                ], 'name': 'new commercial',
                'id': commercial.id
            },
            'deliveries': [
                {'date': '01/08/2014'},
                {'date': '02/08/2014'},
                {'date': '12/08/2014'}
            ],
            'project':
                {
                    'end_productions': '07/08/2014',
                    'budget_cost': '800',
                    'line_productions': 1,
                    'commercial': commercial.id,
                    'budget': '1000',
                    'currency': 2,
                    'observations':'Mis observaciones',
                    'start_productions': '01/08/2014'
                },
            'client': {
                'director': client_director.id,
                'agency': client_agency.id,
                'productor': client_productor.id
            },
            'line': {},
            'payment':
                {
                    'client': client_director.id,
                    'conditions': ['condicion1', 'condicion2']
                },
            'resources': []
        }


        view = ProjectSaveJsonView.as_view()
        request = self.request_factory.post(
            url, data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), 'success')
        self.assertEqual(Project.objects.all().count(), 5)

    def test_update_project(self):
        self.assertEqual(Project.objects.all().count(), 4)
        url = reverse('project_update')
        project = self.insert_project()
        casting = Casting()
        casting.project = project
        casting.save()
        self.assertEqual(Project.objects.all().count(), 5)

        commercial = Commercial.objects.get(pk=1)
        client_director = Client.objects.get(pk=3)
        client_agency = Client.objects.get(pk=2)
        client_productor = Client.objects.get(pk=1)

        data = {
            'duty': {},
            'models': [
                {
                    'profile': 'perfil',
                    'scene': '1',
                    'character': {'id': 1, 'name': 'Principal'},
                    'feature': 'carracteristicas',
                    'budget': '100',
                    'cant': 2,
                    'type': [
                        {'id': 1, 'name': 'Especifico'},
                        {'id': 2, 'name': 'Archivo'}
                    ]
                },
                {
                    'profile': 'perfil test',
                    'scene': '1',
                    'character': {'id': 0, 'name': 'Secundario'},
                    'feature': 'features',
                    'budget': '200',
                    'cant': 3,
                    'type': [
                        {'id': 2, 'name': 'Archivo'}
                    ]
                }
            ],
            'commercial': {
                'dates': [
                    {'date': '15/08/2014'},
                    {'date': '06/08/2014'}
                ], 'name': 'new commercial',
                'id': commercial.id
            },
            'deliveries': [
                {'date': '01/08/2014'},
                {'date': '02/08/2014'},
                {'date': '12/08/2014'}
            ],
            'project':
                {
                    'end_productions': '07/08/2014',
                    'budget_cost': '800',
                    'line_productions': 1,
                    'commercial': commercial.id,
                    'budget': '1000',
                    'currency': 2,
                    'observations':'Mis observaciones',
                    'start_productions': '01/08/2014'
                },
            'client': {
                'director': client_director.id,
                'agency': client_agency.id,
                'productor': client_productor.id
            },
            'line': {},
            'project_id': project.id,
            'payment':
                {
                    'client': client_director.id,
                    'conditions': ['condicion1', 'condicion2']
                },
            'resources': []
        }


        view = ProjectUpdateJsonView.as_view()
        request = self.request_factory.post(
            url, data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), 'success')
        self.assertEqual(Project.objects.all().count(), 5)
Ejemplo n.º 12
0
class ClientViewTest(TestCase):
    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_basic_data(self):
        """
        Tests data test insert correct
        """
        self.assertTrue(TypeClient.objects.all().count() > 0)
        self.assertTrue(Client.objects.all().count() > 0)

    def test_list_view_client(self):
        """
        Tests data: List
        """
        view = ClientListView.as_view()
        request = self.request_factory.get(reverse("client_list"))
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data["object_list"].count(), 3)

        client = Client()
        client.name = "Client Test"
        client.ruc = "2345654321"
        client.address = "Direccion"
        client.save()
        response = view(request)
        self.assertEqual(response.context_data["object_list"].count(), 4)

    def test_list_view_brand_filter(self):
        """
        Tests data: Filter
        """
        request = self.request_factory.get(reverse("brand_list"), data={"name__icontains": "Produc"})
        request.user = self.user
        view = ClientListView.as_view()
        response = view(request)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(response.context_data["object_list"]), 1)

    def test_create_view_brand(self):
        """
        Tests data: Create
        """
        self.assertEqual(Client.objects.all().count(), 3)

        data = {
            "name": "Brand test",
            "ruc": "2323232323",
            "address": "mi direccion",
            "type_client": [TypeClient.objects.get(name="Productora").id],
        }
        view = ClientCreateView.as_view()
        request = self.request_factory.post(reverse("client_create"), data)
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Client.objects.all().count(), 4)

    def test_update_view_brand(self):
        """
        Tests data: Update
        """
        self.assertEqual(Client.objects.all().count(), 3)
        client = Client.objects.get(name="Productora")

        request = self.request_factory.get(reverse("client_edit", kwargs={"pk": client.id}))
        request.user = self.user
        view = ClientUpdateView.as_view()
        response = view(request, pk=client.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Client.objects.all().count(), 3)
        self.assertEqual(client.name, "Productora")
        # Post
        data = {
            "pk": client.id,
            "name": "actualizado",
            "ruc": "2323232323",
            "address": "mi direccion",
            "type_client": [TypeClient.objects.get(name="Productora").id],
        }

        url_kwargs = {"pk": client.id}
        url = reverse("client_edit", kwargs=url_kwargs)
        request = self.request_factory.post(url, data=data)
        request.user = self.user
        view = ClientUpdateView.as_view()
        response = view(request, **data)

        client = Client.objects.get(pk=1)
        self.assertEqual(client.name, "actualizado")
        self.assertEqual(response.status_code, 302)

    def test_delete_view_brand(self):
        """
        Tests data: Delete
        """
        self.insert_test_data()
        self.assertEqual(Client.objects.all().count(), 3)
        brand = Client.objects.get(pk=1)

        kwargs = {"pk": brand.id}
        url = reverse("brand_delete", kwargs=kwargs)
        request = self.request_factory.post(url, kwargs)
        request.user = self.user
        response = ClientDeleteView.as_view()(request, **kwargs)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Client.objects.all().count(), 2)

    def test_data_list(self):
        """
        Tests List
        """
        self.insert_test_data()
        view = ClientDataListView.as_view()
        request = self.request_factory.get(reverse("client_data_list"))
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len(content.get("client")), 3)
        client = Client()
        client.name = "Client Test"
        client.ruc = "2345654321"
        client.address = "Direccion"
        client.save()
        response = view(request)
        content = json.loads(response._container[0])
        self.assertEqual(len(content.get("client")), 4)

    def test_create_json(self):
        self.insert_test_data()
        self.assertEqual(Client.objects.all().count(), 3)
        type_client = TypeClient.objects.get(pk=1)
        data = {
            "ruc": "1233212334",
            "type": [{"id": type_client.id, u"name": type_client.name}],
            "name": "razon",
            "address": "direccion",
        }

        view = ClientCreateDataJson.as_view()
        request = self.request_factory.post(
            reverse("client_json_create"), data=dumps(data), content_type="application/json"
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(content.get("status"), "success")
        self.assertEqual(Client.objects.all().count(), 4)
Ejemplo n.º 13
0
class ExtraViewTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_project(self):
        project = Project()
        project.line_productions = Project.LINE_PHOTO
        project.code = '1'
        project.commercial = Commercial.objects.latest('created')
        project.version = '0'
        project.start_productions = '2014-08-1'
        project.end_productions = '2014-08-2'
        project.save()
        return project

    def test_data_required(self):
        self.assertTrue(len(Currency.objects.all()) > 0)

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_character_data_list(self):
        """
        Tests List
        """
        view = ExtraCharacterDataList.as_view()
        request = self.request_factory.get(
            reverse('extra_data_character')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len( content.get('character')), 2)

    def test_save_casting_method(self):
        self.assertEqual(len(Extras.objects.all()), 0)
        extra_save_process = ExtraSaveProcess()
        project = self.insert_project()
        extra_save_process.extras = extra_save_process.get_extras()
        extra_save_process.data_line = {
        }

        extra_save_process.data_models = [
            {
                'profile': 'perfil',
                'budget_cost': '100',
                'schedule': '12:00',
                'character': {'id': 0, 'name': 'Extra especial'},
                'feature': 'carracteristicas',
                'currency': {
                    'symbol': '$',
                    'id': 2
                },
                'cant': 2
            },
            {
                'profile': 'perfil2',
                'budget_cost': '100',
                'schedule': '12:00',
                'character': {'id': 0, 'name': 'Extra especial'},
                'feature': 'test',
                'currency': {'symbol': '$', 'id': 2},
                'cant': 2
            }
        ]

        extra = extra_save_process.save_extra(project)
        extra_save_process.save_detail_model_extra(extra)

        self.assertEqual(len(Extras.objects.all()), 1)
        self.assertEqual(len(ExtrasDetailModel.objects.filter(extras=extra)), 2)
Ejemplo n.º 14
0
class UsersTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.client = Client()
        self.insert_data = InsertDataHelper()
        self.insert_default_data()

    def insert_default_data(self):
        self.insert_data.run()
        self.user = User.objects.get(is_superuser=True)

    def create_user(self):
        self.user = User()
        self.user.username = '******'
        self.user.set_password(uuid.uuid4().hex)
        self.user.email = '*****@*****.**'
        self.user.save()

    def test_list_users(self):
        """
        Tests data: List
        """
        view = AdminUserListView.as_view()
        request = self.request_factory.get(
            reverse('admin_user_list')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 1)
        self.create_user()
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data['object_list'].count(), 2)

    def test_create_user(self):
        """
         Tests data: Create
         """
        self.assertEqual(User.objects.all().count(), 1)
        data = {
            'username': '******',
            'first_name': '',
            'last_name': '',
            're_password': '******',
            'password': '******',
            'email': '*****@*****.**',
            'groups': []
        }

        view = AdminUserCreateView.as_view()
        request = self.request_factory.post(
            reverse('admin_user_create'), data
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(User.objects.all().count(), 2)

    def test_create_user_password_invalid(self):
        """
        Tests data: Create
        """
        self.assertEqual(User.objects.all().count(), 1)
        data = {
            'username': '******',
            'first_name': '',
            'last_name': '',
            're_password': '******',
            'password': '******',
            'email': '*****@*****.**',
            'groups': []
        }

        view = AdminUserCreateView.as_view()
        request = self.request_factory.post(
            reverse('admin_user_create'), data
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(User.objects.all().count(), 1)

    def test_update_state_user(self):
        self.assertEqual(self.user.is_active, True)
        url_kwargs = {'pk': self.user.id}
        url = reverse('admin_user_change_status', kwargs=url_kwargs)
        request = self.request_factory.get(url)
        request.user = self.user
        view = AdminUserChangeStatusRedirectView.as_view()
        response = view(request, pk=self.user.id)
        user = User.objects.get(is_superuser=True)
        self.assertEqual(user.is_active, False)
        self.assertEqual(response.status_code, 302)

    def test_update_user(self):
        """
        Tests data: Update
        """
        self.assertEqual(User.objects.all().count(), 1)
        user = User.objects.get(is_superuser=True)

        request = self.request_factory.get(reverse('admin_user_update',
                                                   kwargs={'pk': user.id}))
        request.user = self.user
        view = AdminUserUpdateView.as_view()
        response = view(request, pk=user.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(User.objects.all().count(), 1)
        self.assertEqual(user.first_name, '')
        #Post
        data = {
            'pk':  user.id,
            'username': '******',
            'first_name': 'administrador',
            'last_name': '',
            're_password': '******',
            'password': '******',
            'email': '*****@*****.**',
            'groups': []
        }

        url_kwargs = {'pk': user.id}
        url = reverse('admin_user_update', kwargs=url_kwargs)
        request = self.request_factory.post(url, data=data)
        request.user = self.user
        view = AdminUserUpdateView.as_view()
        response = view(request, **data)

        user = User.objects.get(is_superuser=True)
        self.assertEqual(user.first_name, 'administrador')
        self.assertEqual(response.status_code, 302)

    def test_assign_group_user(self):
        """
        Tests data: Update
        """
        user_group = self.user.groups.all()
        self.assertEqual(user_group.count(), 0)
        request = self.request_factory.get(reverse('admin_user_group_detail',
                                                   kwargs={'pk': self.user.id}))
        request.user = self.user
        view = AdminUserDetailView.as_view()
        response = view(request, pk=self.user.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(user_group.count(), 0)
        #Post
        data = {
            'pk': self.user.id,
            'group': Group.objects.get(pk=1).id
        }

        url_kwargs = {'pk': self.user.id}
        url = reverse('admin_user_group_detail', kwargs=url_kwargs)
        request = self.request_factory.post(url, data=data)
        request.user = self.user
        view = AdminUserDetailView.as_view()
        response = view(request, **data)

        user = User.objects.get(is_superuser=True)
        user_group = user.groups.all()
        self.assertEqual(user_group.count(), 1)
        self.assertEqual(response.status_code, 302)

    def test_permission_dashboard(self):
        #SuperAdmin
        view = SettingsTemplateView.as_view()
        request = self.request_factory.get(
            reverse('admin_settings')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        #Other User
        self.create_user()
        request.user = self.user
        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)
        response = view(request)
        self.assertEqual(response.status_code, 302)
Ejemplo n.º 15
0
class CastingViewTest(TestCase):
    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_project(self):
        project = Project()
        project.line_productions = Project.LINE_PHOTO
        project.code = '1'
        project.commercial = Commercial.objects.latest('created')
        project.version = '0'
        project.start_productions = '2014-08-1'
        project.end_productions = '2014-08-2'
        project.save()
        return project

    def test_data_required(self):
        self.assertTrue(len(TypeCasting.objects.all()) > 0)

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_character_data_list(self):
        """
        Tests List
        """
        view = CastingCharacterDataList.as_view()
        request = self.request_factory.get(reverse('casting_data_character'))
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len(content.get('character')), 2)

    def test_save_casting_method(self):
        self.assertEqual(len(Casting.objects.all()), 0)
        casting_save_process = CastingSaveProcess()
        project = self.insert_project()
        casting_save_process.casting = casting_save_process.get_casting()
        casting_save_process.data_line = {
            'ppi':
            '2014-07-01',
            'ppg':
            '2014-07-01',
            'type_casting': [{
                'id': 2,
                'name': 'Archivo'
            }, {
                'id': 3,
                'name': 'Scouting'
            }, {
                'id': 4,
                'name': 'Callback'
            }]
        }

        casting_save_process.data_models = [{
            'profile':
            'perfil1',
            'scene':
            '1',
            'character': {
                'id': 0,
                'name': 'Secundario'
            },
            'feature':
            'carracteristica 1',
            'budget':
            '100',
            'cant':
            2,
            'type': [{
                'id': 3,
                'name': 'Scouting'
            }, {
                'id': 4,
                'name': 'Callback'
            }]
        }, {
            'profile':
            'perfil2',
            'scene':
            '',
            'character': {
                'id': 1,
                'name': 'Principal'
            },
            'feature':
            'test',
            'budget':
            '100',
            'cant':
            2,
            'type': [{
                'id': 3,
                'name': 'Scouting'
            }]
        }]

        casting = casting_save_process.save_casting(project)
        casting_save_process.save_detail_model_casting(casting)

        self.assertEqual(len(Casting.objects.all()), 1)
        self.assertEqual(
            len(CastingDetailModel.objects.filter(casting=casting)), 2)
Ejemplo n.º 16
0
class ModelCreateTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.client = Client()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_template_model_create(self):
        self.assertEqual(Model.objects.all().count(), 4)
        view = ModelControlTemplateView.as_view()
        model = Model.objects.latest('created')
        request = self.request_factory.get(
            reverse('panel_model_control_list') + '?pk=' + str(model.model_code)
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context_data), 7)
        self.assertTrue('doc_types' in response.context_data)
        self.assertTrue('genders' in response.context_data)
        self.assertTrue('menu' in response.context_data)
        self.assertTrue('features' in response.context_data)
        self.assertTrue('id' in response.context_data)
        self.assertTrue('pk' in response.context_data)

    def test_get_model(self):
        view = ModelDataJsonView.as_view()
        model = Model.objects.latest('created')
        request = self.request_factory.get(
            reverse('panel_information_model', kwargs={'pk': model.model_code})
        )
        request.user = self.user
        response = view(request, pk=model.model_code)
        self.assertEqual(response.status_code, 200)
        data = json.loads(response.content)

        self.assertTrue('profile' in data)
        self.assertTrue('features' in data)
        self.assertTrue('commercial' in data)
        self.assertTrue('images' in data)

    def test_get_model_fail(self):
        view = ModelDataJsonView.as_view()
        request = self.request_factory.get(
            reverse('panel_information_model', kwargs={'pk': 876})
        )
        request.user = self.user
        response = view(request, pk=876)
        content = json.loads(response._container[0])
        self.assertEqual(response.status_code, 200)
        self.assertEqual(content.get('status'), "warning")

    def test_save_model(self):
        self.assertEqual(Model.objects.all().count(), 4)
        data = {
            "name_complete": "jonathancarrasco garcia",
            "type_doc": {"id": 1,"name": "DNI"},
            "num_doc": "46223224",
            "address": "Jr catalino Miranda 356",
            "email": "*****@*****.**",
            "birth": "1978-08-12",
            "nationality": 1,
            "city": 66,
            "phone_fixed": "256-1212",
            "phone_mobil": "963726756",
            "gender": 1
        }

        view = ModelCreateView.as_view()
        request = self.request_factory.post(
            reverse('panel_model_save_profile'), data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), "success")
        self.assertEqual(Model.objects.all().count(), 5)

    def test_update_model(self):
        self.assertEqual(Model.objects.all().count(), 4)
        model = Model.objects.latest('created')
        url = reverse('panel_model_update_profile',  kwargs={'pk': model.id})
        data = {
            "name_complete": "jonathancarrasco garcia",
            "type_doc": {"id": 1,"name": "DNI"},
            "num_doc": "46223224",
            "address": "Jr catalino Miranda 356",
            "email": "*****@*****.**",
            "birth": "1978-08-12",
            "nationality": 1,
            "city": 66,
            "phone_fixed": "256-1212",
            "phone_mobil": "963726756",
            "gender": 1
        }
        view = ModelUpdateView.as_view()
        request = self.request_factory.post(
            url, data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request, pk=model.id)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), "success")
        self.assertEqual(Model.objects.all().count(), 4)

    def test_save_features(self):
        model = Model.objects.latest('created')
        self.assertEqual(model.model_feature_detail_set.all().count(), 1)
        url = reverse('panel_model_save_feature',  kwargs={'pk': model.id})
        data = {
            "feature_value": {
                "value_id": 138,
                "value_name": "Facebook"
            }
        }
        view = ModelFeatureCreateView.as_view()
        request = self.request_factory.post(
            url, data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request, pk=model.id)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), 'success')
        self.assertEqual(model.model_feature_detail_set.all().count(), 2)

    def test_update_features(self):
        model = Model.objects.latest('created')
        self.assertEqual(model.model_feature_detail_set.all().count(), 1)
        model_feature_detail = ModelFeatureDetail()
        model_feature_detail.model = model
        model_feature_detail.feature_value = FeatureValue.objects.get(pk=139)
        model_feature_detail.description = 'Facebook'
        model_feature_detail.save()

        url = reverse('panel_model_update_feature',  kwargs={'pk': model.id})
        data = {
                "feature": {
                    "value_id": 139,
                    "value_name": "Twitter"
                },
            "description": "olalal",
            "model_feature_id": model_feature_detail.id
        }
        view = ModelFeatureUpdateView.as_view()
        request = self.request_factory.post(
            url, data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request, pk=model.id)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), 'success')
        self.assertEqual(model.model_feature_detail_set.all().count(), 2)

    def test_delete_features(self):
        model = Model.objects.latest('created')
        model_feature_detail = ModelFeatureDetail()
        model_feature_detail.model = model
        model_feature_detail.feature_value = FeatureValue.objects.get(pk=139)
        model_feature_detail.description = 'Facebook'
        model_feature_detail.save()
        self.assertEqual(model.model_feature_detail_set.all().count(), 2)

        url = reverse('panel_model_delete_feature')
        data = str(model_feature_detail.id)
        view = ModelFeatureDeleteView.as_view()
        request = self.request_factory.post(
            url, data=dumps(data), content_type='application/json'
        )
        request.user = self.user
        response = view(request)
        content = json.loads(response._container[0])
        self.assertEqual(content.get('status'), 'success')
        self.assertEqual(model.model_feature_detail_set.all().count(), 1)
Ejemplo n.º 17
0
class PhotoCastingViewTest(TestCase):

    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_project(self):
        project = Project()
        project.line_productions = Project.LINE_PHOTO
        project.code = '1'
        project.commercial = Commercial.objects.latest('created')
        project.version = '0'
        project.start_productions = '2014-08-1'
        project.end_productions = '2014-08-2'
        project.save()
        return project

    def test_data_required(self):
        self.assertTrue(len(UsePhotos.objects.all()) > 0)
        self.assertTrue(len(TypePhotoCasting.objects.all()) > 0)

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_type_casting_list(self):
        """
        Tests List
        """
        view = TypePhotoCastingDataList.as_view()
        request = self.request_factory.get(
            reverse('photo_casting_data_types')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len( content.get('types')), 3)

    def test_use_photo_list(self):
        """
        Tests List
        """
        view = UsePhotoDataList.as_view()
        request = self.request_factory.get(
            reverse('photo_casting_use_photos')
        )
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len( content.get('uses')), 10)

    def test_save_photo_casting_method(self):
        self.assertEqual(len(PhotoCasting.objects.all()), 0)
        photo_casting_save_process = PhotoCastingSaveProcess()
        project = self.insert_project()
        photo_casting_save_process.photo_casting = photo_casting_save_process.get_photo_casting()
        photo_casting_save_process.data_line = {
            'type_casting': 2,
            'uses': [
                {'id': 1, 'name': 'Todo Uso'},
                {'id': 2, 'name': 'Paneles'}
            ]
        }

        photo_casting_save_process.data_models = [
            {
                'profile': 'perfil',
                'budget_cost': '100',
                'character': {'id': 1, 'name': 'Principal'},
                'feature': 'carracteristicas',
                'currency': {'symbol': '$', 'id': 2},
                'cant': 2,
                'observations': 'observacio es'
            },
            {
                'profile': 'test',
                'budget_cost': '200',
                'character': {'id': 1, 'name': 'Principal'},
                'feature': 'features',
                'currency': {'symbol': '$', 'id': 2},
                'cant': 1
            }
        ]


        photo = photo_casting_save_process.save_photo(project)
        photo_casting_save_process.save_detail_model_photo(photo)

        self.assertEqual(len(PhotoCasting.objects.all()), 1)
        self.assertEqual(len(PhotoCastingDetailModel.objects.filter(photo_casting=photo)), 2)
Ejemplo n.º 18
0
 def setUp(self):
     self.request_factory = RequestFactory()
     self.client = Client()
     self.insert_data = InsertDataHelper()
     self.insert_default_data()
Ejemplo n.º 19
0
class RepresentationViewTest(TestCase):
    def setUp(self):
        self.request_factory = RequestFactory()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_project(self):
        project = Project()
        project.line_productions = Project.LINE_PHOTO
        project.code = '1'
        project.commercial = Commercial.objects.latest('created')
        project.version = '0'
        project.start_productions = '2014-08-1'
        project.end_productions = '2014-08-2'
        project.save()
        return project

    def test_data_required(self):
        self.assertTrue(len(Model.objects.all()) > 0)

    def insert_test_data(self):
        self.insert_data_helper.run()
        self.user = User.objects.get(is_superuser=True)

    def test_event_list(self):
        """
        Tests List
        """
        view = RepresentationEventsDataList.as_view()
        request = self.request_factory.get(
            reverse('representation_data_event'))
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len(content.get('events')), 4)

    def test_character_list(self):
        """
        Tests List
        """
        view = RepresentationCharacterDataList.as_view()
        request = self.request_factory.get(
            reverse('representation_data_character'))
        request.user = self.user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response._container[0])
        self.assertEqual(len(content.get('character')), 5)

    def test_save_representation_method(self):
        self.assertEqual(len(Representation.objects.all()), 0)
        representation_save_process = RepresentationSaveProcess()
        project = self.insert_project()
        representation_save_process.representation = representation_save_process.get_representation(
        )
        type_event = TypeEvent.objects.get(pk=2)

        representation_save_process.data_line = {
            'ppi': '2014-08-06',
            'ppg': '2014-08-21',
            'type_event': type_event.id
        }

        model_1 = Model.objects.get(pk=1)
        model_2 = Model.objects.get(pk=2)

        representation_save_process.data_models = [{
            'profile':
            'perfil',
            'budget_cost':
            '1000',
            'character': {
                'id': 1,
                'name': 'Extra'
            },
            'currency': {
                'symbol': '$',
                'id': 2
            },
            'model': {
                'id': model_1.id
            },
            'model_name':
            'jonathan carrasco'
        }, {
            'profile':
            'perfil2',
            'budget_cost':
            '200',
            'character': {
                'id': 1,
                'name': 'Extra'
            },
            'currency': {
                'symbol': '$',
                'id': 2
            },
            'model': {
                'id': model_2.id
            },
            'model_name':
            'jonathan carrasco'
        }]

        representation = representation_save_process.save_representation(
            project)
        representation_save_process.save_detail_model_representation(
            representation)

        self.assertEqual(len(Representation.objects.all()), 1)
        self.assertEqual(
            len(
                RepresentationDetailModel.objects.filter(
                    representation=representation)), 2)
Ejemplo n.º 20
0
 def setUp(self):
     self.request_factory = RequestFactory()
     self.insert_data_helper = InsertDataHelper()
     self.insert_test_data()
Ejemplo n.º 21
0
 def setUp(self):
     self.request_factory = RequestFactory()
     self.insert_data_helper = InsertDataHelper()
     self.insert_test_data()
Ejemplo n.º 22
0
class SearchLogicTest(TestCase):

    def setUp(self):
        self.search = Search()
        self.insert_data_helper = InsertDataHelper()
        self.insert_test_data()

    def insert_test_data(self):
        self.insert_data_helper.run()

    def test_data_inserted(self):
        _count_model = Model.objects.all().count()
        _count_model_feature = ModelFeatureDetail.objects.all().count()
        self.assertTrue(_count_model > 0)
        self.assertTrue(_count_model_feature > 0)

    def test_basic_search(self):
        data = {'text': 'Jonathan'}
        self.search.set_type(Search.TYPE_BASIC)

        #Name
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 2)

        #Not found
        self.search = Search()
        data = {'text': 'cualquiera'}
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 0)

        #Lastname
        self.search = Search()
        data = {'text': 'de la cruz'}
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 1)

        #Number
        self.search = Search()
        data = {'text': '96372543756'}
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 1)

        #Name and LastName
        self.search = Search()
        data = {'text': 'Jonathan perez'}
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 2)

        #ExactName and LastName
        self.search = Search()
        data = {'text': 'Jonathan perez'}
        self.search.set_mode(Search.MODE_SENSITIVE)
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 1)

        #ExactName and LastName
        self.search = Search()
        data = {'text': '96372543756 perez'}
        self.search.set_mode(Search.MODE_SENSITIVE)
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 0)

    def test_advance_search_features(self):
        model = Model.objects.latest('created')
        model_features = model.model_feature_detail_set.all()
        data = {
            'advance': [],
            'features': [
                {
                    'id': model_features[0].feature_value.id,
                    'text': 'Tipo-de-cabello-Lacio',
                    'feature': True
                }
            ]
        }
        self.search.set_type(Search.TYPE_ADVANCE)
        #Features
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 2)

    def test_advance_search_age(self):
        data = {
            'advance': [
                {
                    'camp': 'sp_model.birth',
                    'id': ['15', '25'],
                    'feature': False
                }
            ],
            'features': []
        }
        self.search.set_type(Search.TYPE_ADVANCE)
        #Age
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 2)

    def test_advance_search_feature_params(self):
        model = Model.objects.latest('created')
        model_features = model.model_feature_detail_set.all()
        data = {
            'advance': [
                {
                    'camp': 'sp_model.birth',
                    'id': ['15', '25'],
                    'feature': False
                }
            ],
            'features': [
                {
                    'id': model_features[0].feature_value.id,
                    'text': 'Tipo-de-cabello-Lacio',
                    'feature': True
                }
            ]
        }
        self.search.set_type(Search.TYPE_ADVANCE)
        #Features and Age
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 1)

    def test_advance_search_web_casting(self):
        model = Model.objects.latest('created')
        model_features = model.model_feature_detail_set.all()
        data = {
            'advance': [
                {
                    'camp': 'sp_model.last_visit',
                    'id': False,
                    'feature': False
                }
            ],
            'features': []
        }
        self.search.set_type(Search.TYPE_ADVANCE)
        #Features and Age
        self.search.set_params(data)
        result = self.search.run()
        self.assertEquals(len(result), 3)
Ejemplo n.º 23
0
 def setUp(self):
     self.tab_facebook_task = TabFacebookTask()
     insert_data_helper = InsertDataHelper()
     insert_data_helper.run()