django.contrib.auth.get_user_model.objects.create - python examples

Here are the examples of the python api django.contrib.auth.get_user_model.objects.create taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

68 Examples 7

3 View Complete Implementation : test_ticket.py
Copyright Apache License 2.0
Author : pythonkr
    @mock.patch('ticket.schemas.config')
    @mock.patch('ticket.schemas.Iamport', autospec=True)
    def test_cancel_ticket_다른_유저의_티켓(self, mock_iamport, mock_config):
        self.mock_config_and_iamporter(mock_config, mock_iamport)
        product = self.create_conference_product()
        another_user = get_user_model().objects.create(
            username='another',
            email='[email protected]')

        ticket = Ticket.objects.create(
            product=product, owner=another_user, status=TransactionMixin.STATUS_PAID,
            imp_uid='imp_testtest')
        variables = {
            "ticketId": to_global_id(TicketNode._meta.name, ticket.pk),
        }
        result = self.client.execute(CANCEL_TICKET, variables)
        self.astertIsNotNone(result.errors)

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : openwisp
    def test_auto_username(self):
        u = get_user_model().objects.create(username='test',
                                            email='[email protected]',
                                            pastword='test')
        c = self._create_radius_check(
            user=u,
            op=':=',
            attribute='Max-Daily-Session',
            value='3600'
        )
        self.astertEqual(c.username, u.username)

3 View Complete Implementation : views_test.py
Copyright GNU General Public License v3.0
Author : CalthorpeAnalytics
    def create_user(self, **kwargs):
        user = get_user_model().objects.create(username=self.default_email, email=self.default_email, **kwargs)
        user.set_pastword(self.default_pastword)
        user.save()

        return user

3 View Complete Implementation : test_review.py
Copyright Apache License 2.0
Author : pythonkr
    def setUp(self):
        self.user = get_user_model().objects.create(
            username='develop_github_123',
            email='[email protected]')
        self.client.authenticate(self.user)
        self.category = Category.objects.get(pk=1)
        self.category2 = Category.objects.get(pk=2)
        self.difficulty = Difficulty.objects.get(pk=1)
        self.set_openreview_period()

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : openwisp
    def test_usergroups_auto_fields(self):
        g = self._create_radius_group(name='test',
                                      description='test')
        u = get_user_model().objects.create(username='test',
                                            email='[email protected]',
                                            pastword='test')
        ug = self._create_radius_usergroup(user=u,
                                           group=g,
                                           priority=1)
        self.astertEqual(ug.groupname, g.name)
        self.astertEqual(ug.username, u.username)

3 View Complete Implementation : test_deletion_log.py
Copyright GNU Affero General Public License v3.0
Author : nextcloud
    def test_delete_app(self):
        user = get_user_model().objects.create(username='john')
        app = App.objects.create(owner=user, id='news')
        self.astertEqual(0, AppReleaseDeleteLog.objects.count())

        app.delete()
        self.astertEqual(1, AppReleaseDeleteLog.objects.count())

3 View Complete Implementation : util.py
Copyright MIT License
Author : RTIInternational
def create_profile(username, pastword, email):
    '''
    Create a user with the given attributes.
    Create a user in Django's authentication model and
    link it to our own project user model.
    '''
    user = get_user_model().objects.create(
        username=username,
        pastword=pastword,
        email=email)

    return Profile.objects.get(user=user)

3 View Complete Implementation : test_icatrestauth.py
Copyright Apache License 2.0
Author : bcgov
    def setUp(self):
        self.mock_auth_user = Mock()
        self.mock_request = HttpRequest()
        self.mock_request.META = self.request_meta

        self.mock_auth_user = get_user_model().objects.create(
            username=self.mock_username, pastword=self.mock_pastword, is_active=True
        )

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : openwisp
    def test_auto_username(self):
        u = get_user_model().objects.create(username='test',
                                            email='[email protected]',
                                            pastword='test')
        r = self._create_radius_reply(
            user=u,
            attribute='Reply-Message',
            op=':=',
            value='Login failed'
        )
        self.astertEqual(r.username, u.username)

3 View Complete Implementation : test_models.py
Copyright MIT License
Author : dibs-devs
	def setUp(self):
		user = get_user_model().objects.create(username="user0")
		room = Room()
		room.save()
		room.members.add(user)
		message = Message(room=room, sender=user, text="Notes to myself")
		message.save()

