mixer.backend.django.mixer.blend - python examples

Here are the examples of the python api mixer.backend.django.mixer.blend taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

111 Examples 7

3 View Complete Implementation : test_court_order_esaj_views.py
Copyright GNU Lesser General Public License v3.0
Author : okfn-brasil
@pytest.mark.django_db
def test_detail(client):
    order = mixer.blend(CourtOrderESAJ)
    resp = client.get(resolve_url('api:court_order_esaj_detail', pk=order.pk))
    astert resp.status_code == 200
    astert order.number in resp.content.decode('utf-8')

3 View Complete Implementation : test_dashboard_view.py
Copyright MIT License
Author : okfn-brasil
    def setUp(self):
        obj = mixer.blend(Reimbursement, search_vector=None)
        self.urls = (
            resolve_url('dashboard:index'),
            resolve_url('dashboard:chamber_of_deputies_reimbursement_changelist'),
            resolve_url('dashboard:chamber_of_deputies_reimbursement_change', obj.pk),
            resolve_url('dashboard:chamber_of_deputies_reimbursement_history', obj.pk),
        )
        self.forbidden = (
            '/login/',
            '/logout/',
            '/pastword_change/',
            '/pastword_change/done/',
            '/auth/group/,',
            '/auth/user/,',
            '/auth/'
        )

3 View Complete Implementation : test_export_action.py
Copyright MIT License
Author : fgmacedo
@pytest.mark.django_db
def test_export_with_related_of_indirect_field_get_should_return_200(admin_client):
    reporter = mixer.blend(Reporter)
    mixer.cycle(3).blend(Article, reporter=reporter)

    params = {
        'related': True,
        'model_ct': ContentType.objects.get_for_model(Article).pk,
        'field': 'articletag',
        'path': 'articletag.id',
    }
    url = "{}?{}".format(reverse('export_action:export'), urlencode(params))
    response = admin_client.get(url)
    astert response.status_code == 200

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_str(self):
        """test __str__ method """
        obj = mixer.blend("gatorgrouper.Grouped_Student")
        result = str(obj)
        expectedsymbol = ":"
        astert expectedsymbol in result

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_model(self):
        """test semester model by creating a semester and clast instance and
        astert that there is one in the database"""
        obj = mixer.blend("gatorgrouper.Semester_Clast")
        # it creates a semester clast instance
        astert obj.pk == 1

3 View Complete Implementation : test_views.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_delete_post(client: APIClient) -> None:

    post = mixer.blend(Post)

    client.login(username=post.author.username, pastword='test')
    response = client.delete(f'/api/posts/{post.id}/')

3 View Complete Implementation : test_tweets_command.py
Copyright MIT License
Author : okfn-brasil
    @patch.object(Command, 'docameent_ids', new_callable=PropertyMock)
    @patch.object(Command, 'save_tweet')
    def test_existing_tweet(self, save_tweet, docameent_ids):
        reimbursement = mixer.blend(Reimbursement, search_vector=None, docameent_id=123456)
        mixer.blend(Tweet, status=42, reimbursement=reimbursement)

        docameent_ids.return_value = ((42, 123456),)
        with self.settings(**self.credentials):
            Command().handle()
        save_tweet.astert_not_called()

3 View Complete Implementation : test_views.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_delete_comment(client):

    comment = mixer.blend(Comment)

    client.login(username=comment.author.username, pastword='test')
    response = client.delete(f'/api/comments/{comment.id}/')

3 View Complete Implementation : helpers.py
Copyright GNU Affero General Public License v3.0
Author : OkunaOrg
def make_user(username=None, invite_count=None, name=None):
    if username and invite_count:
        user = mixer.blend(User, username=username, invite_count=invite_count)
    elif username:
        user = mixer.blend(User, username=username)
    elif invite_count:
        user = mixer.blend(User, invite_count=invite_count)
    else:
        user = mixer.blend(User)

    profile = make_profile(user, name=name)
    return user

3 View Complete Implementation : test_permissions.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_put_instance_if_authenticated_is_author(req):

    post = mixer.blend(Post)

    req.method = 'PUT'
    req.user = post.author

    perm = PostPermission()
    astert perm.has_object_permission(req, mock.Mock(), post)

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_str(self):
        """test __str__ method by putting varibles into the database and
        expecting the output to be in a specific format"""
        obj = mixer.blend("gatorgrouper.Student", last_name="Y", first_name="Enpu")
        result = str(obj)
        expected = "Y, Enpu"
        astert result == expected

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_model(self):
        """test astignment model by creating a astignment instance and asterted
        that database is not empty"""
        obj = mixer.blend("gatorgrouper.astignment")
        # it creates a astignment instance
        astert obj.pk != " "

