Example #1
0
    def test_create_link(self, mock_create_short_link):
        mock_shortlink = models.ShortLink(
            id=123,
            created=datetime.datetime(2018, 10, 1),
            organization='googs.com',
            owner='*****@*****.**',
            shortpath='there',
            destination_url='http://example.com/there')

        mock_create_short_link.return_value = mock_shortlink

        response = self.testapp.post_json(
            '/_/api/links', {
                'shortpath': 'there',
                'destination': 'http://example.com/there'
            },
            headers={'TROTTO_USER_UNDER_TEST': '*****@*****.**'})

        self.assertEqual(
            {
                'oid': 123,
                'created': '2018-10-01 00:00:00',
                'owner': '*****@*****.**',
                'shortpath': 'there',
                'destination_url': 'http://example.com/there',
                'visits_count': 0
            }, json.loads(response.text))

        self.assertEqual(mock_create_short_link.call_args_list, [
            call('googs.com', '*****@*****.**', 'there',
                 'http://example.com/there')
        ])
Example #2
0
    def test_get_shortlinks_for_user(self):
        ndb.put_multi([
            models.ShortLink(id=1,
                             created=datetime.datetime(2018, 10, 1),
                             organization='googs.com',
                             owner='*****@*****.**',
                             shortpath='there',
                             destination_url='http://example.com'),
            models.ShortLink(id=2,
                             created=datetime.datetime(2018, 11, 1),
                             organization='googs.com',
                             owner='*****@*****.**',
                             shortpath='here',
                             destination_url='http://gmail.com'),
            models.ShortLink(id=3,
                             organization='widgets.com',
                             owner='*****@*****.**',
                             shortpath='elsewhere',
                             destination_url='http://drive.com')
        ])

        response = self.testapp.get(
            '/_/api/links',
            headers={'TROTTO_USER_UNDER_TEST': '*****@*****.**'})

        self.assertEqual([{
            'oid': 1,
            'created': '2018-10-01 00:00:00',
            'mine': True,
            'owner': '*****@*****.**',
            'shortpath': 'there',
            'destination_url': 'http://example.com',
            'visits_count': 0
        }, {
            'oid': 2,
            'created': '2018-11-01 00:00:00',
            'mine': False,
            'owner': '*****@*****.**',
            'shortpath': 'here',
            'destination_url': 'http://gmail.com',
            'visits_count': 0
        }], json.loads(response.text))
Example #3
0
    def test_update_link__go_link__successful(self):
        models.ShortLink(id=7,
                         organization='googs.com',
                         owner='*****@*****.**',
                         shortpath='there',
                         destination_url='http://example.com').put()

        self.testapp.put_json(
            '/_/api/links/7', {'destination': 'http://boop.com'},
            headers={'TROTTO_USER_UNDER_TEST': '*****@*****.**'})

        shortlink = models.ShortLink.get_by_id(7)

        self.assertEqual('http://boop.com', shortlink.destination_url)
Example #4
0
    def test_update_link__go_link_of_other_company(self):
        models.ShortLink(id=7,
                         organization='googs.com',
                         owner='*****@*****.**',
                         shortpath='there',
                         destination_url='http://drive.com').put()

        response = self.testapp.put_json(
            '/_/api/links/7', {'destination': 'http://boop.com'},
            headers={'TROTTO_USER_UNDER_TEST': '*****@*****.**'},
            expect_errors=True)

        self.assertEqual(403, response.status_int)

        shortlink = models.ShortLink.get_by_id(7)

        self.assertEqual('http://drive.com', shortlink.destination_url)
Example #5
0
    def test_update_link__go_link_of_other_user__is_admin_for_different_org(
            self, mock_is_user_admin):
        models.ShortLink(id=7,
                         organization='widgets.com',
                         owner='*****@*****.**',
                         shortpath='there',
                         destination_url='http://drive.com').put()

        response = self.testapp.put_json(
            '/_/api/links/7', {'destination': 'http://boop.com'},
            headers={'TROTTO_USER_UNDER_TEST': '*****@*****.**'},
            expect_errors=True)

        self.assertEqual(403, response.status_int)

        shortlink = models.ShortLink.get_by_id(7)

        self.assertEqual('http://drive.com', shortlink.destination_url)
Example #6
0
    def test_update_link__go_link_of_other_user__is_admin(
            self, mock_is_user_admin):
        models.ShortLink(id=7,
                         organization='googs.com',
                         owner='*****@*****.**',
                         shortpath='there',
                         destination_url='http://drive.com').put()

        self.testapp.put_json(
            '/_/api/links/7', {'destination': 'http://boop.com'},
            headers={'TROTTO_USER_UNDER_TEST': '*****@*****.**'})

        shortlink = models.ShortLink.get_by_id(7)

        self.assertEqual('http://boop.com', shortlink.destination_url)

        self.assertEqual(1, mock_is_user_admin.call_count)
        self.assertEqual('*****@*****.**',
                         mock_is_user_admin.call_args[0][0].email)
Example #7
0
    def _populate_test_links(self):
        test_shortlinks = [

            # company2 - go/drive
            models.ShortLink(id=13,
                             organization='2.com',
                             owner='*****@*****.**',
                             shortpath='drive',
                             shortpath_prefix='drive',
                             destination_url='http://drive3.com'),

            # company1 - go/drive
            models.ShortLink(id=14,
                             organization='1.com',
                             owner='*****@*****.**',
                             shortpath='drive',
                             shortpath_prefix='drive',
                             destination_url='http://drive4.com'),

            # company2 - go/drive/%s
            models.ShortLink(id=15,
                             organization='2.com',
                             owner='*****@*****.**',
                             shortpath='drive/%s',
                             shortpath_prefix='drive',
                             destination_url='http://drive5.com/%s'),

            # company1 - go/drive/%s
            models.ShortLink(id=16,
                             organization='1.com',
                             owner='*****@*****.**',
                             shortpath='drive/%s',
                             shortpath_prefix='drive',
                             destination_url='http://drive6.com/%s'),

            # company2 - go/paper/%s
            models.ShortLink(id=114,
                             organization='2.com',
                             owner='*****@*****.**',
                             shortpath='paper/%s',
                             shortpath_prefix='paper',
                             destination_url='http://paper.com/%s'),

            # company1 - go/sfdc/%s
            models.ShortLink(id=115,
                             organization='1.com',
                             owner='*****@*****.**',
                             shortpath='sfdc/%s',
                             shortpath_prefix='sfdc',
                             destination_url='http://sfdc.com/%s'),

            # company1 - go/looker/%s/%s
            models.ShortLink(id=116,
                             organization='1.com',
                             owner='*****@*****.**',
                             shortpath='looker/%s/%s',
                             shortpath_prefix='looker',
                             destination_url='http://looker.com/%s/search/%s'),
        ]

        ndb.put_multi(test_shortlinks)