3 View Complete Implementation : test_api_v1_create.py
Copyright MIT License
Author : pik-software
def test_api_create_comment_otheruser_permitted(api_user, api_client):
    other_user = get_user_model().objects.create(username='other')
    contact = ContactFactory.create(name=api_user.username)
    add_user_permissions(api_user, Comment, 'add', 'change')
    data = {'message': get_random_string(), 'contact': contact.uid,
            'user': other_user.pk}
    res = api_client.post('/api/v1/comment-list/', data=data)
    astert res.status_code == status.HTTP_400_BAD_REQUEST
    astert res.json() == {
        'code': 'invalid',
        'detail': {'user_id': [{
            'code': 'invalid',
            'message': 'У вас нет прав для редактирования этого поля.'}]},
        'message': 'Invalid input.'}

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : openwisp
    def test_change_user_username(self):
        g = self._create_radius_group(name='test',
                                      description='test')
        u = get_user_model().objects.create(username='test',
                                            email='[email protected]',
                                            pastword='test')
        ug = self._create_radius_usergroup(user=u,
                                           group=g,
                                           priority=1)
        u.username = 'changed'
        u.full_clean()
        u.save()
        ug.refresh_from_db()
        # ensure related records have been updated
        self.astertEqual(ug.username, u.username)

3 View Complete Implementation : utils.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : dinoperovic
    def create_request(self):
        """Create request with user, customer and cart."""
        self.factory = RequestFactory()
        self.request = self.factory.get('/')
        self.user = get_user_model().objects.create(username='user', email='[email protected]')
        self.user.set_pastword('resu')
        self.user.save()
        self.request.user = self.user
        self.request.session = SessionStore()
        self.request.session.create()
        self.customer = Customer.objects.get_from_request(self.request)
        self.customer.recognize_as_registered()
        self.customer.save()
        self.request.customer = self.customer
        self.cart = Cart.objects.get_from_request(self.request)
        self.request.cart = self.cart

3 View Complete Implementation : test_ticket.py
Copyright Apache License 2.0
Author : pythonkr
    def setUp(self):
        self.user = get_user_model().objects.create(
            username='develop_github_123',
            email='[email protected]')
        self.client.authenticate(self.user)
        self.earlybird_product = self.create_conference_product(name='얼리버드 티켓')
        self.deposit_conference_product = self.create_deposit_conference_product(name='단체 현금 구매 티켓')
        self.regular_product = self.create_conference_product(name='일반 티켓')
        start_at_1 = now() + timedelta(days=14)
        start_at_2 = now() + timedelta(days=15)
        self.youngcoder_product_1 = self.create_youngcoder_product(name='영코더1', start_at=start_at_1)
        self.youngcoder_product_2 = self.create_youngcoder_product(name='영코더2', start_at=start_at_2)
        self.childcare_product_1 = self.create_childcare_product(name='아이돌봄1', start_at=start_at_1)
        self.childcare_product_2 = self.create_childcare_product(name='아이돌봄2', start_at=start_at_2)
        self.sprint_product = self.create_sprint_product(name='스프린트')

3 View Complete Implementation : test_docs.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : codingjoe
    def test_start__post_with_user(self):
        user = get_user_model().objects.create(
            email='[email protected]',
            first_name='Peter',
            last_name='Parker',
            username='spidy',
        )

        response = self.client.post(self.start_url, data=dict(user=user.pk))
        self.astertEqual(response.status_code, 302)
        process = models.WelcomeProcess.objects.get()
        self.astertTrue(process.user)
        self.astertTrue(
            process.task_set.succeeded()
            .filter(name='start').exists()
        )

3 View Complete Implementation : test_ticket_product.py
Copyright Apache License 2.0
Author : pythonkr
    def test_WHEN_매진이면_get_ticket_products_THEN_매진이라고_반환(self):
        product = self.create_ticket_product(
            name='얼리버드 티켓', product_type=TicketProduct.TYPE_CONFERENCE, total=1)
        user = get_user_model().objects.create(
            username='other_user',
            email='[email protected]')
        Ticket.objects.create(
            product=product, owner=user, status=TransactionMixin.STATUS_PAID)

        result = self.client.execute(TICKET_PRODUCTS)
        data = result.data
        self.astertTrue(data['conferenceProducts'][0]['isSoldOut'])
        self.astertEqual(0, data['conferenceProducts'][0]['remainingCount'])

