def test_get(self):
        a = Analysis(1)
        u = User('*****@*****.**')
        self.assertEqual(a.shared_with, [u])

        # deselecting
        args = {'deselected': u.id, 'id': a.id}
        response = self.get('/analysis/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {'users': [], 'links': ''}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(a.shared_with, [])

        # Make sure unshared message added to the system
        self.assertEqual("Analysis 'SomeAnalysis' has been unshared with you.",
                         u.messages()[0][1])

        # selecting
        args = {'selected': u.id, 'id': a.id}
        response = self.get('/analysis/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {
            'users': ['*****@*****.**'],
            'links':
            ('<a target="_blank" href="mailto:[email protected]">Shared</a>')
        }
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(a.shared_with, [u])

        # Make sure shared message added to the system
        self.assertEqual(
            'Analysis <a href="/analysis/description/1">\'SomeAnalysis\'</a> '
            'has been shared with you.',
            u.messages()[0][1])
Beispiel #2
0
    def test_messages(self):
        add_system_message('SYS MESSAGE', datetime.now())
        user = User('*****@*****.**')
        obs = user.messages()
        exp_msg = [
            (4, 'SYS MESSAGE'),
            (1, 'message 1'),
            (2, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
                'Pellentesque sed auctor ex, non placerat sapien. Vestibulum '
                'vestibulum massa ut sapien condimentum, cursus consequat diam'
                ' sodales. Nulla aliquam arcu ut massa auctor, et vehicula '
                'mauris tempor. In lacinia viverra ante quis pellentesque. '
                'Nunc vel mi accumsan, porttitor eros ut, pharetra elit. Nulla'
                ' ac nisi quis dui egestas malesuada vitae ut mauris. Morbi '
                'blandit non nisl a finibus. In erat velit, congue at ipsum '
                'sit amet, venenatis bibendum sem. Curabitur vel odio sed est '
                'rutrum rutrum. Quisque efficitur ut purus in ultrices. '
                'Pellentesque eu auctor justo.'),
            (3, 'message <a href="#">3</a>')]
        self.assertEqual([(x[0], x[1]) for x in obs], exp_msg)
        self.assertTrue(all(x[2] < datetime.now() for x in obs))
        self.assertFalse(all(x[3] for x in obs))
        self.assertEqual([x[4] for x in obs], [True, False, False, False])

        obs = user.messages(1)
        exp_msg = ['SYS MESSAGE']
        self.assertEqual([x[1] for x in obs], exp_msg)
Beispiel #3
0
    def test_mark_messages(self):
        user = User('*****@*****.**')
        user.mark_messages([1, 2])
        obs = user.messages()
        exp = [True, True, False]
        self.assertEqual([x[3] for x in obs], exp)

        user.mark_messages([1], read=False)
        obs = user.messages()
        exp = [False, True, False]
        self.assertEqual([x[3] for x in obs], exp)
    def test_get(self):
        a = Analysis(1)
        u = User('*****@*****.**')
        self.assertEqual(a.shared_with, [u])

        # deselecting
        args = {'deselected': u.id, 'id': a.id}
        response = self.get('/analysis/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {'users': [], 'links': ''}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(a.shared_with, [])

        # Make sure unshared message added to the system
        self.assertEqual("Analysis 'SomeAnalysis' has been unshared with you.",
                         u.messages()[0][1])

        # selecting
        args = {'selected': u.id, 'id': a.id}
        response = self.get('/analysis/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {
            'users': ['*****@*****.**'],
            'links':
                ('<a target="_blank" href="mailto:[email protected]">Shared</a>')}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(a.shared_with, [u])

        # Make sure shared message added to the system
        self.assertEqual(
            'Analysis <a href="/analysis/description/1/">\'SomeAnalysis\'</a> '
            'has been shared with you.', u.messages()[0][1])

        # admins can share
        BaseHandler.get_current_user = Mock(return_value=User("*****@*****.**"))
        args = {'deselected': u.id, 'id': a.id}
        response = self.get('/analysis/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {'users': [], 'links': ''}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(a.shared_with, [])
    def test_get_deselected(self):
        s = Study(1)
        u = User('*****@*****.**')
        args = {'deselected': u.id, 'id': s.id}
        self.assertEqual(s.shared_with, [u])
        response = self.get('/study/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {'users': [], 'links': ''}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(s.shared_with, [])

        # Make sure unshared message added to the system
        self.assertEqual('Study \'Identification of the Microbiomes for '
                         'Cannabis Soils\' has been unshared from you.',
                         u.messages()[0][1])
Beispiel #6
0
    def test_delete_messages(self):
        # Make message 1 a system message
        sql = """UPDATE qiita.message
                 SET expiration = '2015-08-05'
                 WHERE message_id = 1"""
        self.conn_handler.execute(sql)
        user = User('*****@*****.**')
        user.delete_messages([1, 2])
        obs = user.messages()
        exp_msg = [(3, 'message <a href="#">3</a>')]
        self.assertItemsEqual([(x[0], x[1]) for x in obs], exp_msg)

        sql = "SELECT message_id FROM qiita.message"
        obs = self.conn_handler.execute_fetchall(sql)
        self.assertItemsEqual(obs, [[1], [3]])
Beispiel #7
0
    def test_get_deselected(self):
        a = Analysis(1)
        u = User('*****@*****.**')
        args = {'deselected': u.id, 'id': a.id}
        self.assertEqual(a.shared_with, [u])
        response = self.get('/analysis/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {'users': [], 'links': ''}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(a.shared_with, [])

        # Make sure unshared message added to the system
        self.assertEqual('Analysis \'SomeAnalysis\' has been unshared from '
                         'you.', u.messages()[0][1])
        # Share the analysis back with the user
        a.share(u)
    def test_get_deselected(self):
        s = Analysis(1)
        u = User('*****@*****.**')
        args = {'deselected': u.id, 'id': s.id}
        self.assertEqual(s.shared_with, [u])
        response = self.get('/analysis/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {'users': [], 'links': ''}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(s.shared_with, [])

        # Make sure unshared message added to the system
        self.assertEqual(
            'Analysis \'SomeAnalysis\' has been unshared from '
            'you.',
            u.messages()[0][1])
Beispiel #9
0
    def test_get_deselected(self):
        s = Study(1)
        u = User('*****@*****.**')
        args = {'deselected': u.id, 'id': s.id}
        self.assertEqual(s.shared_with, [u])
        response = self.get('/study/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {'users': [], 'links': ''}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(s.shared_with, [])

        # Make sure unshared message added to the system
        self.assertEqual(
            'Study \'Identification of the Microbiomes for '
            'Cannabis Soils\' has been unshared from you.',
            u.messages()[0][1])
Beispiel #10
0
    def test_get_selected(self):
        s = Analysis(1)
        u = User('*****@*****.**')
        args = {'selected': u.id, 'id': s.id}
        response = self.get('/analysis/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {
            'users': ['*****@*****.**', u.id],
            'links':
                ('<a target="_blank" href="mailto:[email protected]">Shared</a>, '
                 '<a target="_blank" href="mailto:[email protected]">Admin</a>')}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(s.shared_with, [User('*****@*****.**'), u])

        # Make sure shared message added to the system
        self.assertEqual('Analysis <a href="/analysis/results/1">'
                         '\'SomeAnalysis\'</a> has been shared with you.',
                         u.messages()[0][1])
Beispiel #11
0
    def test_get_selected(self):
        s = Study(1)
        u = User('*****@*****.**')
        args = {'selected': u.id, 'id': s.id}
        response = self.get('/study/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {
            'users': ['*****@*****.**', u.id],
            'links':
                ('<a target="_blank" href="mailto:[email protected]">Shared</a>, '
                 '<a target="_blank" href="mailto:[email protected]">Admin</a>')}
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(s.shared_with, [User('*****@*****.**'), u])

        # Make sure shared message added to the system
        self.assertEqual('Study <a href="/study/description/1">'
                         '\'Identification of the Microbiomes for Cannabis '
                         'Soils\'</a> has been shared with you.',
                         u.messages()[0][1])
    def test_get_selected(self):
        s = Analysis(1)
        u = User('*****@*****.**')
        args = {'selected': u.id, 'id': s.id}
        response = self.get('/analysis/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {
            'users': ['*****@*****.**', u.id],
            'links':
            ('<a target="_blank" href="mailto:[email protected]">Shared</a>, '
             '<a target="_blank" href="mailto:[email protected]">Admin</a>')
        }
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(s.shared_with, [User('*****@*****.**'), u])

        # Make sure shared message added to the system
        self.assertEqual(
            'Analysis <a href="/analysis/results/1">'
            '\'SomeAnalysis\'</a> has been shared with you.',
            u.messages()[0][1])
Beispiel #13
0
    def test_get_selected(self):
        s = Study(1)
        u = User('*****@*****.**')
        args = {'selected': u.id, 'id': s.id}
        response = self.get('/study/sharing/', args)
        self.assertEqual(response.code, 200)
        exp = {
            'users': ['*****@*****.**', u.id],
            'links':
            ('<a target="_blank" href="mailto:[email protected]">Shared</a>, '
             '<a target="_blank" href="mailto:[email protected]">Admin</a>')
        }
        self.assertEqual(loads(response.body), exp)
        self.assertEqual(s.shared_with, [User('*****@*****.**'), u])

        # Make sure shared message added to the system
        self.assertEqual(
            'Study <a href="/study/description/1">'
            '\'Identification of the Microbiomes for Cannabis '
            'Soils\'</a> has been shared with you.',
            u.messages()[0][1])