|
6 | 6 | from django_factory_boy import auth
|
7 | 7 |
|
8 | 8 | from journalmanager.tests import modelfactories
|
| 9 | +from editorialmanager.tests import modelfactories as editorial_modelfactories |
9 | 10 | from articletrack.tests import modelfactories as articletrack_modelfactories
|
10 | 11 | from api.resources_v2 import (
|
11 | 12 | JournalResource,
|
@@ -1613,3 +1614,316 @@ def test_api_v2_data_checkin(self):
|
1613 | 1614 | ]
|
1614 | 1615 |
|
1615 | 1616 | self.assertEqual(sorted(response.json.keys()), sorted(expected_keys))
|
| 1617 | + |
| 1618 | + |
| 1619 | +class EditorialBoardRestAPITest(WebTest): |
| 1620 | + |
| 1621 | + def setUp(self): |
| 1622 | + self.api_path = '/api/v2/editorialboard/' |
| 1623 | + self.user = auth.UserF(is_active=True) |
| 1624 | + self.extra_environ = _make_auth_environ(self.user.username, self.user.api_key.key) |
| 1625 | + # setup collection |
| 1626 | + self.collection = modelfactories.CollectionFactory.create() |
| 1627 | + self.collection.add_user(self.user, is_manager=False) |
| 1628 | + self.collection.make_default_to_user(self.user) |
| 1629 | + # journal |
| 1630 | + self.journal = modelfactories.JournalFactory.create() |
| 1631 | + self.journal.join(self.collection, self.user) |
| 1632 | + #set the user as editor of the journal |
| 1633 | + self.journal.editor = self.user |
| 1634 | + self.journal.save() |
| 1635 | + # create an issue |
| 1636 | + self.issue = modelfactories.IssueFactory.create() |
| 1637 | + self.issue.journal = self.journal |
| 1638 | + self.journal.save() |
| 1639 | + self.issue.save() |
| 1640 | + |
| 1641 | + def tearDown(self): |
| 1642 | + pass |
| 1643 | + |
| 1644 | + def test_post_data(self): |
| 1645 | + """ method POST not allowed """ |
| 1646 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1647 | + self.assertEqual(response.status_code, 405) |
| 1648 | + |
| 1649 | + def test_put_data(self): |
| 1650 | + """ method PUT not allowed """ |
| 1651 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1652 | + self.assertEqual(response.status_code, 405) |
| 1653 | + |
| 1654 | + def test_del_data(self): |
| 1655 | + """ method DELETE not allowed """ |
| 1656 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1657 | + self.assertEqual(response.status_code, 405) |
| 1658 | + |
| 1659 | + def test_access_denied_for_unauthenticated_users(self): |
| 1660 | + response = self.app.get(self.api_path, status=401) |
| 1661 | + self.assertEqual(response.status_code, 401) |
| 1662 | + |
| 1663 | + def test_editorialboard_index(self): |
| 1664 | + # with |
| 1665 | + board = editorial_modelfactories.EditorialBoardFactory.create(issue=self.issue) |
| 1666 | + # when |
| 1667 | + response = self.app.get(self.api_path, extra_environ=self.extra_environ) |
| 1668 | + # then |
| 1669 | + self.assertEqual(response.status_code, 200) |
| 1670 | + self.assertTrue('objects' in response.content) |
| 1671 | + |
| 1672 | + def test_api_v2_data_editorialboard(self): |
| 1673 | + # with |
| 1674 | + board = editorial_modelfactories.EditorialBoardFactory.create(issue=self.issue) |
| 1675 | + target_url = "%s%s/" % (self.api_path, board.pk) |
| 1676 | + # when |
| 1677 | + response = self.app.get(target_url, extra_environ=self.extra_environ) |
| 1678 | + # then |
| 1679 | + expected_keys = [ |
| 1680 | + u'id', |
| 1681 | + u'issue', |
| 1682 | + u'resource_uri', |
| 1683 | + ] |
| 1684 | + self.assertEqual(sorted(response.json.keys()), sorted(expected_keys)) |
| 1685 | + |
| 1686 | + |
| 1687 | +class RoleTypeRestAPITest(WebTest): |
| 1688 | + |
| 1689 | + def setUp(self): |
| 1690 | + self.api_path = '/api/v2/roletype/' |
| 1691 | + self.user = auth.UserF(is_active=True) |
| 1692 | + self.extra_environ = _make_auth_environ(self.user.username, self.user.api_key.key) |
| 1693 | + |
| 1694 | + def tearDown(self): |
| 1695 | + pass |
| 1696 | + |
| 1697 | + def test_post_data(self): |
| 1698 | + """ method POST not allowed """ |
| 1699 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1700 | + self.assertEqual(response.status_code, 405) |
| 1701 | + |
| 1702 | + def test_put_data(self): |
| 1703 | + """ method PUT not allowed """ |
| 1704 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1705 | + self.assertEqual(response.status_code, 405) |
| 1706 | + |
| 1707 | + def test_del_data(self): |
| 1708 | + """ method DELETE not allowed """ |
| 1709 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1710 | + self.assertEqual(response.status_code, 405) |
| 1711 | + |
| 1712 | + def test_access_denied_for_unauthenticated_users(self): |
| 1713 | + response = self.app.get(self.api_path, status=401) |
| 1714 | + self.assertEqual(response.status_code, 401) |
| 1715 | + |
| 1716 | + def test_roletype_index(self): |
| 1717 | + # with |
| 1718 | + role = editorial_modelfactories.RoleTypeFactory.create() |
| 1719 | + # when |
| 1720 | + response = self.app.get(self.api_path, extra_environ=self.extra_environ) |
| 1721 | + # then |
| 1722 | + self.assertEqual(response.status_code, 200) |
| 1723 | + self.assertTrue('objects' in response.content) |
| 1724 | + |
| 1725 | + def test_api_v2_data_roletype(self): |
| 1726 | + # with |
| 1727 | + role = editorial_modelfactories.RoleTypeFactory.create() |
| 1728 | + target_url = "%s%s/" % (self.api_path, role.pk) |
| 1729 | + # when |
| 1730 | + response = self.app.get(target_url, extra_environ=self.extra_environ) |
| 1731 | + # then |
| 1732 | + expected_keys = [ |
| 1733 | + u'id', |
| 1734 | + u'name', |
| 1735 | + u'resource_uri', |
| 1736 | + ] |
| 1737 | + self.assertEqual(sorted(response.json.keys()), sorted(expected_keys)) |
| 1738 | + |
| 1739 | + |
| 1740 | +class RoleTypeTranslationRestAPITest(WebTest): |
| 1741 | + |
| 1742 | + def setUp(self): |
| 1743 | + self.api_path = '/api/v2/roletypetranslation/' |
| 1744 | + self.user = auth.UserF(is_active=True) |
| 1745 | + self.extra_environ = _make_auth_environ(self.user.username, self.user.api_key.key) |
| 1746 | + |
| 1747 | + def tearDown(self): |
| 1748 | + pass |
| 1749 | + |
| 1750 | + def test_post_data(self): |
| 1751 | + """ method POST not allowed """ |
| 1752 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1753 | + self.assertEqual(response.status_code, 405) |
| 1754 | + |
| 1755 | + def test_put_data(self): |
| 1756 | + """ method PUT not allowed """ |
| 1757 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1758 | + self.assertEqual(response.status_code, 405) |
| 1759 | + |
| 1760 | + def test_del_data(self): |
| 1761 | + """ method DELETE not allowed """ |
| 1762 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1763 | + self.assertEqual(response.status_code, 405) |
| 1764 | + |
| 1765 | + def test_access_denied_for_unauthenticated_users(self): |
| 1766 | + response = self.app.get(self.api_path, status=401) |
| 1767 | + self.assertEqual(response.status_code, 401) |
| 1768 | + |
| 1769 | + def test_roletypetranslation_index(self): |
| 1770 | + # with |
| 1771 | + role_i18n = editorial_modelfactories.RoleTypeTranslationFactory.create() |
| 1772 | + # when |
| 1773 | + response = self.app.get(self.api_path, extra_environ=self.extra_environ) |
| 1774 | + # then |
| 1775 | + self.assertEqual(response.status_code, 200) |
| 1776 | + self.assertTrue('objects' in response.content) |
| 1777 | + |
| 1778 | + def test_api_v2_data_roletypetranslation(self): |
| 1779 | + # with |
| 1780 | + role_i18n = editorial_modelfactories.RoleTypeTranslationFactory.create() |
| 1781 | + target_url = "%s%s/" % (self.api_path, role_i18n.pk) |
| 1782 | + # when |
| 1783 | + response = self.app.get(target_url, extra_environ=self.extra_environ) |
| 1784 | + # then |
| 1785 | + expected_keys = [ |
| 1786 | + u'id', |
| 1787 | + u'language', |
| 1788 | + u'name', |
| 1789 | + u'resource_uri', |
| 1790 | + u'role', |
| 1791 | + ] |
| 1792 | + self.assertEqual(sorted(response.json.keys()), sorted(expected_keys)) |
| 1793 | + |
| 1794 | + |
| 1795 | + |
| 1796 | +class EditorialMemberRestAPITest(WebTest): |
| 1797 | + |
| 1798 | + def setUp(self): |
| 1799 | + self.api_path = '/api/v2/editorialmember/' |
| 1800 | + self.user = auth.UserF(is_active=True) |
| 1801 | + self.extra_environ = _make_auth_environ(self.user.username, self.user.api_key.key) |
| 1802 | + # setup collection |
| 1803 | + self.collection = modelfactories.CollectionFactory.create() |
| 1804 | + self.collection.add_user(self.user, is_manager=False) |
| 1805 | + self.collection.make_default_to_user(self.user) |
| 1806 | + # journal |
| 1807 | + self.journal = modelfactories.JournalFactory.create() |
| 1808 | + self.journal.join(self.collection, self.user) |
| 1809 | + #set the user as editor of the journal |
| 1810 | + self.journal.editor = self.user |
| 1811 | + self.journal.save() |
| 1812 | + # create an issue |
| 1813 | + self.issue = modelfactories.IssueFactory.create() |
| 1814 | + self.issue.journal = self.journal |
| 1815 | + self.journal.save() |
| 1816 | + self.issue.save() |
| 1817 | + |
| 1818 | + def tearDown(self): |
| 1819 | + pass |
| 1820 | + |
| 1821 | + def test_post_data(self): |
| 1822 | + """ method POST not allowed """ |
| 1823 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1824 | + self.assertEqual(response.status_code, 405) |
| 1825 | + |
| 1826 | + def test_put_data(self): |
| 1827 | + """ method PUT not allowed """ |
| 1828 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1829 | + self.assertEqual(response.status_code, 405) |
| 1830 | + |
| 1831 | + def test_del_data(self): |
| 1832 | + """ method DELETE not allowed """ |
| 1833 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1834 | + self.assertEqual(response.status_code, 405) |
| 1835 | + |
| 1836 | + def test_access_denied_for_unauthenticated_users(self): |
| 1837 | + response = self.app.get(self.api_path, status=401) |
| 1838 | + self.assertEqual(response.status_code, 401) |
| 1839 | + |
| 1840 | + def test_editorialmember_index(self): |
| 1841 | + # with |
| 1842 | + member = editorial_modelfactories.EditorialMemberFactory.create() |
| 1843 | + # when |
| 1844 | + response = self.app.get(self.api_path, extra_environ=self.extra_environ) |
| 1845 | + # then |
| 1846 | + self.assertEqual(response.status_code, 200) |
| 1847 | + self.assertTrue('objects' in response.content) |
| 1848 | + |
| 1849 | + def test_api_v2_data_editorialmember(self): |
| 1850 | + # with |
| 1851 | + board = editorial_modelfactories.EditorialBoardFactory.create(issue=self.issue) |
| 1852 | + role = editorial_modelfactories.RoleTypeFactory.create() |
| 1853 | + member = editorial_modelfactories.EditorialMemberFactory.create(board=board, role=role, order=1) |
| 1854 | + target_url = "%s%s/" % (self.api_path, member.pk) |
| 1855 | + # when |
| 1856 | + response = self.app.get(target_url, extra_environ=self.extra_environ) |
| 1857 | + # then |
| 1858 | + expected_keys = [ |
| 1859 | + u'board', |
| 1860 | + u'city', |
| 1861 | + u'country', |
| 1862 | + u'email', |
| 1863 | + u'first_name', |
| 1864 | + u'id', |
| 1865 | + u'institution', |
| 1866 | + u'last_name', |
| 1867 | + u'link_cv', |
| 1868 | + u'orcid', |
| 1869 | + u'order', |
| 1870 | + u'research_id', |
| 1871 | + u'resource_uri', |
| 1872 | + u'role', |
| 1873 | + u'state' |
| 1874 | + ] |
| 1875 | + self.assertEqual(sorted(response.json.keys()), sorted(expected_keys)) |
| 1876 | + |
| 1877 | + |
| 1878 | +class LanguageRestAPITest(WebTest): |
| 1879 | + |
| 1880 | + def setUp(self): |
| 1881 | + self.api_path = '/api/v2/language/' |
| 1882 | + self.user = auth.UserF(is_active=True) |
| 1883 | + self.extra_environ = _make_auth_environ(self.user.username, self.user.api_key.key) |
| 1884 | + |
| 1885 | + def tearDown(self): |
| 1886 | + pass |
| 1887 | + |
| 1888 | + def test_post_data(self): |
| 1889 | + """ method POST not allowed """ |
| 1890 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1891 | + self.assertEqual(response.status_code, 405) |
| 1892 | + |
| 1893 | + def test_put_data(self): |
| 1894 | + """ method PUT not allowed """ |
| 1895 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1896 | + self.assertEqual(response.status_code, 405) |
| 1897 | + |
| 1898 | + def test_del_data(self): |
| 1899 | + """ method DELETE not allowed """ |
| 1900 | + response = self.app.delete(self.api_path, extra_environ=self.extra_environ, status=405) |
| 1901 | + self.assertEqual(response.status_code, 405) |
| 1902 | + |
| 1903 | + def test_access_denied_for_unauthenticated_users(self): |
| 1904 | + response = self.app.get(self.api_path, status=401) |
| 1905 | + self.assertEqual(response.status_code, 401) |
| 1906 | + |
| 1907 | + def test_language_index(self): |
| 1908 | + # with |
| 1909 | + language = modelfactories.LanguageFactory.create() |
| 1910 | + # when |
| 1911 | + response = self.app.get(self.api_path, extra_environ=self.extra_environ) |
| 1912 | + # then |
| 1913 | + self.assertEqual(response.status_code, 200) |
| 1914 | + self.assertTrue('objects' in response.content) |
| 1915 | + |
| 1916 | + def test_api_v2_data_language(self): |
| 1917 | + # with |
| 1918 | + language = modelfactories.LanguageFactory.create() |
| 1919 | + target_url = "%s%s/" % (self.api_path, language.pk) |
| 1920 | + # when |
| 1921 | + response = self.app.get(target_url, extra_environ=self.extra_environ) |
| 1922 | + # then |
| 1923 | + expected_keys = [ |
| 1924 | + u'id', |
| 1925 | + u'iso_code', |
| 1926 | + u'name', |
| 1927 | + u'resource_uri', |
| 1928 | + ] |
| 1929 | + self.assertEqual(sorted(response.json.keys()), sorted(expected_keys)) |
0 commit comments