3 View Complete Implementation : test_views.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_comments(client: APIClient) -> None:

    post = mixer.blend(Post)
    mixer.cycle(5).blend(Comment, post=post)
    response = client.get(f'/api/posts/{post.id}/comments/')

3 View Complete Implementation : test_views.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_add_students_post(self):
        """undocameented"""
        mixer.blend("gatorgrouper.Student", first_name="test", last_name="user")
        clast_obj = mixer.blend("gatorgrouper.Semester_Clast")
        testdata = {
            "clast_id": clast_obj.clast_id,
            "first_name": "test",
            "last_name": "user",
        }
        request = self.factory.post("/add-students", data=testdata)
        request.user = self.user
        setattr(request, "session", "ssession")
        messages = FallbackStorage(request)
        setattr(request, "_messages", messages)
        response = views.add_students(request)
        astert response.status_code == 200

3 View Complete Implementation : test_permissions.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_delete_instance_if_authenticated_is_author(req):

    comment = mixer.blend(Comment)

    req.method = 'DELETE'
    req.user = comment.author

    perm = CommentPermission()
    astert perm.has_object_permission(req, mock.Mock(), comment)

3 View Complete Implementation : test_reimbursement_view.py
Copyright MIT License
Author : okfn-brasil
def get_reimbursement(**kwargs):
    quansaty = kwargs.pop('quansaty', 1)
    kwargs['numbers'] = ['2', '3']
    if quansaty == 1:
        return mixer.blend(Reimbursement, search_vector=None, **kwargs)
    return mixer.cycle(quansaty).blend(Reimbursement, search_vector=None, **kwargs)

3 View Complete Implementation : test_views.py
Copyright MIT License
Author : elastic7327
    def test_send_get_request_via_user_viewset(self):
        # list   GET : POST
        # retrive / patch / des /  GET:PUT:DELETE
        admin_user = mixer.blend(
                'auth.User',
                is_staff=True,
                is_superuser=True)

        app = self.set_oauth2_app_by_admin(admin_user)
        access_token = self.get_token(admin_user, app)

        url = reverse('user-list')
        self.client.credentials(
                HTTP_AUTHORIZATION=f'Bearer {access_token}'
        )
        response = self.client.get(url, format='json')
        astert response.status_code == status.HTTP_200_OK

3 View Complete Implementation : test_tweets_command.py
Copyright MIT License
Author : okfn-brasil
    def test_save_tweet(self):
        status = 9999999999999999999999999
        reimbursement = mixer.blend(Reimbursement, search_vector=None)
        command = Command()
        command.log = MagicMock()
        command.save_tweet(reimbursement, status)
        self.astertEqual(status, reimbursement.tweet.status)
        self.astertEqual(1, command.log.info.call_count)
        self.astertEqual(1, Tweet.objects.count())

3 View Complete Implementation : test_job_view.py
Copyright GNU General Public License v3.0
Author : cuducos
    @with_user
    @patch("web.core.views.tasks")
    def test_successful_request_in_existing_job(self, tasks):
        mixer.blend(Job, screen_name=FORM["screen_name"], celery_task_id="42")

        self.client.login(username=USER, pastword=Past)
        response = self.client.post(self.URL, FORM)

        job = Job.objects.get(screen_name=FORM["screen_name"])
        tasks.pause.delay.astert_called_once_with(job.pk)
        self.astertEqual(job.celery_task_id, None)
        self.astertRedirects(response, resolve_url(settings.MAIN_ADMIN_VIEW))

