Ejemplo n.º 1
0
    def test_threat_throttle(self):
        # create a report
        report = Report.objects.create(
            coordinates=Coordinates.objects.create(latitude=10, longitude=22))
        threat_url = reverse('mobile_res:threatreport-list')
        emergency_url = reverse('mobile_res:emergencyreport-list')

        for i in range(int(self.reports_limit_rate / 2)):
            t = ThreatType.objects.create(title=random_username())
            data = {'type': t.id, 'report': report.id}
            response = easy_post(self.client, threat_url, data,
                                 self.mobile_user.token.key)
            self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        for i in range(int(self.reports_limit_rate / 2)):
            e = EmergencyType.objects.create(title=random_username())
            data = {'type': e.id, 'report': report.id}
            response = easy_post(self.client, emergency_url, data,
                                 self.mobile_user.token.key)
            self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        e = EmergencyType.objects.create(title='derrumbe total')
        data = {'type': e.id, 'report': report.id}
        response = easy_post(self.client, emergency_url, data,
                             self.mobile_user.token.key)
        self.assertEqual(response.status_code,
                         status.HTTP_429_TOO_MANY_REQUESTS)

        t = ThreatType.objects.create(title='grietas')
        data = {'type': t.id, 'report': report.id}
        response = easy_post(self.client, threat_url, data,
                             self.mobile_user.token.key)
        self.assertEqual(response.status_code,
                         status.HTTP_429_TOO_MANY_REQUESTS)
Ejemplo n.º 2
0
    def setUpClass(cls):
        super().setUpClass()
        cls.reports_limit_rate = int(
            REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['reports'].split("/")[0])
        cls.events_limit_rate = int(
            REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['events'].split("/")[0])
        cls.anon_limit_rate = int(
            REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['anon'].split("/")[0])

        cls.mobile_user = MobileUser.objects.create_random_mobile_user()
        cls.web_user = WebUser.objects.create_web_user(random_username())
Ejemplo n.º 3
0
    def test_random_username(self):
        """
        Check uniqueness of *iter_limit* random user-names generated
        :return:
        """
        iter_limit = 100000
        username_list = []
        for i in range(iter_limit):
            username_list.append(random_username())

        username_set = set(username_list)
        self.assertEqual(len(username_set), len(username_list))
Ejemplo n.º 4
0
 def create_random_mobile_user(self):
     # generate random user & password
     django_user = User.objects.create_user(random_username())
     django_user.set_password(User.objects.make_random_password())
     django_user.save()
     return MobileUser.objects.create(user=django_user)
Ejemplo n.º 5
0
def get_username():
    username = input("enter username (leave blank for random)")
    if username is None or username == "":
        username = random_username()
    return username