예제 #1
0
    def test_user_types(self):
        UserDim.commit(self.batch)

        self.assertEqual(UserDim.objects.count(), 5)
        self.assertEqual(
            UserDim.objects.filter(user_type=SYSTEM_USER_TYPE).first().user_id,
            SYSTEM_USER_ID,
        )
        self.assertEqual(
            UserDim.objects.filter(user_type=DEMO_USER_TYPE).first().user_id,
            DEMO_USER_ID,
        )
        self.assertEqual(
            UserDim.objects.filter(
                user_type=COMMCARE_SUPPLY_USER_TYPE).first().user_id,
            COMMTRACK_USERNAME,
        )
        self.assertEqual(
            UserDim.objects.filter(user_type=MOBILE_USER_TYPE).first().user_id,
            'greengoblin',
        )
        self.assertEqual(
            UserDim.objects.filter(user_type=WEB_USER_TYPE).first().user_id,
            'beeboobop',
        )
예제 #2
0
    def test_basic_user_group_insert(self):
        UserDim.commit(self.batch)
        self.assertEqual(UserDim.objects.count(), 3)

        # Setup group records to have multiple users
        dogs = create_group_staging_record(
            self.domain,
            'dogs',
            user_ids=[self.blue_dog.user_id, self.black_dog.user_id],
            batch_id=self.batch.id)
        create_group_staging_record(self.domain,
                                    'cats',
                                    user_ids=[self.yellow_cat.user_id],
                                    batch_id=self.batch.id)
        GroupDim.commit(self.batch)
        self.assertEqual(GroupDim.objects.count(), 2)

        UserGroupDim.commit(self.batch)
        self.assertEqual(UserGroupDim.objects.count(), 3)
        dog_relations = UserGroupDim.objects.filter(
            group_dim=GroupDim.objects.get(group_id=dogs.group_id))
        self.assertEqual(
            dog_relations.count(),
            2,
        )
        self.assertEqual(
            set(dog_relations.values_list('user_dim_id', flat=True)),
            set(
                UserDim.objects.filter(user_id__in=[
                    self.blue_dog.user_id, self.black_dog.user_id
                ]).values_list('id', flat=True)),
        )
예제 #3
0
 def bootstrap_user_staging(cls):
     create_user_staging_record(
         domain='test1',
         user_id='u1',
         username='******',
         doc_type='CommCareUser',
         batch_id=cls.batch.id,
     )
     create_user_staging_record(
         domain='test1',
         user_id='u2',
         username='******',
         doc_type='CommCareUser',
         batch_id=cls.batch.id,
     )
     create_user_staging_record(domain=None,
                                username='******',
                                user_id='u3',
                                doc_type='WebUser',
                                batch_id=cls.batch.id,
                                domain_memberships=[
                                    {
                                        'domain': 'test1',
                                        'is_admin': True
                                    },
                                    {
                                        'domain': 'test2',
                                        'is_admin': False
                                    },
                                ])
     UserDim.commit(cls.batch)
예제 #4
0
    def test_user_types(self):
        start = datetime.utcnow() - timedelta(days=3)
        end = datetime.utcnow() + timedelta(days=3)

        UserDim.commit(start, end)

        self.assertEqual(UserDim.objects.count(), 5)
        self.assertEqual(
            UserDim.objects.filter(user_type=SYSTEM_USER_TYPE).first().user_id,
            SYSTEM_USER_ID,
        )
        self.assertEqual(
            UserDim.objects.filter(user_type=DEMO_USER_TYPE).first().user_id,
            DEMO_USER_ID,
        )
        self.assertEqual(
            UserDim.objects.filter(
                user_type=COMMCARE_SUPPLY_USER_TYPE).first().user_id,
            COMMTRACK_USERNAME,
        )
        self.assertEqual(
            UserDim.objects.filter(user_type=MOBILE_USER_TYPE).first().user_id,
            'greengoblin',
        )
        self.assertEqual(
            UserDim.objects.filter(user_type=WEB_USER_TYPE).first().user_id,
            'beeboobop',
        )
예제 #5
0
    def test_loading_form_fact(self):
        batch = self.batch

        DomainStagingTable.commit(batch)
        self.assertEqual(DomainStagingTable.objects.count(), len(self.domain_records))

        DomainDim.commit(batch)
        self.assertEqual(DomainDim.objects.count(), len(self.domain_records))

        UserStagingTable.commit(batch)
        self.assertEqual(UserStagingTable.objects.count(), len(self.user_records))

        UserDim.commit(batch)
        self.assertEqual(UserDim.objects.count(), len(self.user_records))

        FormStagingTable.commit(batch)
        self.assertEqual(FormStagingTable.objects.count(), len(self.form_records))

        FormFact.commit(batch)
        self.assertEqual(FormFact.objects.count(), len(self.form_records))
예제 #6
0
    def test_loading_form_fact(self):
        start = datetime.utcnow() - timedelta(days=3)
        end = datetime.utcnow() + timedelta(days=3)

        DomainStagingTable.commit(start, end)
        self.assertEqual(DomainStagingTable.objects.count(),
                         len(self.domain_records))

        DomainDim.commit(start, end)
        self.assertEqual(DomainDim.objects.count(), len(self.domain_records))

        UserStagingTable.commit(start, end)
        self.assertEqual(UserStagingTable.objects.count(),
                         len(self.user_records))

        UserDim.commit(start, end)
        self.assertEqual(UserDim.objects.count(), len(self.user_records))

        FormStagingTable.commit(start, end)
        self.assertEqual(FormStagingTable.objects.count(),
                         len(self.form_records))

        FormFact.commit(start, end)
        self.assertEqual(FormFact.objects.count(), len(self.form_records))