test_pagure_lib_model.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. parent_id=1,
  63. hook_token='aaabbbyyy',
  64. )
  65. self.session.commit()
  66. self.session.add(item)
  67. repo = pagure.lib.get_project(self.session, 'test')
  68. forked_repo = pagure.lib.get_project(
  69. self.session, 'test', user='pingou')
  70. # Create an pull-request
  71. req = pagure.lib.new_pull_request(
  72. session=self.session,
  73. repo_from=forked_repo,
  74. branch_from='master',
  75. repo_to=repo,
  76. branch_to='master',
  77. title='test pull-request',
  78. user='pingou',
  79. requestfolder=None,
  80. )
  81. self.assertEqual(req.id, 1)
  82. self.assertEqual(req.title, 'test pull-request')
  83. self.assertEqual(
  84. str(req),
  85. 'PullRequest(1, project:test, user:pingou, '
  86. 'title:test pull-request)')
  87. request = pagure.lib.search_pull_requests(self.session, requestid=1)
  88. self.assertEqual(
  89. str(request),
  90. 'PullRequest(1, project:test, user:pingou, '
  91. 'title:test pull-request)')
  92. def test_paguregroup__repr__(self):
  93. """ Test the PagureGroup.__repr__ function of pagure.lib.model. """
  94. item = pagure.lib.model.PagureGroup(
  95. group_name='admin',
  96. user_id=1,
  97. )
  98. self.session.add(item)
  99. self.session.commit()
  100. self.assertEqual(str(item), 'Group: 1 - name admin')
  101. def test_tagissue__repr__(self):
  102. """ Test the TagIssue.__repr__ function of pagure.lib.model. """
  103. self.test_issue__repr__()
  104. repo = pagure.lib.get_project(self.session, 'test')
  105. issues = pagure.lib.search_issues(self.session, repo)
  106. self.assertEqual(len(issues), 1)
  107. item = pagure.lib.model.Tag(tag='foo')
  108. self.session.add(item)
  109. self.session.commit()
  110. item = pagure.lib.model.TagIssue(
  111. issue_uid=issues[0].uid,
  112. tag='foo',
  113. )
  114. self.session.add(item)
  115. self.session.commit()
  116. self.assertEqual(str(item), 'TagIssue(issue:1, tag:foo)')
  117. if __name__ == '__main__':
  118. SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureLibModeltests)
  119. unittest.TextTestRunner(verbosity=2).run(SUITE)