示例#1
0
 def test_content_property(self):
     test_data = '경기도 하남시 풍산로 270, 206동 402호 (선동, 미사강변도시2단지)'
     addr, is_created = Address.get_or_create_smart(test_data)
     saved = Address.objects.first()
     self.assertEqual(addr.content, test_data)
     self.assertEqual(saved, addr)
     self.assertEqual(saved.id, addr.id)
     self.assertEqual(saved.content, addr.content)
示例#2
0
    def __skip__test_access_methods(self):
        test_data = '경기도 하남시 풍산로 270, 206동 402호 (선동, 미사강변도시2단지)'
        addr, is_created = Address.get_or_create_smart(test_data)

        path = Path(addr.path_accessed)
        if path.exists():
            path.unlink()

        self.assertEqual(path.exists(), False)
        addr.access_force()
        self.assertEqual(path.exists(), True)
示例#3
0
 def test_save_and_retreive(self):
     test_data = '경기도 하남시 풍산로 270, 206동 402호 (선동, 미사강변도시2단지)'
     addr, is_created = Address.get_or_create_smart(test_data)
     saved = Address.objects.first()
     self.assertEqual(addr.uuid, '%s.addr' % b16encode(addr.id.bytes))
     self.assertEqual(saved, addr)
     self.assertEqual(saved.id, addr.id)
     saved2 = Address.get_from_json('{"uuid": "%s", "content": null}' % addr.uuid)
     self.assertEqual(saved2, addr)
     saved3 = Address.get_from_json('{"uuid": null, "content": "%s"}' % addr.content)
     self.assertEqual(saved3, addr)
示例#4
0
    def setUp(self):
        super(PostPieceTest, self).setUp()
        self.place = Place()
        self.place.save()
        self.uplace = UserPlace()
        self.uplace.save()
        self.vd = VD()
        self.vd.save()

        self.image, is_created = Image.get_or_create_smart(
            'http://blogthumb2.naver.net/20160302_285/mardukas_1456922688406bYGAH_JPEG/DSC07301.jpg'
        )
        self.url, is_created = Url.get_or_create_smart('http://www.naver.com/')

        self.lp, is_created = LegacyPlace.get_or_create_smart(
            '4ccffc63f6378cfaace1b1d6.4square')
        self.addr, is_created = Address.get_or_create_smart(
            '경기도 하남시 풍산로 270, 206동 402호 (선동, 미사강변도시2단지)')
        self.phone, is_created = PhoneNumber.get_or_create_smart(
            '010-5597-9245')
示例#5
0
 def test_string_representation(self):
     test_data = '경기도 하남시 풍산로 270, 206동 402호 (선동, 미사강변도시2단지)'
     addr, is_created = Address.get_or_create_smart(test_data)
     self.assertEqual(unicode(addr), test_data)