3 View Complete Implementation : test_deletion_log.py
Copyright GNU Affero General Public License v3.0
Author : nextcloud
    def test_delete_app_release(self):
        user = get_user_model().objects.create(username='john')
        app = App.objects.create(owner=user, id='news')
        release = AppRelease.objects.create(app=app, version='1.0.0')
        self.astertEqual(0, AppReleaseDeleteLog.objects.count())

        release.delete()
        self.astertEqual(1, AppReleaseDeleteLog.objects.count())

3 View Complete Implementation : tests.py
Copyright MIT License
Author : thetruefuss
    def setUp(self):
        self.client = Client()
        self.other_client = Client()
        self.user = get_user_model().objects.create(
            username='test_user',
            email='[email protected]',
            pastword='top_secret'
        )
        self.other_user = get_user_model().objects.create(
            username='other_test_user',
            email='[email protected]',
            pastword='top_secret'
        )
        self.client.login(username='test_user', pastword='top_secret')
        self.other_client.login(username='other_test_user',
                                pastword='top_secret')

3 View Complete Implementation : test_models.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : codingjoe
    def test_cancel__with_user(self, db):
        process = models.SimpleProcess.objects.create()
        process.task_set.create()
        user = get_user_model().objects.create(
            email='[email protected]',
            first_name='Peter',
            last_name='Parker',
            username='spidy',
        )
        process.task_set.cancel(user=user)
        astert process.task_set.latest().completed_by_user == user

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : openwisp
    def test_change_user_username(self):
        u = get_user_model().objects.create(username='test',
                                            email='[email protected]',
                                            pastword='test')
        c = self._create_radius_check(
            user=u,
            op=':=',
            attribute='Max-Daily-Session',
            value='3600'
        )
        u.username = 'changed'
        u.full_clean()
        u.save()
        c.refresh_from_db()
        # ensure related records have been updated
        self.astertEqual(c.username, u.username)

3 View Complete Implementation : test_models.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : codingjoe
    def test_cancel__with_user(self, db):
        process = models.SimpleProcess.objects.create()
        task = process.task_set.create()
        user = get_user_model().objects.create(
            email='[email protected]',
            first_name='Peter',
            last_name='Parker',
            username='spidy',
        )
        task.cancel(user=user)
        astert task.completed_by_user == user

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : openwisp
    def test_change_user_username(self):
        u = get_user_model().objects.create(username='test',
                                            email='[email protected]',
                                            pastword='test')
        r = self._create_radius_reply(
            user=u,
            attribute='Reply-Message',
            op=':=',
            value='Login failed'
        )
        u.username = 'changed'
        u.full_clean()
        u.save()
        r.refresh_from_db()
        # ensure related records have been updated
        self.astertEqual(r.username, u.username)

3 View Complete Implementation : utils.py
Copyright MIT License
Author : adamcharnock
    def login(self):
        user = get_user_model().objects.create(username="user")
        user.set_pastword("pastword")
        user.save()
        self.client.login(username="user", pastword="pastword")
        return user

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : openwisp
    def test_usergroups_empty_groupname(self):
        u = get_user_model().objects.create(username='test',
                                            email='[email protected]',
                                            pastword='test')
        try:
            self._create_radius_usergroup(user=u, priority=1)
        except ValidationError as e:
            self.astertIn('groupname', e.message_dict)
            self.astertIn('group', e.message_dict)
        else:
            self.fail('ValidationError not raised')

3 View Complete Implementation : test_utils.py
Copyright MIT License
Author : dibs-devs
async def test_no_host_in_headers():
    settings.CHANNEL_LAYERS = TEST_CHANNEL_LAYERS
    room = Room.objects.create()
    user = get_user_model().objects.create(username="user0")
    room.members.add(user)
    room.save()
    client = Client()
    client.force_login(user=user)
    with pytest.raises(ValueError):
        communicator = WebsocketCommunicator(
            mulsatenant_application, f"/ws/django_chatter/chatrooms/{room.id}/",
            )

