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)
Esempio n. 2
0
    def test_can_save_prefs(self):
        user = UserFactory.create(is_superuser=True)

        key1 = KeyFactory.create(name='some.random.1')
        key2 = KeyFactory.create(name='some.random.2')

        UsersViolationsPrefsFactory.create(user=user, key=key1, is_active=True)
        UsersViolationsPrefsFactory.create(user=user, key=key2, is_active=False)

        loaded_prefs = UsersViolationsPrefs.get_prefs(self.db, user)
        expect(loaded_prefs).to_length(2)
        expect(loaded_prefs).to_be_like({
            'some.random.1': True,
            'some.random.2': False
        })

        yield self.authenticated_fetch(
            '/users/violations-prefs/',
            user_email=user.email,
            method='POST',
            body=dumps([
                {'key': 'some.random.1', 'is_active': False},
                {'key': 'some.random.2', 'is_active': True},
            ])
        )

        loaded_prefs = UsersViolationsPrefs.get_prefs(self.db, user)
        expect(loaded_prefs).to_length(2)
        expect(loaded_prefs).to_be_like({
            'some.random.1': False,
            'some.random.2': True
        })
Esempio n. 3
0
    def test_can_convert_user_to_dict(self):
        user = UserFactory.create()

        user_dict = user.to_dict()

        expect(user_dict['fullname']).to_equal(user.fullname)
        expect(user_dict['email']).to_equal(user.email)
        expect(user_dict['is_superuser']).to_equal(user.is_superuser)
        expect(user_dict['last_login']).to_equal(user.last_login)
Esempio n. 4
0
    def test_can_get_user_by_email(self):
        self.db.query(User).delete()

        user = UserFactory.create()

        loaded_user = User.by_email(user.email, self.db)
        expect(loaded_user.id).to_equal(user.id)

        invalid_user = User.by_email('*****@*****.**', self.db)
        expect(invalid_user).to_be_null()
Esempio n. 5
0
    def test_can_create_user(self):
        user = UserFactory.create()

        expect(str(user)).to_be_like('%s' % user.email)

        expect(user.id).not_to_be_null()
        expect(user.fullname).to_equal('Marcelo Jorge Vieira')
        expect(user.email).to_equal('*****@*****.**')
        expect(user.is_superuser).to_equal(True)
        last_login = datetime(2013, 12, 11, 10, 9, 8)
        expect(user.last_login).to_be_like(last_login)
Esempio n. 6
0
    def test_can_get_user_locale(self):
        user = UserFactory.create(locale='pt_BR')

        response = yield self.authenticated_fetch('/users/locale/',
                                                  user_email=user.email)

        expect(response.code).to_equal(200)

        locale_data = loads(response.body)

        expect(locale_data.get('locale')).to_equal('pt_BR')
Esempio n. 7
0
    def test_can_update_locale(self):
        user = UserFactory.create(locale='es_ES')

        loaded_user = User.by_email(user.email, self.db)
        expect(loaded_user.id).to_equal(user.id)
        expect(loaded_user.locale).to_equal('es_ES')

        User.update_locale(self.db, user, 'pt_BR')

        loaded_user = User.by_email(user.email, self.db)
        expect(loaded_user.id).to_equal(user.id)
        expect(loaded_user.locale).to_equal('pt_BR')
    def test_can_get_prefs(self):
        user = UserFactory.create()
        key1 = KeyFactory.create()
        key2 = KeyFactory.create()

        UsersViolationsPrefs.insert_pref(self.db, user, key1, True)
        UsersViolationsPrefs.insert_pref(self.db, user, key2, False)

        data = UsersViolationsPrefs.get_prefs(self.db, user)

        expect(data).to_length(2)

        expect(data).to_be_like({key1.name: True, key2.name: False})
Esempio n. 9
0
    def test_can_get_user_locale(self):
        user = UserFactory.create(locale='pt_BR')

        response = yield self.authenticated_fetch(
            '/users/locale/',
            user_email=user.email
        )

        expect(response.code).to_equal(200)

        locale_data = loads(response.body)

        expect(locale_data.get('locale')).to_equal('pt_BR')
    def test_can_get_prefs(self):
        user = UserFactory.create()
        key1 = KeyFactory.create()
        key2 = KeyFactory.create()

        UsersViolationsPrefs.insert_pref(self.db, user, key1, True)
        UsersViolationsPrefs.insert_pref(self.db, user, key2, False)

        data = UsersViolationsPrefs.get_prefs(self.db, user)

        expect(data).to_length(2)

        expect(data).to_be_like(
            {key1.name: True, key2.name: False}
        )