示例#6
0
    def test_post(self):
        place = Place()
        place.save()
        vd1 = VD()
        vd1.save()
        uplace1 = UserPlace(vd=vd1, place=place)
        uplace1.save()
        point1 = GEOSGeometry('POINT(127 37)', srid=4326)
        name1, is_created = PlaceName.get_or_create_smart('능라')
        addr1, is_created = Address.get_or_create_smart(
            '경기도 성남시 분당구 운중동 883-3')
        note11, is_created = PlaceNote.get_or_create_smart('분당 냉면 최고')
        note12, is_created = PlaceNote.get_or_create_smart('만두도 괜찮음')
        imgNote1, is_created = ImageNote.get_or_create_smart('냉면 사진')
        img1_content = 'http://blogthumb2.naver.net/20160302_285/mardukas_1456922688406bYGAH_JPEG/DSC07301.jpg'
        img1, is_created = Image.get_or_create_smart(img1_content)
        phone1, is_created = PhoneNumber.get_or_create_smart('010-5686-1613')

        vd2 = VD()
        vd2.save()
        uplace2 = UserPlace(vd=vd2, place=place)
        uplace2.save()
        point2 = GEOSGeometry('POINT(127.1037430 37.3997320)', srid=4326)
        name2, is_created = PlaceName.get_or_create_smart('능라도')
        addr2, is_created = Address.get_or_create_smart(
            '경기도 성남시 분당구 산운로32번길 12')
        note21, is_created = PlaceNote.get_or_create_smart('여기 가게 바로 옆으로 이전')
        note22, is_created = PlaceNote.get_or_create_smart('평양냉면 맛집')
        img21_content = 'http://blogpfthumb.phinf.naver.net/20100110_16/mardukas_1263055491560_VI01Ic_JPG/DSCN1968.JPG'
        img22_content = 'http://mblogthumb3.phinf.naver.net/20160807_298/mardukas_14705287064440EYVC_JPEG/DSC03530.JPG?type=w800'
        img21, is_created = Image.get_or_create_smart(img21_content)
        img22, is_created = Image.get_or_create_smart(img22_content)
        imgNote2, is_created = ImageNote.get_or_create_smart('만두 사진')
        url2, is_created = Url.get_or_create_smart('http://www.naver.com/')
        lp, is_created = LegacyPlace.get_or_create_smart(
            '4ccffc63f6378cfaace1b1d6.4square')
        phone2, is_created = PhoneNumber.get_or_create_smart('010-5597-9245')

        json_userPost = '''
            {
                "lonLat": {"lon": %f, "lat": %f},
                "name": {"uuid": "%s", "content": "%s"},
                "addr2": {"uuid": "%s", "content": "%s"},
                "notes": [{"uuid": "%s", "content": "%s"}, {"uuid": "%s", "content": "%s"}],
                "images": [{"uuid": "%s", "content": "%s", "note": {"uuid": "%s", "content": "%s"}}],
                "urls": [],
                "lps": [],
                "phone": {"uuid": "%s", "content": "%s"}
            }
        ''' % (
            point1.x,
            point1.y,
            name1.uuid,
            name1.content,
            addr1.uuid,
            addr1.content,
            note12.uuid,
            note12.content,
            note11.uuid,
            note11.content,
            img1.uuid,
            img1.content,
            imgNote1.uuid,
            imgNote1.content,
            phone1.uuid,
            phone1.content,
        )
        json_placePost = '''
            {
                "lonLat": {"lon": %f, "lat": %f},
                "name": {"uuid": "%s", "content": "%s"},
                "addr1": {"uuid": "%s", "content": "%s"},
                "addr2": {"uuid": "%s", "content": "%s"},
                "notes": [
                    {"uuid": "%s", "content": "%s"},
                    {"uuid": "%s", "content": "%s"},
                    {"uuid": "%s", "content": "%s"},
                    {"uuid": "%s", "content": "%s"}
                ],
                "images": [
                    {"uuid": "%s", "content": "%s", "note": null},
                    {"uuid": "%s", "content": "%s", "note": {"uuid": "%s", "content": "%s"}},
                    {"uuid": "%s", "content": "%s", "note": {"uuid": "%s", "content": "%s"}}
                ],
                "urls": [{"uuid": "%s", "content": "%s"}],
                "lps": [{"uuid": "%s", "content": "%s"}],
                "phone": {"uuid": "%s", "content": "%s"}
            }
        ''' % (
            point2.x,
            point2.y,
            name2.uuid,
            name2.content,
            addr2.uuid,
            addr2.content,
            addr1.uuid,
            addr1.content,
            note22.uuid,
            note22.content,
            note21.uuid,
            note21.content,
            note12.uuid,
            note12.content,
            note11.uuid,
            note11.content,
            img22.uuid,
            img22.content,
            img21.uuid,
            img21.content,
            imgNote2.uuid,
            imgNote2.content,
            img1.uuid,
            img1.content,
            imgNote1.uuid,
            imgNote1.content,
            url2.uuid,
            url2.content,
            lp.uuid,
            lp.content,
            phone2.uuid,
            phone2.content,
        )
        pb1 = PostBase(json_userPost)
        pb2 = PostBase(json_placePost)
        self.assertEqual(PostPiece.objects.count(), 0)
        pp1 = PostPiece.create_smart(uplace1, pb1)
        self.assertEqual(PostPiece.objects.count(), 1)
        pp2 = PostPiece.create_smart(uplace2, pb2)
        pp3 = PostPiece.create_smart_4place(place, vd1, pb2, by_MAMMA=True)
        self.assertEqual(PostPiece.objects.count(), 3)

        want_userPost = json_loads(json_userPost)
        want_placePost = json_loads(json_placePost)

        self.assertNotIn('timestamp', uplace1.userPost.json['lonLat'])
        self.assertNotIn('timestamp', uplace1.userPost.json['name'])
        self.assertIn('timestamp', uplace1.userPost.json['notes'][0])
        self.assertNotIn('timestamp', uplace1.userPost.json['images'][0])
        self.assertIn('timestamp', uplace1.userPost.json['images'][0]['note'])

        self.assertNotIn('timestamp', uplace2.userPost.json['urls'][0])
        self.assertNotIn('timestamp', uplace2.userPost.json['lps'][0])
        timestamp = uplace1.userPost.json['notes'][0]['timestamp']
        self.assertAlmostEqual(get_timestamp(), timestamp, delta=1000)
        self.assertIn('summary', uplace1.userPost.json['images'][0])
        self.assertIn('phone', uplace1.userPost.json)
        self.assertNotEqual(uplace1.userPost.json['images'][0]['content'],
                            None)

        self.assertIsSubsetOf(want_userPost, uplace1.userPost)
        self.assertIsNotSubsetOf(uplace1.userPost, want_userPost)

        self.assertIsSubsetOf(want_placePost, uplace1.place.placePost)
        self.assertIsNotSubsetOf(uplace1.place.placePost, want_placePost)
        uplace1._clearCache()
        p1 = uplace1.place.placePost
        uplace2._clearCache()
        p2 = uplace2.place.placePost
        place._clearCache()
        p3 = place.placePost
        self.assertDictEqual(p1.json, p3.json)
        self.assertDictEqual(p2.json, p3.json)

        pb12 = PostBase(json_userPost)
        pb12.update(pb1)
        self.assertNotEqual(pb12.json, pb1.json)
        pb12.normalize()
        self.assertEqual(pb12.json, pb1.json)

        pb13 = PostBase(json_userPost)
        pb13.update(pb1)
        pb13.update(pb1, add=False)
        pb_null = PostBase()
        self.assertEqual(pb13.json, pb_null.json)

        totalPost = place._totalPost
        self.assertIsSubsetOf(uplace1.place.placePost, totalPost)
        #self.assertIsSubsetOf(uplace1.userPost, totalPost)     # Note 에서 timestamp 를 제거해야...
        #self.assertIsSubsetOf(uplace2.userPost, totalPost)     # 상동
        #self.assertIsNotSubsetOf(totalPost, uplace1.place.placePost)   # userPost 를 하나 더 생성해야...

        # child/parent test
        uplace3 = UserPlace.objects.create(parent=uplace1)
        self.assertEqual(uplace3.parent, uplace1)
        self.assertNotEqual(uplace3.userPost, uplace1.userPost)
        self.printJson(uplace3.userPost.json)
        self.printJson(uplace1.userPost.json)
        self.assertEqual(uplace3.userPost.json, uplace1.userPost.json)
        uplace1._clearCache()
        uplace3._clearCache()
        pb3 = PostBase('{"notes": [{"content": "child"}]}')
        pp3 = PostPiece.create_smart(uplace3, pb3)
        self.assertNotEqual(uplace3.userPost, uplace1.userPost)
        self.assertNotEqual(uplace3.userPost.json, uplace1.userPost.json)

        place4 = Place.objects.create()
        uplace4 = UserPlace.objects.create(parent=uplace1,
                                           vd=vd1,
                                           place=place4)
        self.assertEqual(uplace4.parent, uplace1)
        self.assertNotEqual(uplace4.userPost, uplace1.userPost)
        self.assertEqual(uplace4.userPost.json, uplace1.userPost.json)
        uplace1._clearCache()
        uplace4._clearCache()
        pb3 = PostBase('{"notes": [{"content": "child"}]}')
        pp3 = PostPiece.create_smart(uplace4, pb3)
        self.assertNotEqual(uplace4.userPost, uplace1.userPost)
        self.assertNotEqual(uplace4.userPost.json, uplace1.userPost.json)