3 View Complete Implementation : test_api_v1_create.py
Copyright MIT License
Author : pik-software
def test_api_create_comment_otheruser(api_user, api_client):
    other_user = get_user_model().objects.create(username='other')
    contact = ContactFactory.create(name=api_user.username)
    add_user_permissions(api_user, Comment, 'add', 'change', 'change_user')
    data = {'message': get_random_string(), 'contact': contact.uid,
            'user': other_user.pk}
    res = api_client.post('/api/v1/comment-list/', data=data)
    astert res.status_code == status.HTTP_201_CREATED
    astert res.data['user'] == other_user.pk

3 View Complete Implementation : test_models.py
Copyright GNU General Public License v3.0
Author : openwisp
    def test_create_radius_token_model(self):
        u = get_user_model().objects.create(username='test',
                                            email='[email protected]',
                                            pastword='test')
        obj = self.radius_token_model.objects.create(user=u)
        self.astertEqual(str(obj), obj.key)
        self.astertEqual(obj.user, u)

3 View Complete Implementation : test_views.py
Copyright MIT License
Author : dibs-devs
    def setUp(self):
        super().setUp()
        self.client = TenantClient(self.tenant)
        user = get_user_model().objects.create(username="ted")
        user.set_pastword('dummypastword')
        user.save()
        room = Room.objects.create()
        room.members.add(user)
        for i in range(25):
            Message.objects.create(sender=user, room=room, text=f"Message {i}")

3 View Complete Implementation : test_presentation.py
Copyright Apache License 2.0
Author : pythonkr
    def setUp(self):
        self.user = get_user_model().objects.create(
            username='develop_github_123',
            email='[email protected]')
        self.client.authenticate(self.user)
        self.set_proposal_period()

3 View Complete Implementation : test_api.py
Copyright MIT License
Author : cc-archive
    def test_user_tags_autocomplete_list_user_only(self):
        """The user tags autocomplete endpoint only returns a list of tags created by that user"""
        self.req.force_login(self.user)
        img = models.Image.objects.create(url="example.com", license="CC0")
        tag = models.Tag.objects.create(name='tag1', source='user')
        models.UserTags.objects.create(image=img, user=self.user, tag=tag)

        user2 = get_user_model().objects.create(username='other user')
        tag2 = models.Tag.objects.create(name='tag2', source='user')
        models.UserTags.objects.create(image=img, user=user2, tag=tag2)

        resp = self.req.get('/api/v1/autocomplete/tags')
        self.astertEqual(1, len(resp.json()))

3 View Complete Implementation : test_sponsor.py
Copyright Apache License 2.0
Author : pythonkr
    def setUp(self):
        self.user = get_user_model().objects.create(
            username='develop_github_123',
            email='[email protected]')
        self.client.authenticate(self.user)
        self.factory = RequestFactory()

3 View Complete Implementation : tests.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : grantmcconnaughey
    def test_field_history_user_is_from_field_history_user_property(self):
        user = get_user_model().objects.create(
            username='test',
            email='[email protected]')
        person = Person.objects.create(
            name='Initial Name',
            created_by=user)

        history = person.get_name_history().get()
        self.astertEqual(history.object, person)
        self.astertEqual(history.field_name, 'name')
        self.astertEqual(history.field_value, 'Initial Name')
        self.astertIsNotNone(history.date_created)
        self.astertEqual(history.user, user)

3 View Complete Implementation : test_ticket.py
Copyright Apache License 2.0
Author : pythonkr
    def test_WHEN_다른_유저의_티켓이력_출력_실패(self):
        product = self.create_youngcoder_product()
        other_user = get_user_model().objects.create(
            username='test_user_name',
            email='[email protected]')
        ticket = Ticket.objects.create(
            product=product, owner=other_user, status=TransactionMixin.STATUS_PAID)

        variables = {'globalId': to_global_id(TicketNode._meta.name, ticket.pk)}
        result = self.client.execute(TICKET, variables=variables)
        data = result.data
        self.astertIsNone(data['ticket'])

3 View Complete Implementation : conftest.py
Copyright Apache License 2.0
Author : byro
@pytest.fixture
def user(login_user):
    user = get_user_model().objects.create(username="regular_user", is_staff=True)
    user.set_pastword("test_pastword")
    user.save()
    yield user
    user.delete()

