Beispiel #1
0
    def setUp(cls):
        """
        Data set up for the unit test
        """
        role = Role(role="organizer")
        role.save()

        user = User.objects.create_user(email="*****@*****.**", password="******")
        role_obj = Role.objects.get(role="organizer")

        user_profile_obj = UserProfile.objects.create(
            user=user, name="*****@*****.**", contact_number="9999911111",
            organization="organization", address="Bangalore",
            role=role_obj)
        user_profile_obj.save()

        data = dict(email="*****@*****.**", password="******")
        login_response = cls.client.post('/authentication/login', json.dumps(data),
                                         content_type='application/json')
        cls.user_id = login_response.data['data']['user']['user_id']
        cls.token = login_response.data['data']['access']
        cls.user = User.objects.get(id=cls.user_id)

        cls.event_type = EventType(type="test")
        cls.event_type.save()

        cls.event = Event(name="test_event", type=cls.event_type, description="New Event",
                          date="2020-04-02",
                          time="12:38:00", location="karnal", subscription_fee=500,
                          no_of_tickets=250,
                          images="https://www.google.com/images", sold_tickets=0,
                          external_links="google.com",
                          event_created_by_id=cls.user_id)
        cls.event.save()
Beispiel #2
0
    def setUp(cls):
        """
        Data setup for Feedback Question Unit test cases
        """
        role = Role(role="organizer")
        role.save()

        user = User.objects.create_user(email="*****@*****.**",
                                        password="******")
        role_obj = Role.objects.get(role="organizer")

        user_profile_obj = UserProfile.objects.create(
            user=user,
            name="*****@*****.**",
            contact_number="9999911111",
            organization="organization",
            address="Bangalore",
            role=role_obj)
        user_profile_obj.save()
        data = dict(email="*****@*****.**", password="******")
        login_response = cls.client.post('/authentication/login',
                                         json.dumps(data),
                                         content_type='application/json')
        cls.user_id = login_response.data['data']['user']['user_id']
        cls.token = login_response.data['data']['access']
        cls.end_point = "/core/feedback-questions/"
        cls.question = Question(question="Demo question1 ?")
        cls.question.save()
    def setUp(cls):
        """
        Data setup for the Subscription Unit test cases
        """
        role = Role(role="subscriber")
        role.save()
        content = {
            "email": "*****@*****.**",
            "name": "user 12",
            "password": "******",
            "contact": "9999911111",
            "address": "Bangalore",
            "role": "subscriber",
            "organization": "Eventhigh"
        }

        url1 = reverse('registration')
        response = cls.client.post(url1,
                                   json.dumps(content),
                                   content_type='application/json')

        cls.user_id = response.data['data']['user']['user_id']
        cls.token = response.data['data']['access']

        cls.event_type = EventType(type="test")
        cls.event_type.save()

        cls.event = Event(name="test_event",
                          type=cls.event_type,
                          description="New Event",
                          date="2020-04-02",
                          time="12:38:00",
                          location="karnal",
                          subscription_fee=100,
                          no_of_tickets=250,
                          images="https://www.google.com/images",
                          sold_tickets=0,
                          external_links="google.com",
                          event_created_by_id=cls.user_id)
        cls.event.save()
        cls.event_free = Event(name="test_event_free",
                               type=cls.event_type,
                               description="New Event",
                               date="2020-04-02",
                               time="12:38:00",
                               location="karnal",
                               subscription_fee=0,
                               no_of_tickets=250,
                               images="https://www.google.com/images",
                               sold_tickets=0,
                               external_links="google.com",
                               event_created_by_id=cls.user_id)
        cls.event_free.save()

        cls.end_point = "/core/subscription/"
