Exemple #1
0
    def test_put_category(self, mock_auth):
        category = create_category()

        data = {
            'title': 'A New Title',
            'help_text': 'Some new help text',
        }

        response = self.client.put(
            '/categories/%i' % category.id,
            json=data,
            headers=auth_headers(),
        )
        self.assertEqual(response.status_code, 200)
        mock_auth.assert_called_once()

        # Refresh category object
        category = Category.query.first()

        self.assertEqual(category.title, 'A New Title')
        self.assertEqual(category.help_text, 'Some new help text')

        json_response = json.loads(response.data.decode('utf-8'))

        self.assertEqual(
            json_response, {
                'id': category.id,
                'title': 'A New Title',
                'help_text': 'Some new help text',
                'active': True,
                'deactivated_at': None,
            })
 def setUp(self):
     self.client = app.test_client()
     self.category = create_category()
     self.subcategory = Subcategory(
         category_id=self.category.id,
         title='Safe Work Environment',
         help_text='Some help text',
     ).save()
 def setUp(self):
     self.client = app.test_client()
     self.category = create_category()
     self.subcategory = create_subcategory(self.category.id)
     self.state1_code = 'NY'
     self.state2_code = 'AZ'
     create_state(code=self.state1_code)
     create_state(code=self.state2_code)
 def setUp(self):
     self.state = create_state()
     self.category = create_category()
     self.grade = StateCategoryGrade(
         state_code=self.state.code,
         category_id=self.category.id,
         grade=2,
     ).save()
Exemple #5
0
    def test_get_category(self):
        category = create_category()
        create_subcategory(category.id)

        response = self.client.get(f'/categories/{category.id}')
        self.assertEqual(response.status_code, 200)

        json_response = json.loads(response.data)
        self.assertEqual(json_response, category.serialize())
Exemple #6
0
    def setUp(self):
        self.client = app.test_client()

        self.state = create_state()
        category = create_category()
        create_state_grade(self.state.code)
        create_state_grade(self.state.code)
        create_state_category_grade(self.state.code, category.id)
        create_state_category_grade(self.state.code, category.id)
Exemple #7
0
    def test_get_categories_with_subcategories(self):
        category = create_category()
        create_subcategory(category.id)
        expected_response = [category.serialize(with_subcategories=True)]

        response = self.client.get('/categories?withSubcategories=true')
        self.assertEqual(response.status_code, 200)

        json_response = json.loads(response.data)
        self.assertEqual(json_response, expected_response)
Exemple #8
0
 def setUp(self):
     self.state = create_state()
     self.category = create_category()
     self.subcategory = create_subcategory(self.category.id)
     self.criterion = create_criterion(self.subcategory.id)
     self.score = Score(
         criterion_id=self.criterion.id,
         state=self.state.code,
         meets_criterion=True,
     ).save()
 def setUp(self):
     self.state_code = 'NY'
     create_state(code=self.state_code)
     self.category = create_category()
     self.subcategory = create_subcategory(self.category.id)
     self.link = Link(
         subcategory_id=self.subcategory.id,
         state=self.state_code,
         text='Section 20 of Statute 39-B',
         url='ny.gov/link/to/statute',
     ).save()
Exemple #10
0
    def setUp(self):
        self.client = app.test_client()

        self.category = create_category()
        self.subcategory = create_subcategory(self.category.id)
        self.criterion = Criterion(
            subcategory_id=self.subcategory.id,
            title='Includes economic abuse framework',
            recommendation_text=(
                "The state's definition of domestic violence should include a framework of "
                'economic abuse'
            ),
            help_text=(
                'This means that the state acknowledges the role that economic control and abuse '
                'can play in domestic violence'
            ),
            adverse=False,
        ).save()
Exemple #11
0
    def test_put_category_deactivate(self, mock_auth):
        category = create_category()

        data = {
            'active': False,
        }

        response = self.client.put(
            '/categories/%i' % category.id,
            json=data,
            headers=auth_headers(),
        )
        self.assertEqual(response.status_code, 200)
        mock_auth.assert_called_once()

        # Refresh category object
        category = Category.query.first()

        self.assertFalse(category.active)
        self.assertTrue(isinstance(category.deactivated_at, datetime.datetime))

        json_response = json.loads(response.data.decode('utf-8'))

        self.assertTrue(isinstance(json_response['deactivated_at'], str))

        # Category cannot be reactivated
        deactivated_at = category.deactivated_at
        data = {
            'active': True,
        }

        response = self.client.put(
            '/categories/%i' % category.id,
            json=data,
            headers=auth_headers(),
        )
        category = Category.query.first()
        self.assertFalse(category.active)
        self.assertEqual(category.deactivated_at, deactivated_at)
Exemple #12
0
 def setUp(self):
     self.client = app.test_client()
     self.category = create_category()
     self.subcategory = create_subcategory(self.category.id)
Exemple #13
0
    def setUp(self):
        self.client = app.test_client()

        self.state = State(
            code='NY',
            name='New York',
            innovative_idea='Innovative idea',
            honorable_mention='Honorable mention',
        ).save()
        other_state = create_state(code='AZ')

        category1 = create_category()
        category2 = create_category()
        subcategory = create_subcategory(category1.id)
        criterion1 = create_criterion(subcategory.id)
        criterion2 = create_criterion(subcategory.id)

        self.link1 = create_link(subcategory.id, self.state.code)
        self.link2 = create_link(subcategory.id, self.state.code)

        self.state_grade1 = create_state_grade(self.state.code)
        self.state_grade2 = create_state_grade(self.state.code)

        # state_grade1 is more recent than state_grade2
        self.state_grade1.created_at = datetime.utcnow()
        self.state_grade2.created_at = datetime.utcnow() - timedelta(5)

        self.state_category_grade1 = create_state_category_grade(
            self.state.code, category1.id)
        self.state_category_grade2 = create_state_category_grade(
            self.state.code, category1.id)
        self.state_category_grade3 = create_state_category_grade(
            self.state.code, category2.id)

        # state_category_grade1 is more recent than state_category_grade2
        self.state_category_grade1.created_at = datetime.utcnow()
        self.state_category_grade2.created_at = datetime.utcnow() - timedelta(
            5)

        self.score1 = Score(
            criterion_id=criterion1.id,
            state=self.state.code,
            meets_criterion=True,
        )
        self.score2 = Score(
            criterion_id=criterion2.id,
            state=self.state.code,
            meets_criterion=False,
        )
        self.score3 = Score(
            criterion_id=criterion2.id,
            state=self.state.code,
            meets_criterion=True,
        )
        # score2 is more recent than score3
        self.score3.created_at = datetime.utcnow() - timedelta(5)
        self.score4 = Score(
            criterion_id=criterion2.id,
            state=other_state.code,
            meets_criterion=True,
        )

        Score.save_all([self.score1, self.score2, self.score3, self.score4])
        self.maxDiff = None
 def setUp(self):
     self.client = app.test_client()
     self.category = create_category()
     self.subcategory = create_subcategory(self.category.id)
     self.criterion = create_criterion(self.subcategory.id)
     self.state = create_state()