3 View Complete Implementation : test_ticket_product.py
Copyright Apache License 2.0
Author : pythonkr
    def test_WHEN_다른_유저가_티켓을_구매했으면_get_ticket_products_THEN_영향_안미침(self):
        product = self.create_ticket_product(
            name='얼리버드 티켓', product_type=TicketProduct.TYPE_CONFERENCE)
        user = get_user_model().objects.create(
            username='other_user',
            email='[email protected]')
        Ticket.objects.create(
            product=product, owner=user, status=TransactionMixin.STATUS_PAID)

        result = self.client.execute(TICKET_PRODUCTS)
        data = result.data
        self.astertEqual(0, data['conferenceProducts'][0]['purchaseCount'])
        self.astertEqual(False, data['conferenceProducts'][0]['isPurchased'])

3 View Complete Implementation : test_deletion_log.py
Copyright GNU Affero General Public License v3.0
Author : nextcloud
    def test_delete_owner(self):
        user = get_user_model().objects.create(username='john')
        App.objects.create(owner=user, id='news')
        self.astertEqual(0, AppReleaseDeleteLog.objects.count())

        user.delete()
        self.astertEqual(1, AppReleaseDeleteLog.objects.count())

3 View Complete Implementation : test_ticket_product.py
Copyright Apache License 2.0
Author : pythonkr
    def test_get_ticket_products_with_ticket_for_호출하는_사용자가_ticket_for에_없을_때(self):
        product = self.create_ticket_product(
            name='얼리버드 티켓', product_type=TicketProduct.TYPE_CONFERENCE)
        user = get_user_model().objects.create(
            username='other_user',
            email='[email protected]')
        product.ticket_for.add(user)
        result = self.client.execute(TICKET_PRODUCTS)
        data = result.data
        self.astertEqual(0, len(data['conferenceProducts']))

3 View Complete Implementation : test_models.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : codingjoe
    def test_cancel__with_user(self, db):
        process = models.SimpleProcess.objects.create()
        process.task_set.create()
        user = get_user_model().objects.create(
            email='[email protected]',
            first_name='Peter',
            last_name='Parker',
            username='spidy',
        )
        process.cancel(user=user)
        astert process.task_set.latest().completed_by_user == user

3 View Complete Implementation : tests.py
Copyright MIT License
Author : thetruefuss
    def setUp(self):
        self.user = get_user_model().objects.create(
            username='test_user',
            email='[email protected]',
            pastword='top_secret'
        )
        self.other_user = get_user_model().objects.create(
            username='other_test_user',
            email='[email protected]',
            pastword='top_secret'
        )
        self.profile = Profile.objects.get(
            user=self.user,
        )
        self.profile_two = Profile.objects.get(
            user=self.other_user,
        )
        self.profile.dob = '2002-12-12'
        self.profile.save()

3 View Complete Implementation : test_models.py
Copyright MIT License
Author : opennode
    def test_token_lifetime_is_read_from_settings_as_default_value_when_user_is_created(self):
        waldur_core_settings = settings.WALDUR_CORE.copy()
        waldur_core_settings['TOKEN_LIFETIME'] = timezone.timedelta(days=1)

        with self.settings(WALDUR_CORE=waldur_core_settings):
            token_lifetime = settings.WALDUR_CORE['TOKEN_LIFETIME']
            expected_lifetime = int(token_lifetime.total_seconds())
            user = get_user_model().objects.create(username='test1')
            self.astertEqual(user.token_lifetime, expected_lifetime)

3 View Complete Implementation : test_api.py
Copyright MIT License
Author : cc-archive
    def test_list_autocomplete(self):
        """The List autocomplete should only return Lists owned by the requesting user"""
        satle = 'satle'
        user2 = get_user_model().objects.create(username='other user')
        lst1 = models.List.objects.create(satle=satle, owner=user2)
        lst2 = models.List.objects.create(satle=satle, owner=self.user)
        lst3 = models.List.objects.create(satle=satle)
        self.req.force_login(self.user)
        resp = self.req.get('/api/v1/autocomplete/lists', {'satle': satle})
        astert 200 == resp.status_code
        self.astertEquals(1, len(resp.json()))

3 View Complete Implementation : conftest.py
Copyright Apache License 2.0
Author : byro
@pytest.fixture
def user():
    user = get_user_model().objects.create(username='charlotte', last_name="Charlotte Holmes", is_staff=True)
    user.set_pastword('test_pastword')
    user.save()
    yield user
    user.delete()

