Пример #1
0
    def test_min_join_date(self):
        last_week = now() - datetime.timedelta(days=7)
        two_days_ago = now() - datetime.timedelta(days=2)
        yesterday = now() - datetime.timedelta(days=1)
        tda_ts = two_days_ago.strftime(DATETIME_FORMAT)

        Audit.objects.filter(model='InstanceUser')\
            .filter(model_id=self.user1.get_instance_user(self.instance).pk)\
            .update(created=last_week)

        Audit.objects.filter(model='InstanceUser')\
            .filter(model_id=
                    self.commander.get_instance_user(self.instance).pk)\
            .update(created=last_week)

        Audit.objects.filter(model='InstanceUser')\
            .filter(model_id=self.user2.get_instance_user(self.instance).pk)\
            .update(created=yesterday)

        resp = users_json(make_request({'minJoinDate': tda_ts}), self.instance)

        data = json.loads(resp.content)

        self.assertEquals(len(data), 1)

        self.assertEquals(data[0]['username'], self.user2.username)
Пример #2
0
    def test_export_users_json_keep_info_private(self):
        resp = users_json(make_request(), self.instance)

        data = json.loads(resp.content)

        commander, user1data, user2data = data
        self.assertFalse('first_name' in user1data)
Пример #3
0
    def test_export_users_json_make_info_public(self):
        self.user1.make_info_public = True
        self.user1.save()

        resp = users_json(make_request(), self.instance)

        data = json.loads(resp.content)

        commander, user1data, user2data = data

        self.assertEquals(commander['username'], self.commander.username)
        self.assertEquals(user1data.get('email'), None)
        self.assertUserJSON(user1data,
                            {'username': self.user1.username,
                             'email_hash': self.user1.email_hash,
                             'first_name': self.user1.first_name,
                             'last_name': self.user1.last_name,
                             'organization': self.user1.organization,
                             'allow_email_contact': 'False',
                             'role': 'commander',
                             'created': str(self.user1.created)})

        self.assertUserJSON(user2data,
                            {'last_edit_model': 'Tree',
                             'last_edit_model_id': str(self.tree.pk),
                             'last_edit_instance_id': str(self.instance.pk),
                             'last_edit_user_id': str(self.user2.pk),
                             'email': '*****@*****.**',
                             'email_hash': self.user2.email_hash})
Пример #4
0
    def test_min_join_date(self):
        last_week = now() - datetime.timedelta(days=7)
        two_days_ago = now() - datetime.timedelta(days=2)
        yesterday = now() - datetime.timedelta(days=1)
        tda_ts = two_days_ago.strftime(DATETIME_FORMAT)

        Audit.objects.filter(model='InstanceUser')\
            .filter(model_id=self.user1.get_instance_user(self.instance).pk)\
            .update(created=last_week)

        Audit.objects.filter(model='InstanceUser')\
            .filter(model_id=
                    self.commander.get_instance_user(self.instance).pk)\
            .update(created=last_week)

        Audit.objects.filter(model='InstanceUser')\
            .filter(model_id=self.user2.get_instance_user(self.instance).pk)\
            .update(created=yesterday)

        resp = users_json(make_request({'minJoinDate': tda_ts}), self.instance)

        data = json.loads(resp.content)

        self.assertEquals(len(data), 1)

        self.assertEquals(data[0]['username'], self.user2.username)
Пример #5
0
    def test_export_users_json_make_info_public(self):
        self.user1.make_info_public = True
        self.user1.save()

        resp = users_json(make_request(), self.instance)

        data = json.loads(resp.content)

        commander, user1data, user2data = data

        self.assertEquals(commander['username'], self.commander.username)
        self.assertEquals(user1data.get('email'), None)
        self.assertUserJSON(user1data,
                            {'username': self.user1.username,
                             'email_hash': self.user1.email_hash,
                             'first_name': self.user1.first_name,
                             'last_name': self.user1.last_name,
                             'organization': self.user1.organization,
                             'allow_email_contact': 'False',
                             'role': 'commander',
                             'created': str(self.user1.created)})

        self.assertUserJSON(user2data,
                            {'last_edit_model': 'Plot',
                             'last_edit_model_id': str(self.plot.pk),
                             'last_edit_instance_id': str(self.instance.pk),
                             'last_edit_user_id': str(self.user1.pk),
                             'email': '*****@*****.**',
                             'email_hash': self.user2.email_hash,
                             'last_edit_model': 'Tree',
                             'last_edit_model_id': str(self.tree.pk),
                             'last_edit_instance_id': str(self.instance.pk),
                             'last_edit_user_id': str(self.user2.pk)})
