示例#1
0
文件: tests.py 项目: cgarrard/OTM2
    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_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)
示例#3
0
    def test_export_users_json(self):
        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['username'], self.user1.username)
        self.assertEquals(user1data.get('email'), None)
        self.assertEquals(user1data['email_hash'], self.user1.email_hash)
        self.assertEquals(user1data['first_name'], self.user1.first_name)
        self.assertEquals(user1data['last_name'], self.user1.last_name)
        self.assertEquals(user1data['organization'], self.user1.organization)
        self.assertEquals(user1data['allow_email_contact'], 'False')
        self.assertEquals(user1data['role'], 'commander')
        self.assertEquals(user1data['created'], str(self.user1.created))

        self.assertEquals(user1data['last_edit_model'], 'Plot')
        self.assertEquals(user1data['last_edit_model_id'], str(self.plot.pk))
        self.assertEquals(user1data['last_edit_instance_id'],
                          str(self.instance.pk))

        self.assertEquals(user1data['last_edit_user_id'], str(self.user1.pk))

        self.assertEquals(user2data['email'], '*****@*****.**')
        self.assertEquals(user2data['email_hash'], self.user2.email_hash)
        self.assertEquals(user2data['last_edit_model'], 'Tree')
        self.assertEquals(user2data['last_edit_model_id'], str(self.tree.pk))
        self.assertEquals(user2data['last_edit_instance_id'],
                          str(self.instance.pk))

        self.assertEquals(user2data['last_edit_user_id'], str(self.user2.pk))
示例#4
0
文件: tests.py 项目: cgarrard/OTM2
    def test_export_users_json(self):
        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['username'], self.user1.username)
        self.assertEquals(user1data.get('email'), None)
        self.assertEquals(user1data['email_hash'], self.user1.email_hash)
        self.assertEquals(user1data['first_name'], self.user1.first_name)
        self.assertEquals(user1data['last_name'], self.user1.last_name)
        self.assertEquals(user1data['organization'], self.user1.organization)
        self.assertEquals(user1data['allow_email_contact'], 'False')
        self.assertEquals(user1data['role'], 'commander')
        self.assertEquals(user1data['created'], str(self.user1.created))

        self.assertEquals(user1data['last_edit_model'], 'Plot')
        self.assertEquals(user1data['last_edit_model_id'], str(self.plot.pk))
        self.assertEquals(user1data['last_edit_instance_id'],
                          str(self.instance.pk))

        self.assertEquals(user1data['last_edit_user_id'], str(self.user1.pk))

        self.assertEquals(user2data['email'], '*****@*****.**')
        self.assertEquals(user2data['email_hash'], self.user2.email_hash)
        self.assertEquals(user2data['last_edit_model'], 'Tree')
        self.assertEquals(user2data['last_edit_model_id'], str(self.tree.pk))
        self.assertEquals(user2data['last_edit_instance_id'],
                          str(self.instance.pk))

        self.assertEquals(user2data['last_edit_user_id'], str(self.user2.pk))
示例#5
0
文件: tests.py 项目: PyBulls/OTM2
    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
文件: tests.py 项目: PyBulls/OTM2
    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
文件: tests.py 项目: cgarrard/OTM2
    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)
示例#9
0
 def test_min_edit_date_validation(self):
     with self.assertRaises(ValidationError):
         users_json(make_request({"minEditDate": "fsdafsa"}), self.instance)
示例#10
0
文件: tests.py 项目: cgarrard/OTM2
 def test_min_edit_date_validation(self):
     with self.assertRaises(ValidationError):
         users_json(make_request({"minEditDate": "fsdafsa"}), self.instance)