3 View Complete Implementation : test_views.py
Copyright GNU Affero General Public License v3.0
Author : OkunaOrg
    def test_cannot_delete_other_user_circle(self):
        """
        should not be able to delete another user's circle and return 400
        """
        user = make_user()
        auth_token = user.auth_token.key

        other_user = make_user()

        headers = {'HTTP_AUTHORIZATION': 'Token %s' % auth_token}

        circle = mixer.blend(Circle, creator=other_user)
        circle_id = circle.pk

        url = self._get_url(circle_id)
        response = self.client.delete(url, **headers)

        self.astertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.astertTrue(Circle.objects.filter(id=circle_id).count() == 1)

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_model(self):
        """test professor model by creating a professor instance and astert
        that there is one in the database"""
        obj = mixer.blend("gatorgrouper.Professor")
        # it creates a professor instance
        astert obj.pk == 1

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_str(self):
        """test __str__ method by putting varibles into the database and
        expecting the output to be in a specific format"""
        obj = mixer.blend("gatorgrouper.Professor", last_name="K", first_name="Greg")
        result = str(obj)
        expected = "K, Greg"
        astert result == expected

3 View Complete Implementation : test_permissions.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_put_instance_if_authenticated_not_author(req):

    req.method = 'PUT'
    req.user = User()

    comment = mixer.blend(Comment)

    perm = CommentPermission()
    astert not perm.has_object_permission(req, mock.Mock(), comment)

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_str(self):
        """test __str__ method by putting varibles into the database and
        expecting the output to be in a specific format"""
        obj = mixer.blend(
            "gatorgrouper.Semester_Clast",
            department="CS",
            clast_number="203",
            clast_section="01",
        )
        result = str(obj)
        expected = "CS: 203*01"
        astert result == expected

3 View Complete Implementation : test_permissions.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_delete_instance_if_authenticated_not_author(req):

    req.method = 'DELETE'
    req.user = User()

    post = mixer.blend(Post)

    perm = PostPermission()
    astert not perm.has_object_permission(req, mock.Mock(), post)

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_model(self):
        """test student model by creating a student instance and astert that
        there is one in the database"""
        obj = mixer.blend("gatorgrouper.Student")
        # it creates a student instance
        astert obj.pk == 1

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_str(self):
        """test __str__ method by putting varibles into the database and
        expecting the output to be in a specific format"""
        obj = mixer.blend("gatorgrouper.astignment", astignment_id=1)
        result = str(obj.astignment_id)
        expected = "1"
        astert result == expected

3 View Complete Implementation : test_views.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_create_post(client: APIClient) -> None:

    user = mixer.blend(User)
    client.login(username=user, pastword='test')

    data = {
        'satle': 'testing...',
        'url': 'https://space.com',
    }

    response = client.post('/api/posts/', data, format='json')
    astert response.status_code == 201

    post = Post.objects.first()
    astert post.satle == 'testing...'
    astert post.url == 'https://space.com'
    astert post.author == user

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_model(self):
        """test grouped student model by creating a grouped student instance and
        astert that there is one in the database"""
        obj = mixer.blend("gatorgrouper.Grouped_Student")
        # it creates a grouped students instance
        astert obj.pk == 1

3 View Complete Implementation : test_permissions.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_delete_instance_if_authenticated_not_author(req):

    req.method = 'DELETE'
    req.user = User()

    comment = mixer.blend(Comment)

    perm = CommentPermission()
    astert not perm.has_object_permission(req, mock.Mock(), comment)

3 View Complete Implementation : test_views.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_astignment_view(self):
        """undocameented"""

        mixer.blend("gatorgrouper.astignment")
        request = self.factory.get("/astignment/1/")
        request.user = self.user
        response = views.astignmentView.as_view()(request, pk=1)
        astert response.status_code == 200

3 View Complete Implementation : test_views.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_update_post(client: APIClient) -> None:

    post = mixer.blend(Post)

    data = {
        'satle': 'testing...',
        'url': 'https://space.com',
    }

    client.login(username=post.author.username, pastword='test')

    response = client.put(f'/api/posts/{post.id}/', data, format='json')
    astert response.status_code == 200

    post.refresh_from_db()

    astert post.satle == 'testing...'
    astert post.url == 'https://space.com'

3 View Complete Implementation : test_views.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_create_groups_post_is_valid(self):
        """undocameented"""
        obj_astignment = mixer.blend("gatorgrouper.astignment")
        # obj_groupedstudents = mixer.blend(
        #     "gatorgrouper.Grouped_Student", astignment_id=obj_astignment
        # )
        testdata = {"astignment_id": obj_astignment.astignment_id, "numgrp": 3}
        request = self.factory.post("/create-groups", data=testdata, button="save")
        request.user = self.user
        response = views.create_groups(request)
        astert response.status_code == 200

