Пример #1
0
    def test_get_home_member(self):
        user1 = '18868103391'
        user2 = '17862710056'
        scope = 'H'
        relation = '姐姐'

        create_relation(user1, user2, relation, 'test')

        update_user_scope(user1, user2, scope, relation)

        user1 = '18868103391'
        user2 = '13375746248'
        scope = 'H'
        relation = '姐姐'

        create_relation(user1, user2, relation, 'test')

        update_user_scope(user1, user2, scope, relation)

        data = get_home_member(user1)
        self.assertIsNotNone(data)

        friends_information = get_friend_information(data)
        print friends_information
        self.assertIsNotNone(friends_information)
Пример #2
0
    def test_get_involved_group(self):
        user1 = '18868103391'
        user2 = '17862710056'
        scope = 'H'
        relation = '姐姐'

        create_relation(user1, user2, relation, 'test')
        update_user_scope(user1, user2, scope, relation)

        scope_list = get_all_join_scope(user1)
        self.assertEqual(len(scope_list), 4)

        scope_list = get_all_join_scope(user2)
        self.assertEqual(len(scope_list), 4)
Пример #3
0
    def post(self, request):
        """
        Create a relation between two person.

        Support Type List:
            (
            妻子 丈夫 儿子 女儿 弟弟 哥哥 妹妹 姐姐 父亲 母亲
            孙子 孙女 女婿 媳妇 爷爷 奶奶 岳父 岳母 公公 婆婆
            朋友
            )

        ata:

            {
            "user1": varchar(), // user1 is 小明
            "user2": varchar(), // user2 is his mother
            "relation": varchar() // relation is 母亲
            "scope": <F, H, R>
            // if this person is your family, send H, means Home
            // if is other relations, send R, means Relation.
            //If this person is your friend, not
            // your any relation but is your friend. send F, means Friend
            "nickname": nickname  // required == false
            }

        return:

            - 201: relation created.
            - 406: Relation or Scope is not acceptable
            - 409: the relation is already existd.
            - 404: the user is not found.

        ---
        parameters:
        - name: user1
          description: user1 is 小明
          required: true
          type: string
          paramters: form

        - name: user2
          description: user1 is 妈妈
          required: true
          type: string
          paramters: form

        - name: relation
          description: relation is 母亲
          required: true
          type: string
          paramters: form

        - name: nickname
          description: nickname is 围裙妈妈
          required: false
          type: string
          paramters: form

        - name: scope
          description: scope is H
          required: true
          type: string
          parameters: form
        """

        user1 = request.data.get("user1", None)
        user2 = request.data.get("user2", None)
        relation = request.data.get("relation", None)
        nickname = request.data.get("nickname", "Nickname")
        scope = request.data.get("scope", None)

        user1_exist = check_user_exist(user1)
        user2_exist = check_user_exist(user2)

        if not user1_exist or not user2_exist:
            return Response(status=status.HTTP_404_NOT_FOUND)
        elif check_relation_exist(user1, user2):
            return Response(status=status.HTTP_409_CONFLICT)
        elif not check_relation_accept(relation):
            return Response(status=status.HTTP_406_NOT_ACCEPTABLE)
        else:
            create_relation(user1, user2, relation, nickname)
            update_user_scope(user1, user2, scope, relation)
            return Response(status=status.HTTP_201_CREATED)