Пример #6
0
    def test_export_users_json_keep_info_private(self):
        resp = users_json(make_request(), self.instance)

        data = json.loads(resp.content)

        commander, user1data, user2data = data
        self.assertFalse('first_name' in user1data)
Пример #7
0
    def test_min_edit_date(self):
        last_week = now() - datetime.timedelta(days=7)
        two_days_ago = now() - datetime.timedelta(days=2)
        yesterday = now() - datetime.timedelta(days=1)
        tda_ts = two_days_ago.strftime(DATETIME_FORMAT)

        Audit.objects.filter(user=self.user1).update(created=last_week, updated=last_week)

        Audit.objects.filter(user=self.commander).update(created=last_week, updated=last_week)

        Audit.objects.filter(user=self.user2).update(created=yesterday, updated=yesterday)

        resp = users_json(make_request({"minEditDate": tda_ts}), self.instance)

        data = json.loads(resp.content)

        self.assertEquals(len(data), 1)

        self.assertEquals(data[0]["username"], self.user2.username)
Пример #8
0
    def test_export_users_json_make_info_public(self):
        self.user1.make_info_public = True
        self.user1.save()

        resp = users_json(make_request(), self.instance)

        data = json.loads(resp.content)

        commander, user1data, user2data = data

        self.assertEquals(commander["username"], self.commander.username)
        self.assertEquals(user1data.get("email"), None)
        self.assertUserJSON(
            user1data,
            {
                "username": self.user1.username,
                "email_hash": self.user1.email_hash,
                "first_name": self.user1.first_name,
                "last_name": self.user1.last_name,
                "organization": self.user1.organization,
                "allow_email_contact": "False",
                "role": "commander",
                "created": str(self.user1.created),
            },
        )

        self.assertUserJSON(
            user2data,
            {
                "last_edit_model": "Plot",
                "last_edit_model_id": str(self.plot.pk),
                "last_edit_instance_id": str(self.instance.pk),
                "last_edit_user_id": str(self.user1.pk),
                "email": "*****@*****.**",
                "email_hash": self.user2.email_hash,
                "last_edit_model": "Tree",
                "last_edit_model_id": str(self.tree.pk),
                "last_edit_instance_id": str(self.instance.pk),
                "last_edit_user_id": str(self.user2.pk),
            },
        )
Пример #9
0
    def test_min_edit_date(self):
        last_week = now() - datetime.timedelta(days=7)
        two_days_ago = now() - datetime.timedelta(days=2)
        yesterday = now() - datetime.timedelta(days=1)
        tda_ts = two_days_ago.strftime(DATETIME_FORMAT)

        Audit.objects.filter(user=self.user1)\
            .update(created=last_week, updated=last_week)

        Audit.objects.filter(user=self.commander)\
            .update(created=last_week, updated=last_week)

        Audit.objects.filter(user=self.user2)\
            .update(created=yesterday, updated=yesterday)

        resp = users_json(make_request({'minEditDate': tda_ts}), self.instance)

        data = json.loads(resp.content)

        self.assertEquals(len(data), 1)

        self.assertEquals(data[0]['username'], self.user2.username)
Пример #10
0
 def test_min_edit_date_validation(self):
     with self.assertRaises(ValidationError):
         users_json(make_request({"minEditDate": "fsdafsa"}), self.instance)
Пример #11
0
 def test_min_edit_date_validation(self):
     with self.assertRaises(ValidationError):
         users_json(make_request({"minEditDate": "fsdafsa"}), self.instance)