123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- # -*- coding: utf-8 -*-
- """
- (c) 2017 - Copyright Red Hat Inc
- Authors:
- Pierre-Yves Chibon <pingou@pingoured.fr>
- """
- __requires__ = ['SQLAlchemy >= 0.8']
- import pkg_resources
- import json
- import unittest
- import sys
- import os
- import uuid
- sys.path.insert(0, os.path.join(os.path.dirname(
- os.path.abspath(__file__)), '..'))
- import pagure.lib
- import pagure.lib.model as model
- import tests
- class DeleteProjectTests(tests.Modeltests):
- """ Tests for flask issues controller of pagure """
- def test_delete_project_with_group(self):
- """ Test the model when we delete a project with a group. """
- # Create a project
- item = model.Project(
- user_id=1, # pingou
- name='test',
- description='test project #1',
- hook_token='aaabbbiii',
- )
- self.session.add(item)
- self.session.commit()
- # Create a group
- grp = model.PagureGroup(
- group_name='testgrp',
- display_name='Test group',
- description=None,
- group_type='user',
- user_id=1, # pingou
- )
- self.session.add(grp)
- self.session.commit()
- # Add group to project
- project_group = model.ProjectGroup(
- project_id=1,
- group_id=1,
- access='admin',
- )
- self.session.add(project_group)
- self.session.commit()
- self.assertEqual(
- self.session.query(model.Project).count(), 1)
- self.assertEqual(
- self.session.query(model.ProjectGroup).count(), 1)
- project = self.session.query(
- model.Project
- ).filter(
- model.Project.id==1
- ).one()
- self.session.delete(project)
- self.session.commit()
- self.assertEqual(
- self.session.query(model.Project).count(), 0)
- self.assertEqual(
- self.session.query(model.ProjectGroup).count(), 0)
- def test_delete_project_with_user(self):
- """ Test the model when we delete a project with users. """
- # Create a project
- item = model.Project(
- user_id=1, # pingou
- name='test',
- description='test project #1',
- hook_token='aaabbbiii',
- )
- self.session.add(item)
- self.session.commit()
- # Add user #2 to project
- project_user = model.ProjectUser(
- project_id=1,
- user_id=2,
- access='admin',
- )
- self.session.add(project_user)
- self.session.commit()
- self.assertEqual(
- self.session.query(model.Project).count(), 1)
- self.assertEqual(
- self.session.query(model.ProjectUser).count(), 1)
- self.assertEqual(
- self.session.query(model.User).count(), 2)
- project = self.session.query(
- model.Project
- ).filter(
- model.Project.id==1
- ).one()
- self.session.delete(project)
- self.session.commit()
- self.assertEqual(
- self.session.query(model.Project).count(), 0)
- self.assertEqual(
- self.session.query(model.ProjectUser).count(), 0)
- self.assertEqual(
- self.session.query(model.User).count(), 2)
- def test_delete_project_with_coloredtags(self):
- """ Test the model when we delete a project with Colored tags. """
- # Create a project
- item = model.Project(
- user_id=1, # pingou
- name='test',
- description='test project #1',
- hook_token='aaabbbiii',
- )
- self.session.add(item)
- self.session.commit()
- # Create two ColoredTags
- tagobj = model.TagColored(
- tag='Tag#1',
- project_id=1
- )
- self.session.add(tagobj)
- self.session.flush()
- tagobj = model.TagColored(
- tag='Tag#2',
- project_id=1
- )
- self.session.add(tagobj)
- self.session.flush()
- self.assertEqual(
- self.session.query(model.Project).count(), 1)
- self.assertEqual(
- self.session.query(model.TagColored).count(), 2)
- project = self.session.query(
- model.Project
- ).filter(
- model.Project.id==1
- ).one()
- self.session.delete(project)
- self.session.commit()
- self.assertEqual(
- self.session.query(model.Project).count(), 0)
- self.assertEqual(
- self.session.query(model.TagColored).count(), 0)
- def test_delete_project_with_coloredtags_and_issues(self):
- """ Test the model when we delete a project with Colored tags and
- issues. """
- # Create a project
- item = model.Project(
- user_id=1, # pingou
- name='test',
- description='test project #1',
- hook_token='aaabbbiii',
- )
- self.session.add(item)
- self.session.commit()
- # Create two ColoredTags
- tagobj = model.TagColored(
- tag='Tag#1',
- project_id=1
- )
- self.session.add(tagobj)
- self.session.flush()
- tagobj = model.TagColored(
- tag='Tag#2',
- project_id=1
- )
- self.session.add(tagobj)
- self.session.flush()
- # Create issues
- issue = model.Issue(
- id=pagure.lib.get_next_id(self.session, 1),
- project_id=1,
- title='Issue #1',
- content='Description #1',
- user_id=1,
- uid=uuid.uuid4().hex,
- private=False,
- )
- self.session.add(issue)
- self.session.commit()
- issue = model.Issue(
- id=pagure.lib.get_next_id(self.session, 1),
- project_id=1,
- title='Issue #2',
- content='Description #2',
- user_id=1,
- uid=uuid.uuid4().hex,
- private=False,
- )
- self.session.add(issue)
- self.session.commit()
- self.assertEqual(
- self.session.query(model.Project).count(), 1)
- self.assertEqual(
- self.session.query(model.TagColored).count(), 2)
- self.assertEqual(
- self.session.query(model.Issue).count(), 2)
- project = self.session.query(
- model.Project
- ).filter(
- model.Project.id==1
- ).one()
- self.session.delete(project)
- self.session.commit()
- self.assertEqual(
- self.session.query(model.Project).count(), 0)
- self.assertEqual(
- self.session.query(model.TagColored).count(), 0)
- self.assertEqual(
- self.session.query(model.Issue).count(), 0)
- def test_delete_project_with_coloredtags_and_tagged_issues(self):
- """ Test the model when we delete a project with Colored tags and
- tagged issues. """
- # Create a project
- item = model.Project(
- user_id=1, # pingou
- name='test',
- description='test project #1',
- hook_token='aaabbbiii',
- )
- self.session.add(item)
- self.session.commit()
- # Create two ColoredTags
- tagobj = model.TagColored(
- tag='Tag#1',
- project_id=1
- )
- self.session.add(tagobj)
- self.session.flush()
- tagobj = model.TagColored(
- tag='Tag#2',
- project_id=1
- )
- self.session.add(tagobj)
- self.session.flush()
- # Create issues
- issue = model.Issue(
- id=pagure.lib.get_next_id(self.session, 1),
- project_id=1,
- title='Issue #1',
- content='Description #1',
- user_id=1,
- uid='Issue#1',
- private=False,
- )
- self.session.add(issue)
- self.session.commit()
- issue = model.Issue(
- id=pagure.lib.get_next_id(self.session, 1),
- project_id=1,
- title='Issue #2',
- content='Description #2',
- user_id=1,
- uid='Issue#2',
- private=False,
- )
- self.session.add(issue)
- self.session.commit()
- # Tag the issue
- tagissue = model.TagIssueColored(
- issue_uid='Issue#1',
- tag_id=1
- )
- self.session.add(tagissue)
- self.session.commit()
- tagissue = model.TagIssueColored(
- issue_uid='Issue#2',
- tag_id=2
- )
- self.session.add(tagissue)
- self.session.commit()
- self.assertEqual(
- self.session.query(model.Project).count(), 1)
- self.assertEqual(
- self.session.query(model.TagColored).count(), 2)
- self.assertEqual(
- self.session.query(model.Issue).count(), 2)
- project = self.session.query(
- model.Project
- ).filter(
- model.Project.id==1
- ).one()
- self.session.delete(project)
- self.session.commit()
- self.assertEqual(
- self.session.query(model.Project).count(), 0)
- self.assertEqual(
- self.session.query(model.TagColored).count(), 0)
- self.assertEqual(
- self.session.query(model.Issue).count(), 0)
- if __name__ == '__main__':
- unittest.main(verbosity=2)
|