def test_save_and_retreive(self): img = Image() test_data = 'http://blogthumb2.naver.net/20160302_285/mardukas_1456922688406bYGAH_JPEG/DSC07301.jpg' img.content = test_data img.save() saved = Image.objects.first() self.assertEqual(saved, img) saved2 = Image.get_from_json('{"uuid": "%s", "content": null}' % img.uuid) self.assertEqual(saved2, img) saved3 = Image.get_from_json('{"uuid": "%s", "content": null, "note": {"uuid": null, "content": null}}' % img.uuid) self.assertEqual(saved3, img) saved4 = Image.get_from_json('{"uuid": null, "content": "%s"}' % img.content) self.assertEqual(saved4, img)
def test_json(self): test_data = 'http://blogthumb2.naver.net/20160302_285/mardukas_1456922688406bYGAH_JPEG/DSC07301.jpg' img, is_created = Image.get_or_create_smart(test_data) img.summarize() self.assertIn('uuid', img.json) self.assertIn('content', img.json) self.assertNotIn('note', img.json) self.assertNotIn('timestamp', img.json) self.assertIn('summary', img.json) img.timestamp = get_timestamp() inote = ImageNote(content='img note') inote.save() img.note = inote self.assertIn('uuid', img.json) self.assertIn('content', img.json) self.assertIn('note', img.json) #self.assertIn('timestamp', img.json) self.assertIn('summary', img.json) self.assertIn('uuid', img.json['note']) self.assertIn('content', img.json['note']) self.assertNotIn('timestamp', img.json['note']) inote.timestamp = get_timestamp() self.assertIn('uuid', img.json['note']) self.assertIn('content', img.json['note']) self.assertIn('timestamp', img.json['note']) saved = Image.get_from_json(img.json) self.assertEqual(saved, img) self.assertEqual(saved.note, img.note)
def test_create4(self): with open('image/samples/gps_test.jpg') as f: response = self.client.post('/rfs/', dict(file=f)) img_url = json_loads(response.content)['url'] response = self.client.post('/imgs/', dict(content=img_url, lon=127.0, lat=37.0, local_datetime='2015:04:22 11:54:19', test=True)) self.assertEqual(response.status_code, status.HTTP_201_CREATED) uuid = json_loads(response.content)['uuid'] img = Image.get_from_json('{"uuid": "%s"}' % uuid) self.assertEqual(img.lonLat, GEOSGeometry('POINT(%f %f)' % (127.0, 37.0), srid=4326)) self.assertEqual(img.timestamp, 1429671259000)
def test_create3(self): with open('image/samples/gps_test.jpg') as f: response = self.client.post('/rfs/', dict(file=f)) img_url = json_loads(response.content)['url'] response = self.client.post('/imgs/', dict(content=img_url, test=True)) self.assertEqual(response.status_code, status.HTTP_201_CREATED) uuid = json_loads(response.content)['uuid'] img = Image.get_from_json('{"uuid": "%s"}' % uuid) self.assertEqual(img.lonLat, GEOSGeometry('POINT(%f %f)' % (127.103744, 37.399731), srid=4326)) self.assertEqual(img.timestamp, 1459149534000)
def load_additional_info(self): # 이미지가 없는 경우, URL 에서 이미지 가져오기 if not self.images and self.urls and self.urls[0]: url = self.urls[0] try: url.access() pq = PyQuery(url.content_accessed) img_url = pq('meta[property="og:image"]').attr('content') if img_url: img = Image.get_from_json('{"content": "%s"}' % img_url) if img: img.summarize() self.images.append(img) except Timeout: pass
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']