def test_can_update_by_user(self):
        user = UserFactory.create()

        key = KeyFactory.create(name='some.random')

        pref = UsersViolationsPrefsFactory.create(user=user,
                                                  key=key,
                                                  is_active=True)

        data = [{
            'key': pref.key.name,
            'is_active': False
        }, {
            'key': 'blah',
            'is_active': False
        }]

        UsersViolationsPrefs.update_by_user(self.db, user, data)

        prefs = self.db.query(UsersViolationsPrefs).all()

        expect(prefs).to_length(1)
        expect(prefs[0].key.name).to_equal(key.name)
        expect(prefs[0].user).to_equal(user)
        expect(prefs[0].is_active).to_equal(False)
Exemplo n.º 2
0
    def post(self):
        user = self.get_authenticated_user()

        if not user:
            return

        post_data = loads(self.request.body)

        UsersViolationsPrefs.update_by_user(self.db, user, post_data)

        self.write_json({
            'reason': self._('Preferences successfully saved!'),
            'description': self._('Preferences successfully saved!')
        })
    def test_can_update_by_user_with_no_data(self):
        user = UserFactory.create()

        key = KeyFactory.create(name='some.random')

        UsersViolationsPrefsFactory.create(user=user, key=key, is_active=True)

        data = []

        UsersViolationsPrefs.update_by_user(self.db, user, data)

        prefs = self.db.query(UsersViolationsPrefs).all()

        expect(prefs).to_length(1)
        expect(prefs[0].key.name).to_equal(key.name)
        expect(prefs[0].user).to_equal(user)
        expect(prefs[0].is_active).to_equal(True)
    def test_can_update_by_user_with_no_data(self):
        user = UserFactory.create()

        key = KeyFactory.create(name='some.random')

        UsersViolationsPrefsFactory.create(user=user, key=key, is_active=True)

        data = []

        UsersViolationsPrefs.update_by_user(self.db, user, data)

        prefs = self.db.query(UsersViolationsPrefs).all()

        expect(prefs).to_length(1)
        expect(prefs[0].key.name).to_equal(key.name)
        expect(prefs[0].user).to_equal(user)
        expect(prefs[0].is_active).to_equal(True)
    def test_can_update_by_user(self):
        user = UserFactory.create()

        key = KeyFactory.create(name='some.random')

        pref = UsersViolationsPrefsFactory.create(user=user, key=key, is_active=True)

        data = [
            {'key': pref.key.name, 'is_active': False},
            {'key': 'blah', 'is_active': False}
        ]

        UsersViolationsPrefs.update_by_user(self.db, user, data)

        prefs = self.db.query(UsersViolationsPrefs).all()

        expect(prefs).to_length(1)
        expect(prefs[0].key.name).to_equal(key.name)
        expect(prefs[0].user).to_equal(user)
        expect(prefs[0].is_active).to_equal(False)