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)), )
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', )
def tearDownClass(cls): GroupStagingTable.clear_records() UserStagingTable.clear_records() GroupDim.clear_records() UserDim.clear_records() UserGroupDim.clear_records() super(TestUserGroupDim, cls).tearDownClass()
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)
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', )
def tearDownClass(cls): for user in cls.user_records: user.delete() for domain in cls.domain_records: domain.delete() FormProcessorTestUtils.delete_all_sql_forms(cls.domain) DomainStagingTable.clear_records() DomainDim.clear_records() UserStagingTable.clear_records() UserDim.clear_records() FormStagingTable.clear_records() FormFact.clear_records()
def tearDownClass(cls): for user in cls.user_records: user.delete() for domain in cls.domain_records: domain.delete() FormProcessorTestUtils.delete_all_sql_forms(cls.domain) FormStagingTable.clear_records() FormFact.clear_records() DomainStagingTable.clear_records() DomainDim.clear_records() UserStagingTable.clear_records() UserDim.clear_records() super(FormFactIntegrationTest, cls).tearDownClass()
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))
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))
def tearDownClass(cls): for record in cls.records: record.delete() UserDim.clear_records() UserStagingTable.clear_records() super(TestUserDim, cls).tearDownClass()
def tearDownClass(cls): DomainMembershipDim.clear_records() UserDim.clear_records() UserStagingTable.clear_records() super(TestDomainMembershipDim, cls).tearDownClass()