test_pagure_lib_model.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2015 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. __requires__ = ['SQLAlchemy >= 0.8']
  8. import pkg_resources
  9. import unittest
  10. import shutil
  11. import sys
  12. import os
  13. from mock import patch
  14. sys.path.insert(0, os.path.join(os.path.dirname(
  15. os.path.abspath(__file__)), '..'))
  16. import pagure.lib
  17. import tests
  18. class PagureLibModeltests(tests.Modeltests):
  19. """ Tests for pagure.lib.model """
  20. def test_user__repr__(self):
  21. """ Test the User.__repr__ function of pagure.lib.model. """
  22. item = pagure.lib.search_user(self.session, email='foo@bar.com')
  23. self.assertEqual(str(item), 'User: 2 - name foo')
  24. self.assertEqual('foo', item.user)
  25. self.assertEqual('foo', item.username)
  26. self.assertEqual([], item.groups)
  27. @patch('pagure.lib.git.update_git')
  28. @patch('pagure.lib.notify.send_email')
  29. def test_issue__repr__(self, p_send_email, p_ugt):
  30. """ Test the Issue.__repr__ function of pagure.lib.model. """
  31. p_send_email.return_value = True
  32. p_ugt.return_value = True
  33. tests.create_projects(self.session)
  34. repo = pagure.lib.get_project(self.session, 'test')
  35. # Create an issue
  36. msg = pagure.lib.new_issue(
  37. session=self.session,
  38. repo=repo,
  39. title='Test issue',
  40. content='We should work on this',
  41. user='pingou',
  42. ticketfolder=None
  43. )
  44. self.assertEqual(msg.title, 'Test issue')
  45. issues = pagure.lib.search_issues(self.session, repo)
  46. self.assertEqual(len(issues), 1)
  47. self.assertEqual(
  48. str(issues[0]),
  49. 'Issue(1, project:test, user:pingou, title:Test issue)')
  50. @patch('pagure.lib.git.update_git')
  51. @patch('pagure.lib.notify.send_email')
  52. def test_pullrequest__repr__(self, p_send_email, p_ugt):
  53. """ Test the PullRequest.__repr__ function of pagure.lib.model. """
  54. p_send_email.return_value = True
  55. p_ugt.return_value = True
  56. tests.create_projects(self.session)
  57. # Create a forked repo
  58. item = pagure.lib.model.Project(
  59. user_id=1, # pingou
  60. name='test',
  61. description='test project #1',
  62. is_fork=True,
  63. parent_id=1,
  64. hook_token='aaabbbyyy',
  65. )
  66. self.session.commit()
  67. self.session.add(item)
  68. repo = pagure.lib.get_project(self.session, 'test')
  69. forked_repo = pagure.lib.get_project(
  70. self.session, 'test', user='pingou')
  71. # Create an pull-request
  72. req = pagure.lib.new_pull_request(
  73. session=self.session,
  74. repo_from=forked_repo,
  75. branch_from='master',
  76. repo_to=repo,
  77. branch_to='master',
  78. title='test pull-request',
  79. user='pingou',
  80. requestfolder=None,
  81. )
  82. self.assertEqual(req.id, 1)
  83. self.assertEqual(req.title, 'test pull-request')
  84. self.assertEqual(
  85. str(req),
  86. 'PullRequest(1, project:test, user:pingou, '
  87. 'title:test pull-request)')
  88. request = pagure.lib.search_pull_requests(self.session, requestid=1)
  89. self.assertEqual(
  90. str(request),
  91. 'PullRequest(1, project:test, user:pingou, '
  92. 'title:test pull-request)')
  93. def test_paguregroup__repr__(self):
  94. """ Test the PagureGroup.__repr__ function of pagure.lib.model. """
  95. item = pagure.lib.model.PagureGroup(
  96. group_name='admin',
  97. display_name='admin group',
  98. description='the local admin group',
  99. user_id=1,
  100. )
  101. self.session.add(item)
  102. self.session.commit()
  103. self.assertEqual(str(item), 'Group: 1 - name admin')
  104. def test_tagissue__repr__(self):
  105. """ Test the TagIssue.__repr__ function of pagure.lib.model. """
  106. self.test_issue__repr__()
  107. repo = pagure.lib.get_project(self.session, 'test')
  108. issues = pagure.lib.search_issues(self.session, repo)
  109. self.assertEqual(len(issues), 1)
  110. item = pagure.lib.model.Tag(tag='foo')
  111. self.session.add(item)
  112. self.session.commit()
  113. item = pagure.lib.model.TagIssue(
  114. issue_uid=issues[0].uid,
  115. tag='foo',
  116. )
  117. self.session.add(item)
  118. self.session.commit()
  119. self.assertEqual(str(item), 'TagIssue(issue:1, tag:foo)')
  120. if __name__ == '__main__':
  121. SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureLibModeltests)
  122. unittest.TextTestRunner(verbosity=2).run(SUITE)