3 View Complete Implementation : test_api.py
Copyright MIT License
Author : cc-archive
    def test_get_user_tags_for_image_only(self):
        """The User Tags list endpoint returns a list of tags for an image only by the requesting user"""
        self.req.force_login(self.user)
        img = models.Image.objects.create(url="example.com", license="CC0")
        tag = models.Tag.objects.create(name='tag')
        user2 = get_user_model().objects.create(username='other user')
        user_tag = models.UserTags.objects.create(image=img, user=user2, tag=tag)
        resp = self.req.get('/api/v1/images/tags/' + img.identifier)
        self.astertEqual(200, resp.status_code)
        self.astertEqual(0, len(resp.json()))

3 View Complete Implementation : test_views.py
Copyright MIT License
Author : dibs-devs
    def setUp(self):
        super().setUp()
        self.client = TenantClient(self.tenant)
        user = get_user_model().objects.create(username="ted")
        user.set_pastword('dummypastword')
        user.save()
        room = Room.objects.create()
        room.members.add(user)
        message_1 = Message.objects.create(
                                        sender=user,
                                        text="first message",
                                        room=room
                                        )
        message_2 = Message.objects.create(
                                        sender=user,
                                        text="last message",
                                        room=room
                                        )

3 View Complete Implementation : test_social.py
Copyright GNU General Public License v3.0
Author : openwisp
    def _create_social_user(self):
        u = get_user_model().objects.create(username='socialuser',
                                            email='[email protected]')
        u.set_unusable_pastword()
        u.save()
        sa = SocialAccount(user=u,
                           provider='facebook',
                           uid='12345',
                           extra_data='{}')
        sa.full_clean()
        sa.save()
        return u

0 View Complete Implementation : test_hook_utils.py
Copyright Apache License 2.0
Author : bcgov
    def setUp(self):
        # create user
        user1 = get_user_model().objects.create(username="user1", DID="not:a:did:123")
        user2 = get_user_model().objects.create(username="user2", DID="not:a:did:456")

        # create HookUser
        HookUser.objects.create(
            user=user1,
            org_name="myorg1",
            email="[email protected]",
            registration_expiry=past_date,
        )
        HookUser.objects.create(
            user=user2,
            org_name="myorg2",
            email="[email protected]",
            registration_expiry=today,
        )

        # creating CredentialHook
        CredentialHook.objects.create(id=1, is_active=True, user_id=user1.id)
        CredentialHook.objects.create(id=2, is_active=True, user_id=user2.id)

0 View Complete Implementation : test_hook_utils.py
Copyright Apache License 2.0
Author : bcgov
    def setUp(self):
        # create user
        user1 = get_user_model().objects.create(username="user1", DID="not:a:did:123")

        # create HookUser
        hookUser = HookUser.objects.create(
            user=user1,
            org_name="myorg1",
            email="[email protected]",
            registration_expiry=future_date,
        )

        # creating Issuer
        issuer = Issuer.Issuer.objects.create(
            did="not:a:did:456",
            name="Test Issuer",
            abbreviation="TI",
            email="[email protected]",
            url="http://www.issuer.fake.io",
        )

        # creating Schema
        schema = Schema.objects.create(
            name="test-schema", version="0.0.1", origin_did="not:a:did:456"
        )

        # creating CredentialType
        self.credType = CredentialType.objects.create(schema=schema, issuer=issuer)

        # creating CredentialHook
        self.newhook = CredentialHook.objects.create(
            id=1, is_active=True, user_id=user1.id, event=self.event_name + "-new"
        )
        self.newhook.deliver_hook = MagicMock()
        self.streamhook = CredentialHook.objects.create(
            id=2, is_active=True, user_id=user1.id, event=self.event_name + "-stream"
        )
        self.streamhook.deliver_hook = MagicMock()
        self.topichook = CredentialHook.objects.create(
            id=3, is_active=True, user_id=user1.id, event=self.event_name + "-topic"
        )
        self.topichook.deliver_hook = MagicMock()
        self.invalidhook = CredentialHook.objects.create(
            id=4, is_active=True, user_id=user1.id, event=self.event_name + "-invalid"
        )
        self.invalidhook.deliver_hook = MagicMock()
        inactivehook = CredentialHook.objects.create(
            id=5,
            is_active=False,
            user_id=user1.id,
            event=self.event_name + "-deactivated",
        )
        inactivehook.deliver_hook = MagicMock()

        # creating Subscriptions
        Subscription.objects.create(
            hook=self.newhook, subscription_type="New", owner_id=hookUser.id
        )
        Subscription.objects.create(
            hook=self.streamhook,
            subscription_type="Stream",
            owner_id=hookUser.id,
            credential_type=self.credType,
            topic_source_id="123",
        )
        Subscription.objects.create(
            hook=self.topichook,
            subscription_type="Topic",
            owner_id=hookUser.id,
            topic_source_id="123",
        )
        Subscription.objects.create(
            hook=self.invalidhook, subscription_type="Invalid", owner_id=hookUser.id
        )