Beispiel #4
0
    def setUp(cls):
        """
        Data setup for Feedback Unit test cases
        """
        role = Role(role="organizer")
        role.save()
        role2 = Role(role="subscriber")
        role2.save()

        user = User.objects.create_user(email="*****@*****.**",
                                        password="******")
        cls.role_obj = Role.objects.get(role="organizer")

        user_profile_obj = UserProfile.objects.create(
            user=user,
            name="*****@*****.**",
            contact_number="9999911111",
            organization="organization",
            address="Bangalore",
            role=cls.role_obj)
        user_profile_obj.save()

        content2 = {
            "email": "*****@*****.**",
            "name": "user 20",
            "password": "******",
            "contact": "9999911111",
            "address": "Bangalore",
            "role": "subscriber",
            "organization": "Eventhigh"
        }

        response = cls.client.post('/authentication/registration',
                                   json.dumps(content2),
                                   content_type='application/json')
        cls.user_id = response.data['data']['user']['user_id']
        cls.token = response.data['data']['access']
        cls.end_point = "/core/feedback/"

        cls.event_type = EventType(type="test")
        cls.event_type.save()

        cls.event = Event(name="test_event",
                          type=cls.event_type,
                          description="New Event",
                          date="2020-04-02",
                          time="12:38:00",
                          location="karnal",
                          subscription_fee=499,
                          no_of_tickets=250,
                          images="https://www.google.com/images",
                          sold_tickets=0,
                          external_links="google.com",
                          event_created_by_id=User.objects.filter()[0].id)
        cls.event.save()
        cls.question = Question(question="Demo question1 ?")
        cls.question.save()
Beispiel #5
0
 def authenticate(self, request, email=None, password=None):
     try:
         role = Role._default_manager.select_related('person').get(
             person__emails__address=email)
     except Role.DoesNotExist:
         Role().set_password(password)
     else:
         if role.check_password(password) and self.user_can_authenticate(
                 role):
             return role
Beispiel #6
0
    def _create_person(self,
                       email,
                       password,
                       *,
                       is_staff,
                       is_superuser,
                       is_active=True,
                       **extra_fields):
        """
        Creates and saves a person with the given username, email and password.
        """
        if not email:
            raise ValueError('The given email must be set')

        role = Role(type=Role.PERSON_ROLE,
                    is_staff=is_staff,
                    is_superuser=is_superuser,
                    is_active=is_active)
        role.set_password(password)

        with transaction.atomic():
            role.save()

            person = self.model(role=role, **extra_fields)
            person.save(using=self._db)

            person.add_email(email)

        return person
Beispiel #7
0
    def authenticate_credentials(self, client_label, password):
        try:
            role = Role.objects.select_related('client').get(client__label=client_label)
        except Role.DoesNotExist:
            # Run the default password hasher once to reduce the timing
            # difference between an existing and a non-existing user (#20760).
            Role().set_password(password)
            raise exceptions.AuthenticationFailed(_('Invalid username/password.'))

        if not role.check_password(password):
            raise exceptions.AuthenticationFailed(_('Invalid username/password.'))

        return role, None
    def setUp(cls):
        role = Role(role="subscriber")
        role.save()
        content = {
            "email": "*****@*****.**",
            "name": "user test",
            "password": "******",
            "contact": "9999911111",
            "address": "Bangalore",
            "role": "subscriber",
            "organization": "Eventhigh"
        }

        response = cls.client.post('/authentication/registration',
                                   json.dumps(content),
                                   content_type='application/json')

        cls.user_id = response.data['data']['user']['user_id']
        cls.token = response.data['data']['access']
        cls.user = User.objects.get(id=cls.user_id)

        event_type = EventType(type="test")
        event_type.save()

        cls.event = Event(name="test_event",
                          type=event_type,
                          description="New Event",
                          date="2020-04-02",
                          time="12:38:00",
                          location="karnal",
                          subscription_fee=500,
                          no_of_tickets=250,
                          images="https://www.google.com/images",
                          sold_tickets=0,
                          external_links="google.com",
                          event_created_by_id=cls.user_id)
        cls.event.save()
Beispiel #9
0
    def validate(self, attrs):
        id = attrs['id']
        secret = attrs['secret']

        try:
            client = models.Client.objects.select_related('role').get(label=id)

            if client.role.check_password(secret) and client.oauth_enabled:
                return {"client": client}

        except models.Client.DoesNotExist:
            # avoid timing attacks by doing a hash round
            Role().set_password(secret)

        raise exceptions.ValidationError(_("Authentification incorrecte"))
Beispiel #10
0
    def _create_client(self,
                       label,
                       password,
                       *,
                       is_superuser,
                       is_active=True,
                       **extra_fields):
        """
        Creates and saves a client with the given label and password.
        """
        if not label:
            raise ValueError('Label must be set')

        role = Role(type=Role.CLIENT_ROLE,
                    is_superuser=is_superuser,
                    is_active=is_active)
        role.set_password(password)

        with transaction.atomic():
            role.save()
            client = self.model(label=label, role=role, **extra_fields)
            client.save(using=self._db)

        return client