def setUp(self): super(BrowseLogsTests, self).setUp() session = Session() # Add a regular user and an admin user self.user = models.User(email='*****@*****.**', username='******') self.admin = models.User(email='*****@*****.**', username='******') self.user_log = models.Log( user='******', project='relational_db', distro='Fedora', description='This is a log', ) self.admin_log = models.Log( user='******', project='best_project', distro='CentOS', description='This is also a log', ) session.add_all([self.user, self.admin, self.user_log, self.admin_log]) session.commit() mock_config = mock.patch.dict( models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]}) mock_config.start() self.addCleanup(mock_config.stop) self.client = self.flask_app.test_client()
def setUp(self): super(SetFlagStateTests, self).setUp() session = Session() # Add a regular user and an admin user self.user = models.User(email='*****@*****.**', username='******') self.admin = models.User(email='*****@*****.**', username='******') self.project1 = models.Project( name='test_project', homepage='https://example.com/test_project', backend='PyPI') self.project2 = models.Project( name='project2', homepage='https://example.com/project2', backend='PyPI') self.flag1 = models.ProjectFlag( reason='I wanted to flag it', user='******', project=self.project1) self.flag2 = models.ProjectFlag( reason='This project is wrong', user='******', project=self.project2) session.add_all( [self.user, self.admin, self.project1, self.project2, self.flag1, self.flag2]) session.commit() mock_config = mock.patch.dict( models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]}) mock_config.start() self.addCleanup(mock_config.stop) self.client = self.flask_app.test_client()
def setUp(self): super(DeleteProjectVersionTests, self).setUp() session = Session() # Add a project with a version to delete. self.project = models.Project( name='test_project', homepage='https://example.com/test_project', backend='PyPI', ) self.project_version = models.ProjectVersion(project=self.project, version='1.0.0') # Add a regular user and an admin user self.user = models.User(email='*****@*****.**', username='******') self.admin = models.User(email='*****@*****.**', username='******') session.add_all([self.user, self.admin, self.project, self.project_version]) session.commit() mock_config = mock.patch.dict( models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]}) mock_config.start() self.addCleanup(mock_config.stop) self.client = self.flask_app.test_client()
def test_main_email(self): """ Assert that correct user data are dumped when providing e-mail. """ user = models.User(email="*****@*****.**", username="******", active=True) user_social_auth = social_models.UserSocialAuth(user_id=user.id, user=user) self.session.add(user_social_auth) self.session.add(user) user2 = models.User(email="*****@*****.**", username="******", active=True) user_social_auth = social_models.UserSocialAuth(user_id=user2.id, user=user2) self.session.add(user_social_auth) self.session.add(user2) self.session.commit() exp = [ { "id": str(user.id), "username": user.username, "email": user.email, "active": user.active, "social_auth": [{"uid": None, "provider": None, "extra_data": None}], } ] sar.main() out, err = self.capsys.readouterr() obs = json.loads(out) self.assertEqual(exp, obs)
def setUp(self): super(DeleteProjectMappingTests, self).setUp() self.project = models.Project( name='test_project', homepage='https://example.com/test_project', backend='PyPI', ) self.distro = models.Distro(name='Fedora') self.package = models.Packages( distro=self.distro.name, project=self.project, package_name='test-project') # Add a regular user and an admin user session = Session() self.user = models.User(email='*****@*****.**', username='******') self.admin = models.User(email='*****@*****.**', username='******') session.add_all([self.user, self.admin, self.distro, self.project, self.package]) session.commit() mock_config = mock.patch.dict( models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]}) mock_config.start() self.addCleanup(mock_config.stop) self.client = self.flask_app.test_client()
def test_main_username(self): """ Assert that correct user data are dumped when providing username. """ user = models.User(email="*****@*****.**", username="******", active=True) self.session.add(user) user2 = models.User(email="*****@*****.**", username="******", active=True) self.session.add(user2) self.session.commit() exp = [{ "id": str(user.id), "username": user.username, "email": user.email, "active": user.active, "user_social_auths": [], }] sar.main() out, err = self.capsys.readouterr() obs = json.loads(out) self.assertEqual(exp, obs)
def test_main_no_env_set(self): """ Assert that correct user data are dumped when nothing is provided. """ user = models.User( email='*****@*****.**', username='******', active=True, ) user_social_auth = social_models.UserSocialAuth(user_id=user.id, user=user) self.session.add(user_social_auth) self.session.add(user) user2 = models.User( email='*****@*****.**', username='******', active=True, ) user_social_auth = social_models.UserSocialAuth(user_id=user2.id, user=user2) self.session.add(user_social_auth) self.session.add(user2) self.session.commit() sar.main() out, err = self.capsys.readouterr() self.assertEqual('[]', out)
def setUp(self): super(EditDistroTests, self).setUp() # Add a regular user and an admin user session = Session() self.user = models.User( email='*****@*****.**', username='******', ) user_social_auth = social_models.UserSocialAuth( user_id=self.user.id, user=self.user ) session.add(self.user) session.add(user_social_auth) self.admin = models.User(email='*****@*****.**', username='******') admin_social_auth = social_models.UserSocialAuth( user_id=self.admin.id, user=self.admin ) # Add distributions to edit self.fedora = models.Distro(name='Fedora') self.centos = models.Distro(name='CentOS') session.add_all([admin_social_auth, self.admin, self.fedora, self.centos]) session.commit() mock_config = mock.patch.dict( models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]}) mock_config.start() self.addCleanup(mock_config.stop) self.client = self.flask_app.test_client()
def setUp(self): super(IsAdminTests, self).setUp() # Add a regular user and an admin user session = Session() self.user = models.User( email='*****@*****.**', username='******', ) user_social_auth = social_models.UserSocialAuth( user_id=self.user.id, user=self.user ) session.add(self.user) session.add(user_social_auth) self.admin = models.User(email='*****@*****.**', username='******') admin_social_auth = social_models.UserSocialAuth( user_id=self.admin.id, user=self.admin ) session.add_all([admin_social_auth, self.admin]) session.commit() mock_config = mock.patch.dict( models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]}) mock_config.start() self.addCleanup(mock_config.stop)
def test_username_unique(self): """Assert User usernames have a uniqueness constraint on them.""" session = Session() user = models.User(email='*****@*****.**', username='******') session.add(user) session.commit() user2 = models.User(email='*****@*****.**', username='******') session.add(user2) self.assertRaises(IntegrityError, session.commit)
def test_main_username(self): """ Assert that correct user data are dumped when providing username. """ user = models.User( email='*****@*****.**', username='******', active=True, ) user_social_auth = social_models.UserSocialAuth(user_id=user.id, user=user) self.session.add(user_social_auth) self.session.add(user) user2 = models.User( email='*****@*****.**', username='******', active=True, ) user_social_auth = social_models.UserSocialAuth(user_id=user2.id, user=user2) self.session.add(user_social_auth) self.session.add(user2) self.session.commit() exp = [{ 'id': str(user.id), 'username': user.username, 'email': user.email, 'active': user.active, 'social_auth': [{ 'uid': None, 'provider': None, 'extra_data': None }] }] sar.main() out, err = self.capsys.readouterr() obs = json.loads(out) self.assertEqual(exp, obs)
def setUp(self): super(IsAdminTests, self).setUp() # Add a regular user and an admin user session = Session() self.user = models.User(email='*****@*****.**', username='******') self.admin = models.User(email='*****@*****.**', username='******') session.add_all([self.user, self.admin]) session.commit() mock_config = mock.patch.dict( models.anitya_config, {'ANITYA_WEB_ADMINS': [six.text_type(self.admin.id)]}) mock_config.start() self.addCleanup(mock_config.stop)
def test_username_unique(self): """Assert User usernames have a uniqueness constraint on them.""" user = models.User(email="*****@*****.**", username="******") user_social_auth = social_models.UserSocialAuth(user_id=user.id, user=user) self.session.add(user) self.session.add(user_social_auth) self.session.commit() user = models.User(email="*****@*****.**", username="******") user_social_auth = social_models.UserSocialAuth(user_id=user.id, user=user) self.session.add(user) self.session.add(user_social_auth) self.assertRaises(IntegrityError, self.session.commit)
def setUp(self): super(EditProjectMappingTests, self).setUp() # Set up a mapping to edit session = Session() self.user = models.User( email='*****@*****.**', username='******', ) user_social_auth = social_models.UserSocialAuth(user_id=self.user.id, user=self.user) self.session.add(self.user) self.session.add(user_social_auth) self.distro1 = models.Distro(name='CentOS') self.distro2 = models.Distro(name='Fedora') self.project = models.Project( name='python_project', homepage='https://example.com/python_project', backend='PyPI', ecosystem_name='pypi', ) self.package = models.Packages(package_name='python_project', distro=self.distro1.name, project=self.project) session.add_all( [self.distro1, self.distro2, self.project, self.package]) session.commit() self.client = self.flask_app.test_client()
def test_social_auth_missing(self): """Assert that exception is thrown when social_auth info is missing.""" user = models.User(email='*****@*****.**', username='******') self.session.add(user) self.session.commit() self.assertRaises(IntegrityError, app.when_user_log_in, app, user)
def test_to_dict(self): """ Assert the correct dictionary is returned. """ user = models.User(email="*****@*****.**", username="******") user_social_auth = social_models.UserSocialAuth(user_id=user.id, user=user, provider="FAS") user_social_auth.set_extra_data({"wookie": "too hairy"}) self.session.add(user_social_auth) self.session.add(user) self.session.commit() expected = { "id": str(user.id), "email": user.email, "username": user.username, "active": user.active, "social_auth": [{ "provider": user_social_auth.provider, "extra_data": user_social_auth.extra_data, "uid": user_social_auth.uid, }], } json = user.to_dict() self.assertEqual(json, expected)
def test_user_id(self): """Assert Users have a UUID id assigned to them.""" session = Session() user = models.User(email='*****@*****.**', username='******') session.add(user) session.commit() self.assertTrue(isinstance(user.id, UUID))
def setUp(self): super(ProjectsResourceGetTests, self).setUp() self.app = self.flask_app.test_client() session = Session() self.user = models.User(email='*****@*****.**', username='******') self.api_token = models.ApiToken(user=self.user) session.add_all([self.user, self.api_token]) session.commit()
def test_user_get_id(self): """Assert Users implements the Flask-Login API for getting user IDs.""" session = Session() user = models.User(email='*****@*****.**', username='******') session.add(user) session.commit() self.assertEqual(six.text_type(user.id), user.get_id())
def setUp(self): """Set up the Flask testing environnment""" super(SettingsTests, self).setUp() self.app = self.flask_app.test_client() session = Session() self.user = models.User(email='*****@*****.**', username='******') session.add(self.user) session.commit()
def setUp(self): super(MapProjectTests, self).setUp() create_distro(self.session) create_project(self.session) self.client = self.flask_app.test_client() session = Session() self.user = models.User(email='*****@*****.**', username='******') session.add(self.user) session.commit()
def setUp(self): super(IntegrityErrorHandlerTests, self).setUp() session = Session() user = models.User(email='*****@*****.**', username='******') social_auth_user = social_models.UserSocialAuth( provider='Demo Provider', user=user) session.add(social_auth_user) session.add(user) session.commit()
def test_check_user_no_social_auth(self): """ Assert `sqlalchemy.exc.IntegrityError` is raised when social_auth is missing. """ user = models.User( email='*****@*****.**', username='******', ) self.session.add(user) self.assertRaises(IntegrityError, self.session.commit)
def test_default_active(self): """Assert User usernames have a uniqueness constraint on them.""" session = Session() user = models.User(email='*****@*****.**', username='******') session.add(user) session.commit() self.assertTrue(user.active) self.assertTrue(user.is_active)
def test_not_anonymous(self): """Assert User implements the Flask-Login API for authenticated users.""" session = Session() user = models.User(email='*****@*****.**', username='******') session.add(user) session.commit() self.assertFalse(user.is_anonymous) self.assertTrue(user.is_authenticated)
def test_user_relationship(self): """Assert users have a reference to their tokens.""" session = Session() user = models.User(email='*****@*****.**', username='******') token = models.ApiToken(user=user) session.add(token) session.commit() self.assertEqual(user.api_tokens, [token])
def test_token_default(self): """Assert creating an ApiToken generates a random token.""" session = Session() user = models.User(email='*****@*****.**', username='******') token = models.ApiToken(user=user) session.add(token) session.commit() self.assertEqual(40, len(token.token))
def test_user_id(self): """Assert Users have a UUID id assigned to them.""" user = models.User(email="*****@*****.**", username="******") user_social_auth = social_models.UserSocialAuth(user_id=user.id, user=user) self.session.add(user) self.session.add(user_social_auth) self.session.commit() self.assertTrue(isinstance(user.id, UUID))
def test_user_get_id(self): """Assert Users implements the Flask-Login API for getting user IDs.""" user = models.User(email="*****@*****.**", username="******") user_social_auth = social_models.UserSocialAuth(user_id=user.id, user=user) self.session.add(user) self.session.add(user_social_auth) self.session.commit() self.assertEqual(six.text_type(user.id), user.get_id())
def setUp(self): """Set up the Flask testing environnment""" super(EditProjectTests, self).setUp() self.app = self.flask_app.test_client() # Make a user to login with session = Session() self.user = models.User(email='*****@*****.**', username='******') session.add(self.user) session.commit() create_distro(self.session) create_project(self.session)