def test_log_create(self): """Test when subset gets created.""" log_count_init = LoggerHistory.objects.count() subset = SubsetFactory.create(**{ 'creator': self.user, 'project': self.project}) log = LoggerHistory.objects.last() log_count = LoggerHistory.objects.count() self.assertNotEqual(log.user, { 'id': str(self.user.id), 'display_name': self.user.display_name}) self.assertEqual(log.project, { 'id': str(self.project.id), 'name': self.project.name}) self.assertEqual(log.usergroup, None) self.assertEqual(log.category, None) self.assertEqual(log.field, None) self.assertEqual(log.location, None) self.assertEqual(log.observation, None) self.assertEqual(log.comment, None) self.assertEqual(log.subset, { 'id': str(subset.id), 'name': subset.name}) self.assertEqual(log.action, { 'id': 'created', 'class': 'Subset'}) self.assertEqual(log_count, log_count_init + 1) self.assertEqual(log.historical, None)
def test_get_with_subset(self): category_1 = CategoryFactory(**{'project': self.project}) category_2 = CategoryFactory(**{'project': self.project}) subset = SubsetFactory.create(**{ 'project': self.project, 'filters': { category_1.id: {} } }) for x in range(0, 2): ObservationFactory.create(**{ 'project': self.project, 'category': category_1 }) ObservationFactory.create(**{ 'project': self.project, 'category': category_2 }) response = self.get(self.admin, subset=subset.id) self.assertEqual(response.status_code, 200) self.assertEqual(len(json.loads(response.content).get('features')), 2)
def setUp(self): """Set up test.""" self.user = UserFactory.create() self.project = ProjectFactory.create(**{ 'creator': self.user}) self.subset = SubsetFactory.create(**{ 'creator': self.user, 'project': self.project})
def test_get_data_subset_user_group_filter(self): user = UserFactory.create() project = ProjectFactory.create() category_1 = CategoryFactory(**{'project': project}) TextFieldFactory.create(**{'key': 'text', 'category': category_1}) category_2 = CategoryFactory(**{'project': project}) UserGroupFactory.create( add_users=[user], **{ 'project': project, 'filters': {category_2.id: {}} } ) subset = SubsetFactory.create(**{ 'project': project, 'filters': {category_1.id: {}} }) for x in range(0, 5): ObservationFactory.create(**{ 'project': project, 'category': category_1} ) ObservationFactory.create(**{ 'project': project, 'category': category_1} ) ObservationFactory.create(**{ 'project': project, 'category': category_1, 'status': 'pending'} ) ObservationFactory.create(**{ 'project': project, 'category': category_2} ) self.assertEqual( project.get_all_contributions(user, subset=subset.id).count(), 0 )
def test_get_data_subset_user_group_filter(self): user = UserF.create() project = ProjectF.create() category_1 = CategoryFactory(**{'project': project}) TextFieldFactory.create(**{'key': 'text', 'category': category_1}) category_2 = CategoryFactory(**{'project': project}) UserGroupF.create( add_users=[user], **{ 'project': project, 'filters': {category_2.id: {}} } ) subset = SubsetFactory.create(**{ 'project': project, 'filters': {category_1.id: {}} }) for x in range(0, 5): ObservationFactory.create(**{ 'project': project, 'category': category_1} ) ObservationFactory.create(**{ 'project': project, 'category': category_1} ) ObservationFactory.create(**{ 'project': project, 'category': category_1, 'status': 'pending'} ) ObservationFactory.create(**{ 'project': project, 'category': category_2} ) self.assertEqual( project.get_all_contributions(user, subset=subset.id).count(), 0 )
def test_delete_with_field_filter_for_subset(self): project = ProjectFactory.create() category = CategoryFactory.create(**{'project': project}) field = Field.create('name', 'key', 'description', False, category, 'TextField') subset = SubsetFactory.create(**{ 'project': project, 'filters': { category.id: { field.key: 'blah' } } }) field.delete() ref = Subset.objects.get(pk=subset.id) self.assertEqual(ref.filters, {str(category.id): {}})
def test_delete_with_field_filter_for_subset(self): project = ProjectFactory.create() category = CategoryFactory.create(**{'project': project}) field = Field.create( 'name', 'key', 'description', False, category, 'TextField' ) subset = SubsetFactory.create( **{ 'project': project, 'filters': { category.id: {field.key: 'blah'}} } ) field.delete() ref = Subset.objects.get(pk=subset.id) self.assertEqual(ref.filters, {str(category.id): {}})
def test_get_with_subset(self): category_1 = CategoryFactory(**{'project': self.project}) category_2 = CategoryFactory(**{'project': self.project}) subset = SubsetFactory.create(**{ 'project': self.project, 'filters': {category_1.id: {}} }) for x in range(0, 2): ObservationFactory.create(**{ 'project': self.project, 'category': category_1} ) ObservationFactory.create(**{ 'project': self.project, 'category': category_2} ) response = self.get(self.admin, subset=subset.id) self.assertEqual(response.status_code, 200) self.assertEqual(len(json.loads(response.content).get('features')), 2)