def test_add_new_tag_utf8(self):
     '''
     Tries to make sure inserting tags with utf-8 chars does not blow things up
     Please see encoding on 1st line of file
     '''
     tag = u"18Наталь"
     unparsed_tag = "  18Наталь   "
     parsed_tag = parse_tag(tag)
     response = self.app.post('/cohorts/{0}/tag/add/{1}'
                              .format(self.cohort.id, unparsed_tag))
     assert_true(response.data.find('"tags":') >= 0)
     # TODO tag is coming like the following, that needs fixing
     # "tags": [
     #{
     #    "id": 14,
     #   "name": "18\u043d\u0430\u0442\u0430\u043b\u044c"
     #}
     self.session.commit()
     t = self.session.query(TagStore).filter(TagStore.name == parsed_tag).first()
     assert_true(t is not None)
def add_tag(cohort_id, tag):
    """
    Checks if tag exists in the tag table and then adds tag to the cohort.
    """
    if tag is None:
        return json_error(message='You cannot submit an empty tag.')
    parsed_tag = parse_tag(tag)
    session = db.get_session()
    data = {}
    try:
        t = session.query(TagStore).filter(TagStore.name == parsed_tag).first()
        if not t:
            t = TagStore(
                name=parsed_tag
            )
            session.add(t)
            session.commit()

        # Check if cohort is already tagged with 'tag'
        try:
            if g.cohort_service.get_tag(session, t, cohort_id, current_user.id):
                return json_response(exists=True)
        except Unauthorized:
            return json_error(message='You are not allowed to access this Cohort')

        # Add tag
        try:
            g.cohort_service.add_tag(session, t, cohort_id, current_user.id)
        except Unauthorized:
            return json_error(message='You are not allowed to access this Cohort')

        data['tags'] = populate_cohort_tags(cohort_id, session)

        tagsAutocompleteList = g.tag_service.get_all_tags(session)
        data['tagsAutocompleteList'] = json.dumps(tagsAutocompleteList)

    except DatabaseError as e:
        session.rollback()
        return json_error(e.message)

    return json_response(data)
Ejemplo n.º 3
0
 def test_add_new_tag_utf8(self):
     '''
     Tries to make sure inserting tags with utf-8 chars does not blow things up
     Please see encoding on 1st line of file
     '''
     tag = u"18Наталь"
     unparsed_tag = "  18Наталь   "
     parsed_tag = parse_tag(tag)
     response = self.app.post('/cohorts/{0}/tag/add/{1}'.format(
         self.cohort.id, unparsed_tag))
     assert_true(response.data.find('"tags":') >= 0)
     # TODO tag is coming like the following, that needs fixing
     # "tags": [
     #{
     #    "id": 14,
     #   "name": "18\u043d\u0430\u0442\u0430\u043b\u044c"
     #}
     self.session.commit()
     t = self.session.query(TagStore).filter(
         TagStore.name == parsed_tag).first()
     assert_true(t is not None)
Ejemplo n.º 4
0
def add_tag(cohort_id, tag):
    """
    Checks if tag exists in the tag table and then adds tag to the cohort.
    """
    if tag is None:
        return json_error(message='You cannot submit an empty tag.')
    parsed_tag = parse_tag(tag)
    session = db.get_session()
    try:
        t = session.query(TagStore).filter(TagStore.name == parsed_tag).first()
        if not t:
            t = TagStore(
                name=parsed_tag
            )
            session.add(t)
            session.commit()

        # Check if cohort is already tagged with 'tag'
        ct = session.query(CohortTagStore) \
            .filter(CohortTagStore.tag_id == t.id) \
            .filter(CohortTagStore.cohort_id == cohort_id) \
            .all()
        if ct:
            return json_response(exists=True)

        cohort_tag = CohortTagStore(
            tag_id=t.id,
            cohort_id=cohort_id,
        )
        session.add(cohort_tag)
        session.commit()
    except DatabaseError as e:
        session.rollback()
        return json_error(e.message)
    finally:
        session.close()

    data = {}
    populate_cohort_tags(data, cohort_id)
    return json_response(data)
 def test_parse_tag(self):
     tag = "  STRINGwithCaps and    SPaces   "
     parsed_tag = parse_tag(tag)
     assert_equal(parsed_tag, "stringwithcaps-and-spaces")
 def test_parse_tag(self):
     tag = "  STRINGwithCaps and    SPaces   "
     parsed_tag = parse_tag(tag)
     assert_equal(parsed_tag, "stringwithcaps-and-spaces")