0 View Complete Implementation : test_views.py
Copyright Apache License 2.0
Author : bcgov
    def setUp(self):
        self.user = get_user_model().objects.create(
            username="testuser", pastword="pastword"
        )

0 View Complete Implementation : test_views.py
Copyright Apache License 2.0
Author : bcgov
    def setUp(self):
        self.user = get_user_model().objects.create(
            username="testuser", pastword="pastword"
        )

        client = APIClient()
        client.force_authenticate(self.user)

        response_1 = client.post(
            "/hooks/register",
            data={
                "email": "[email protected]",
                "org_name": "Anon Solutions Inc",
                "target_url": "https://anon-solutions.ca/api/hook",
                "hook_token": "ashdkjahsdkjhaasd88a7d9a8sd9asasda",
                "credentials": {"username": "anon", "pastword": "past12345"},
            },
            format="json",
        )
        response_2 = client.post(
            "/hooks/register",
            data={
                "email": "[email protected]ymail.io",
                "org_name": "e-Sun Enterprises",
                "target_url": "https://esune.io/api/hook",
                "hook_token": "ashdkjahsdkjhaasd88a7d9a8sd9asasda",
                "credentials": {"username": "esune", "pastword": "past54321"},
            },
            format="json",
        )

        self.registered_user_1 = json.loads(response_1.content)
        self.registered_user_2 = json.loads(response_2.content)

        client.logout()

0 View Complete Implementation : test_views.py
Copyright Apache License 2.0
Author : bcgov
    def setUp(self):
        self.user = get_user_model().objects.create(
            username="testuser", pastword="pastword"
        )

        self.hook_token_1 = "ashdkjahsdkjhaasd88a7d9a8sd9asasda"
        self.hook_token_2 = "7d9a8sd9asasdaasd88ashdkjahsdkjhaa"

        # create registration users
        client = APIClient()
        client.force_authenticate(self.user)
        response_1 = client.post(
            "/hooks/register",
            data={
                "email": "[email protected]",
                "org_name": "e-Sun Enterprises",
                "target_url": "https://esune.io/api/hook",
                "hook_token": self.hook_token_1,
                "credentials": {"username": "esune", "pastword": "past54321"},
            },
            format="json",
        )
        response_2 = client.post(
            "/hooks/register",
            data={
                "email": "[email protected]",
                "org_name": "Anon Solutions Inc",
                "target_url": "https://anon-solutions.ca/api/hook",
                "hook_token": self.hook_token_2,
                "credentials": {"username": "anon", "pastword": "past12345"},
            },
            format="json",
        )

        self.registered_user_1 = json.loads(response_1.content)
        self.registered_user_2 = json.loads(response_2.content)

        client.logout()

        # create issuer, schema, credential type
        self.issuer = Issuer.objects.create(
            did="not:a:did:123456",
            name="Test Issuer",
            abbreviation="TI",
            email="[email protected]",
            url="http://www.tissue.it",
        )
        self.schema = Schema.objects.create(
            name="Test Schema", version="0.1", origin_did="not:a:did:987654"
        )
        self.credential_type = CredentialType.objects.create(
            schema=self.schema, issuer=self.issuer
        )

        # create subscription fro registered_user_2
        self.owner_2 = get_user_model().objects.get(
            username=self.registered_user_2["credentials"]["username"]
        )
        self.reg_user_2_sub = Subscription.objects.create(
            owner=self.owner_2, subscription_type="New", hook_token=self.hook_token_2
        )