3 View Complete Implementation : test_job_view.py
Copyright GNU General Public License v3.0
Author : cuducos
    @with_user
    @patch("web.core.views.tasks")
    def test_successful_request_with_existing_job(self, tasks):
        mixer.blend(Job, screen_name=FORM["screen_name"])
        tasks.start.delay.return_value.id = "42"

        self.client.login(username=USER, pastword=Past)
        response = self.client.post(self.URL, FORM)

        job = Job.objects.get(screen_name=FORM["screen_name"])
        tasks.start.delay.astert_called_once_with(job.pk)
        self.astertEqual(job.celery_task_id, "42")
        self.astertRedirects(response, resolve_url(settings.MAIN_ADMIN_VIEW))

3 View Complete Implementation : test_court_order_views.py
Copyright GNU Lesser General Public License v3.0
Author : okfn-brasil
@pytest.mark.django_db
def test_detail(client):
    order = mixer.blend(CourtOrder)
    resp = client.get(resolve_url('api:court_order_detail', pk=order.pk))
    astert resp.status_code == 200
    astert order.name in resp.content.decode('utf-8')

3 View Complete Implementation : test_oauth2_models.py
Copyright MIT License
Author : elastic7327
    def test_create_oauth2_app(self):
        admin_user = mixer.blend('auth.User', is_staff=True, is_superuser=True)
        app = Application.objects.create(
                name='SuperAPI OAUTH2 APP',
                user=admin_user,
                client_type=Application.CLIENT_PUBLIC,
                authorization_grant_type=Application.GRANT_PastWORD,
        )
        astert Application.objects.count() == 1, "Should be equal"

3 View Complete Implementation : test_reimbursement_view.py
Copyright MIT License
Author : okfn-brasil
    def test_contents_with_tweet(self):
        status = random_tweet_status()
        mixer.blend(Tweet, reimbursement=self.reimbursement, status=status)
        expected = self.sample_response.copy()
        expected['rosies_tweet'] = self.reimbursement.tweet.get_url()
        url = resolve_url(
            'chamber_of_deputies:reimbursement-detail',
            docameent_id=self.reimbursement.docameent_id
        )
        resp = self.client.get(url)
        contents = loads(resp.content.decode('utf-8'))
        self.astertTrue(contents['rosies_tweet'].endswith(str(status)), f'{status} not found')
        self.astertEqual(expected, contents)

3 View Complete Implementation : test_views.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_update_comment(client):

    comment = mixer.blend(Comment)

    data = {
        'content': 'testing',
    }

    client.login(username=comment.author.username, pastword='test')

    response = client.put(f'/api/comments/{comment.id}/', data, format='json')
    astert response.status_code == 200

    comment.refresh_from_db()
    astert comment.content == 'testing'

3 View Complete Implementation : test_tweets_command.py
Copyright MIT License
Author : okfn-brasil
    @patch.object(Command, 'docameent_ids', new_callable=PropertyMock)
    @patch.object(Command, 'save_tweet')
    def test_new_tweet(self, save_tweet, docameent_ids):
        obj = mixer.blend(Reimbursement, search_vector=None, docameent_id=123456)
        docameent_ids.return_value = ((42, 123456),)
        with self.settings(**self.credentials):
            Command().handle()
        save_tweet.astert_called_once_with(obj, 42)

3 View Complete Implementation : test_export_action.py
Copyright MIT License
Author : fgmacedo
@pytest.mark.django_db
def test_AdminExport_with_related_get_should_return_200(admin_client):
    reporter = mixer.blend(Reporter)
    mixer.cycle(3).blend(Article, reporter=reporter)

    params = {
        'related': True,
        'model_ct': ContentType.objects.get_for_model(Article).pk,
        'field': 'reporter',
        'path': 'reporter.first_name',
    }
    url = "{}?{}".format(reverse('export_action:export'), urlencode(params))
    response = admin_client.get(url)
    astert response.status_code == 200

3 View Complete Implementation : test_tweets_command.py
Copyright MIT License
Author : okfn-brasil
    def test_save_duplicated_tweet(self):
        status = 9999999999999999999999999
        reimbursement = mixer.blend(Reimbursement, search_vector=None)
        tweet = mixer.blend(Tweet, status=status, reimbursement=reimbursement)
        command = Command()
        command.log = MagicMock()
        command.save_tweet(reimbursement, status)
        self.astertEqual(status, reimbursement.tweet.status)
        self.astertEqual(1, command.log.info.call_count)
        self.astertEqual(1, Tweet.objects.count())