Esempio n. 11
0
    def test_can_get_prefs(self):
        user = UserFactory.create()

        key1 = KeyFactory.create(name='some.random.1')
        key2 = KeyFactory.create(name='some.random.2')

        UsersViolationsPrefsFactory.create(user=user, key=key1, is_active=True)
        UsersViolationsPrefsFactory.create(user=user, key=key2, is_active=False)

        self.server.application.violation_definitions = {
            'some.random.1': {
                'title': 'some random 1',
                'category': 'SEO',
                'generic_description': 'my some random 1'
            },
            'some.random.2': {
                'title': 'some random 2',
                'category': 'HTTP',
                'generic_description': 'my some random 2'
            }
        }

        response = yield self.authenticated_fetch(
            '/users/violations-prefs/',
            user_email=user.email
        )

        expect(response.code).to_equal(200)

        prefs = loads(response.body)

        expect(prefs).to_length(2)
        expect(prefs[0]).to_length(5)
        expect(prefs[1]).to_length(5)

        expect(prefs).to_be_like([{
            'category': 'SEO',
            'is_active': True,
            'name': 'some random 1',
            'key': u'some.random.1',
            'description': u'my some random 1'
        }, {
            'category': 'HTTP',
            'is_active': False,
            'name': 'some random 2',
            'key': u'some.random.2',
            'description': u'my some random 2'
        }])
    def test_can_insert_prefs(self):
        user = UserFactory.create()

        prefs = self.db.query(UsersViolationsPrefs).all()
        expect(prefs).to_length(0)

        items = []
        for x in range(3):
            name = 'key-test-%d' % x
            KeyFactory.create(name=name)
            items.append(name)

        UsersViolationsPrefs.insert_prefs(self.db, user, items)

        prefs = self.db.query(UsersViolationsPrefs).all()
        expect(prefs).to_length(3)
    def test_can_insert_prefs(self):
        user = UserFactory.create()

        prefs = self.db.query(UsersViolationsPrefs).all()
        expect(prefs).to_length(0)

        items = []
        for x in range(3):
            name = 'key-test-%d' % x
            KeyFactory.create(name=name)
            items.append(name)

        UsersViolationsPrefs.insert_prefs(self.db, user, items)

        prefs = self.db.query(UsersViolationsPrefs).all()
        expect(prefs).to_length(3)
    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_insert_pref(self):
        user = UserFactory.create()
        key1 = KeyFactory.create()
        key2 = KeyFactory.create()

        UsersViolationsPrefs.insert_pref(self.db, user, key1, True)
        UsersViolationsPrefs.insert_pref(self.db, user, key2, False)

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

        expect(prefs).to_length(2)

        expect(prefs[0].key).to_equal(key1)
        expect(prefs[0].user).to_equal(user)
        expect(prefs[0].is_active).to_equal(True)

        expect(prefs[1].key).to_equal(key2)
        expect(prefs[1].user).to_equal(user)
        expect(prefs[1].is_active).to_equal(False)
Esempio n. 17
0
    def test_can_save_user_locale(self):
        user = UserFactory.create(locale='pt_BR')

        loaded_user = User.by_email(user.email, self.db)
        expect(loaded_user.id).to_equal(user.id)
        expect(loaded_user.locale).to_equal('pt_BR')

        response = yield self.authenticated_fetch('/users/locale/',
                                                  user_email=user.email,
                                                  method='POST',
                                                  body=dumps(
                                                      {'locale': 'es_ES'}))

        expect(response.code).to_equal(200)
        expect(loads(response.body)).to_equal('OK')

        loaded_user = User.by_email(user.email, self.db)
        expect(loaded_user.id).to_equal(user.id)
        expect(loaded_user.locale).to_equal('es_ES')
    def test_can_delete_prefs(self):
        user = UserFactory.create()

        pref1 = UsersViolationsPrefsFactory.create(user=user)
        pref2 = UsersViolationsPrefsFactory.create(user=user)

        prefs = self.db.query(UsersViolationsPrefs).all()
        expect(prefs).to_length(2)

        items = [pref1.key.name]

        UsersViolationsPrefs.delete_prefs(self.db, user, items)

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

        expect(prefs).to_length(1)
        expect(prefs[0].key.name).to_equal(pref2.key.name)
        expect(prefs[0].user).to_equal(pref2.user)
        expect(prefs[0].is_active).to_equal(True)
    def test_can_insert_pref(self):
        user = UserFactory.create()
        key1 = KeyFactory.create()
        key2 = KeyFactory.create()

        UsersViolationsPrefs.insert_pref(self.db, user, key1, True)
        UsersViolationsPrefs.insert_pref(self.db, user, key2, False)

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

        expect(prefs).to_length(2)

        expect(prefs[0].key).to_equal(key1)
        expect(prefs[0].user).to_equal(user)
        expect(prefs[0].is_active).to_equal(True)

        expect(prefs[1].key).to_equal(key2)
        expect(prefs[1].user).to_equal(user)
        expect(prefs[1].is_active).to_equal(False)
    def test_can_delete_prefs(self):
        user = UserFactory.create()

        pref1 = UsersViolationsPrefsFactory.create(user=user)
        pref2 = UsersViolationsPrefsFactory.create(user=user)

        prefs = self.db.query(UsersViolationsPrefs).all()
        expect(prefs).to_length(2)

        items = [pref1.key.name]

        UsersViolationsPrefs.delete_prefs(self.db, user, items)

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

        expect(prefs).to_length(1)
        expect(prefs[0].key.name).to_equal(pref2.key.name)
        expect(prefs[0].user).to_equal(pref2.user)
        expect(prefs[0].is_active).to_equal(True)
Esempio n. 21
0
    def test_can_save_user_locale(self):
        user = UserFactory.create(locale='pt_BR')

        loaded_user = User.by_email(user.email, self.db)
        expect(loaded_user.id).to_equal(user.id)
        expect(loaded_user.locale).to_equal('pt_BR')

        response = yield self.authenticated_fetch(
            '/users/locale/',
            user_email=user.email,
            method='POST',
            body=dumps({'locale': 'es_ES'})
        )

        expect(response.code).to_equal(200)
        expect(loads(response.body)).to_equal('OK')

        loaded_user = User.by_email(user.email, self.db)
        expect(loaded_user.id).to_equal(user.id)
        expect(loaded_user.locale).to_equal('es_ES')
    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)