Пример #1
0
    def test_create_shortlink__owner_does_not_match_org(self):
        with self.assertRaises(helpers.LinkCreationException) as cm:
            helpers.create_short_link('1.com', '*****@*****.**', 'drive',
                                      'drive1000.com')

        self.assertEqual(
            "The go link's owner must be in the go link's organization",
            str(cm.exception))
Пример #2
0
    def test_create_shortlink__go_link_already_exists(self):
        with self.assertRaises(helpers.LinkCreationException) as cm:
            helpers.create_short_link('1.com', '*****@*****.**', 'drive',
                                      'drive1000.com')

        self.assertEqual(
            'That go link already exists. go/drive points to http://drive4.com',
            str(cm.exception))
Пример #3
0
    def test_create_short_link__conflicting_hierarchical_link(self):
        with self.assertRaises(helpers.LinkCreationException) as cm:
            helpers.create_short_link('1.com', '*****@*****.**', 'go', 'trotto/%s',
                                      'https://www.trot.to/q=%s')

        self.assertEqual(
            'A conflicting go link already exists. go/trotto/docs points to http://www.trot.to/docs',
            str(cm.exception))
Пример #4
0
    def test_create_short_link__conflicting_programmatic_link(self):
        with self.assertRaises(helpers.LinkCreationException) as cm:
            helpers.create_short_link('1.com', '*****@*****.**', 'go',
                                      'drive/recent', 'drive.com/recent')

        self.assertEqual(
            'A conflicting go link already exists. go/drive/%s points to http://drive.com/%s',
            str(cm.exception))
Пример #5
0
    def test_create_short_link__non_placeholder_after_placeholder(self):
        with self.assertRaises(helpers.LinkCreationException) as cm:
            helpers.create_short_link('1.com', '*****@*****.**', 'go',
                                      'trotto/%s/q',
                                      'https://www.trot.to/q=%s')

        self.assertEqual(
            'After the first "%s" placeholder, you can only have additional placeholders',
            str(cm.exception))
Пример #6
0
  def test_create_shortlink__successful_go_link_creation_with_same_link_at_other_company(self):
    new_link = helpers.create_short_link('1.com', '*****@*****.**', 'paper/%s', 'paper2.com/search/%s')

    self.assert_entity_attributes({'organization': '1.com',
                                   'owner': '*****@*****.**',
                                   'shortpath': 'paper/%s',
                                   'shortpath_prefix': 'paper',
                                   'destination_url': 'http://paper2.com/search/%s',
                                   'visits_count': None,
                                   'visits_count_last_updated': None},
                                  new_link)
Пример #7
0
  def test_create_shortlink__successful_go_link_creation(self):
    new_link = helpers.create_short_link('1.com', '*****@*****.**', 'there', 'example.com')

    self.assert_entity_attributes({'organization': '1.com',
                                   'owner': '*****@*****.**',
                                   'shortpath': 'there',
                                   'shortpath_prefix': 'there',
                                   'destination_url': 'http://example.com',
                                   'visits_count': None,
                                   'visits_count_last_updated': None},
                                  new_link)
Пример #8
0
def post_link():
  object_data = request.json

  try:
    new_link = helpers.create_short_link(current_user.organization,
                                         current_user.email,
                                         object_data['shortpath'],
                                         object_data['destination'])
  except helpers.LinkCreationException as e:
    return jsonify({
      'error': str(e)
    })

  return jsonify(
    convert_entity_to_dict(new_link, PUBLIC_KEYS, get_field_conversion_fns())
  )
Пример #9
0
def post_link():
    object_data = request.json

    if 'owner' in object_data and not user_helpers.is_user_admin(current_user):
        abort(403)

    try:
        new_link = helpers.create_short_link(
            current_user.organization,
            object_data.get('owner', current_user.email),
            object_data['shortpath'], object_data['destination'])
    except helpers.LinkCreationException as e:
        return jsonify({'error': str(e)})

    logging.info(f'{current_user.email} created go link with ID {new_link.id}')

    return jsonify(
        convert_entity_to_dict(new_link, PUBLIC_KEYS,
                               get_field_conversion_fns())), 201