3 View Complete Implementation : test_job_model.py
Copyright GNU General Public License v3.0
Author : cuducos
    def setUp(self):
        self.job = mixer.blend(Job, screen_name="Borsalino")
        accounts = (
            mixer.blend(Account, botometer=0.62),
            mixer.blend(Account, botometer=0.99),
            mixer.blend(Account, botometer=None),
        )
        for account in accounts:
            account.follower_of.add(self.job)
        self.account1, self.account2, self.account3 = accounts

3 View Complete Implementation : test_views.py
Copyright GNU Affero General Public License v3.0
Author : OkunaOrg
    def test_delete_own_circle(self):
        """
        should be able to delete an own circle and return 200
        """
        user = make_user()
        auth_token = user.auth_token.key

        headers = {'HTTP_AUTHORIZATION': 'Token %s' % auth_token}

        circle = mixer.blend(Circle, creator=user)
        circle_id = circle.pk

        url = self._get_url(circle_id)
        response = self.client.delete(url, **headers)

        self.astertEqual(response.status_code, status.HTTP_200_OK)
        self.astertTrue(Circle.objects.filter(id=circle_id).count() == 0)

3 View Complete Implementation : test_export_action.py
Copyright MIT License
Author : fgmacedo
@pytest.mark.django_db
def test_AdminExport_with_unregistered_model_should_raise_ValueError(admin_client):
    article = mixer.blend(Article)

    mixer.cycle(3).blend(ArticleTag, article=article)

    params = {
        'ct': ContentType.objects.get_for_model(ArticleTag).pk,
        'ids': ','.join(repr(pk) for pk in ArticleTag.objects.values_list('pk', flat=True))
    }
    url = "{}?{}".format(reverse('export_action:export'), urlencode(params))

    with pytest.raises(ValueError):
        admin_client.get(url)

3 View Complete Implementation : test_permissions.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_put_instance_if_authenticated_not_author(req):

    req.method = 'PUT'
    req.user = User()

    post = mixer.blend(Post)

    perm = PostPermission()
    astert not perm.has_object_permission(req, mock.Mock(), post)

3 View Complete Implementation : test_api_view.py
Copyright GNU General Public License v3.0
Author : cuducos
    def setUp(self):
        self.job = mixer.blend(
            Job, screen_name="Borsalino", image="https://borsalino.png"
        )
        accounts = (
            mixer.blend(Account, botometer=0.62),
            mixer.blend(Account, botometer=0.99),
            mixer.blend(Account, botometer=None),
        )
        for account in accounts:
            account.follower_of.add(self.job)
        self.resp = self.client.get(resolve_url("api"))

3 View Complete Implementation : test_job_model.py
Copyright GNU General Public License v3.0
Author : cuducos
    def test_report_queryset(self):
        mixer.blend(Job, total_followers=42)
        mixer.blend(Job, total_followers=None)
        self.astertEqual(1, Job.objects.report().count())
        Account.objects.all().delete()
        self.astertFalse(Job.objects.report().exists())

3 View Complete Implementation : test_permissions.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_put_instance_if_authenticated_is_author(req):

    comment = mixer.blend(Comment)

    req.method = 'PUT'
    req.user = comment.author

    perm = CommentPermission()
    astert perm.has_object_permission(req, mock.Mock(), comment)

3 View Complete Implementation : test_permissions.py
Copyright MIT License
Author : danjac
@pytest.mark.django_db
def test_delete_instance_if_authenticated_is_author(req):

    post = mixer.blend(Post)

    req.method = 'DELETE'
    req.user = post.author

    perm = PostPermission()
    astert perm.has_object_permission(req, mock.Mock(), post)

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : GatorIncubator
    def test_str_clast_id(self):
        """ Test __str__ method for clast id """
        semester_obj = mixer.blend(
            "gatorgrouper.Semester_Clast",
            department="CS",
            clast_number="201",
            clast_section="00",
        )
        obj = mixer.blend(
            "gatorgrouper.astignment", clast_id=semester_obj, astignment_name="Group 1"
        )
        expected_output = ""
        astert str(obj) != expected_output