Beispiel #1
0
 def test_string_representation(self):
     place = Place()
     place.save()
     self.assertEqual(unicode(place), 'No named place object')
     placeName = PlaceName(content='능이향기')
     placeName.save()
     place.placeName = placeName
     place.save()
     self.assertEqual(unicode(place), '능이향기')
Beispiel #2
0
 def test_save_and_retreive(self):
     test_data = '방아깐'
     pname, is_created = PlaceName.get_or_create_smart(test_data)
     saved = PlaceName.objects.first()
     self.assertEqual(pname.uuid, '%s.pname' % b16encode(pname.id.bytes))
     self.assertEqual(saved, pname)
     self.assertEqual(saved.id, pname.id)
     saved2 = PlaceName.get_from_json('{"uuid": "%s", "content": null}' % pname.uuid)
     self.assertEqual(saved2, pname)
     saved3 = PlaceName.get_from_json('{"uuid": null, "content": "%s"}' % pname.content)
     self.assertEqual(saved3, pname)
Beispiel #3
0
 def test_placeName_column(self):
     place = Place()
     test_data = '능이향기'
     placeName = PlaceName(content=test_data)
     placeName.save()
     place.placeName = placeName
     place.save()
     saved = Place.objects.first()
     self.assertEqual(place.placeName, placeName)
     self.assertEqual(place.placeName.content, test_data)
     self.assertEqual(saved, place)
     self.assertEqual(saved.placeName, placeName)
     self.assertEqual(saved.placeName.content, test_data)
     self.assertEqual(placeName.places.first(), saved)
     self.assertEqual(
         Place.objects.filter(placeName=placeName).first(), saved)
Beispiel #4
0
 def test_content_property(self):
     test_data = '방아깐'
     pname, is_created = PlaceName.get_or_create_smart(test_data)
     saved = PlaceName.objects.first()
     self.assertEqual(pname.content, test_data)
     self.assertEqual(saved, pname)
     self.assertEqual(saved.id, pname.id)
     self.assertEqual(saved.content, pname.content)
Beispiel #5
0
    def __skip__test_access_methods(self):
        test_data = '방아깐'
        pname, is_created = PlaceName.get_or_create_smart(test_data)

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

        self.assertEqual(path.exists(), False)
        pname.access_force()
        self.assertEqual(path.exists(), True)
Beispiel #6
0
 def test_string_representation(self):
     test_data = '방아깐'
     pname, is_created = PlaceName.get_or_create_smart(test_data)
     self.assertEqual(unicode(pname), test_data)
Beispiel #7
0
    def setUp(self, json, timestamp=None, vd=None):

        # name 조회
        if is_valid_json_item('name', json):
            name = PlaceName.get_from_json(json['name'])
            if name:
                name.vd = vd
                self.names.append(name)

        # visit 조회
        if is_valid_json_item('visit', json):
            visit = Visit.get_from_json(json['visit'])
            if visit:
                visit.vd = vd
                self.visits.append(visit)

        # rating 조회
        if is_valid_json_item('rating', json):
            rating = Rating.get_from_json(json['rating'])
            if rating:
                rating.vd = vd
                self.ratings.append(rating)

        # lonLat 조회
        if is_valid_json_item('lonLat', json):
            point = Point.get_from_json(json['lonLat'])
            if point:
                point.vd = vd
                self.points.append(point)

        # phone 조회
        if is_valid_json_item('phone', json):
            phone = PhoneNumber.get_from_json(json['phone'])
            if phone:
                phone.vd = vd
                self.phone = phone

        # addr1 조회
        if is_valid_json_item('addr1', json):
            addr1 = Address.get_from_json(json['addr1'])
            if addr1:
                addr1.vd = vd
                self.addrs1.append(addr1)

        # addr2 조회
        if is_valid_json_item('addr2', json):
            addr2 = Address.get_from_json(json['addr2'])
            if addr2:
                addr2.vd = vd
                self.addrs2.append(addr2)

        # addr3 조회
        if is_valid_json_item('addr3', json):
            addr3 = Address.get_from_json(json['addr3'])
            if addr3:
                addr3.vd = vd
                self.addrs3.append(addr3)

        # lps 조회
        if is_valid_json_item('lps', json):
            for lp_json in json['lps']:
                if is_valid_json_item(None, json):
                    lp = LegacyPlace.get_from_json(lp_json)
                    if lp:
                        lp.vd = vd
                        self.lps.append(lp)

        # urls 조회
        if is_valid_json_item('urls', json):
            from url.models import Url
            for url_json in json['urls']:
                if is_valid_json_item(None, url_json):
                    url = Url.get_from_json(url_json)
                    if url:
                        url.vd = vd
                        self.urls.append(url)

        # notes 조회
        if is_valid_json_item('notes', json):
            for note_json in json['notes']:
                if is_valid_json_item(None, note_json):
                    note = PlaceNote.get_from_json(note_json)
                    if note:
                        note.timestamp = timestamp
                        note.vd = vd
                        self.notes.append(note)

        # images 조회
        if is_valid_json_item('images', json):
            for img_json in json['images']:
                if is_valid_json_item(None, img_json):
                    img = Image.get_from_json(img_json)
                    if img:
                        if 'note' in img_json and img_json['note']:
                            note = ImageNote.get_from_json(img_json['note'])
                            if note:
                                note.timestamp = timestamp
                                note.vd = vd
                                img.note = note
                        img.vd = vd
                        self.images.append(img)

        # place_id, uplace_uuid, iplace_uuid 조회
        if is_valid_json_item('place_id', json):
            self.place_id = json['place_id']
        if is_valid_json_item('uplace_uuid', json):
            self.uplace_uuid = json['uplace_uuid']
        if is_valid_json_item('iplace_uuid', json):
            self.iplace_uuid = json['iplace_uuid']
Beispiel #8
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)