@@ -29,6 +29,56 @@ def mdo(client):
2929 yield mdo
3030
3131
32+ @pytest .fixture
33+ def conversational_content ():
34+ return {
35+ 'row_data' : {
36+ "messages" : [{
37+ "messageId" : "message-0" ,
38+ "timestampUsec" : 1530718491 ,
39+ "content" : "I love iphone! i just bought new iphone! 🥰 📲" ,
40+ "user" : {
41+ "userId" : "Bot 002" ,
42+ "name" : "Bot"
43+ },
44+ "align" : "left" ,
45+ "canLabel" : False
46+ }],
47+ "version" : 1 ,
48+ "type" : "application/vnd.labelbox.conversational"
49+ }
50+ }
51+
52+
53+ @pytest .fixture
54+ def tile_content ():
55+ return {
56+ "row_data" : {
57+ "tileLayerUrl" :
58+ "https://s3-us-west-1.amazonaws.com/lb-tiler-layers/mexico_city/{z}/{x}/{y}.png" ,
59+ "bounds" : [[19.405662413477728 , - 99.21052827588443 ],
60+ [19.400498983095076 , - 99.20534818927473 ]],
61+ "minZoom" :
62+ 12 ,
63+ "maxZoom" :
64+ 20 ,
65+ "epsg" :
66+ "EPSG4326" ,
67+ "alternativeLayers" : [{
68+ "tileLayerUrl" :
69+ "https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw" ,
70+ "name" :
71+ "Satellite"
72+ }, {
73+ "tileLayerUrl" :
74+ "https://api.mapbox.com/styles/v1/mapbox/navigation-guidance-night-v4/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw" ,
75+ "name" :
76+ "Guidance"
77+ }]
78+ }
79+ }
80+
81+
3282def make_metadata_fields ():
3383 embeddings = [0.0 ] * 128
3484 msg = "A message"
@@ -699,31 +749,14 @@ def test_data_row_rulk_creation_sync_with_same_global_keys(
699749 assert list (dataset .data_rows ())[0 ].global_key == global_key_1
700750
701751
702- def test_create_conversational_text (dataset ):
703- content = {
704- 'row_data' : {
705- "messages" : [{
706- "messageId" : "message-0" ,
707- "timestampUsec" : 1530718491 ,
708- "content" : "I love iphone! i just bought new iphone! 🥰 📲" ,
709- "user" : {
710- "userId" : "Bot 002" ,
711- "name" : "Bot"
712- },
713- "align" : "left" ,
714- "canLabel" : False
715- }],
716- "version" : 1 ,
717- "type" : "application/vnd.labelbox.conversational"
718- }
719- }
752+ def test_create_conversational_text (dataset , conversational_content ):
720753 examples = [
721754 {
722- ** content , 'media_type' : 'CONVERSATIONAL'
755+ ** conversational_content , 'media_type' : 'CONVERSATIONAL'
723756 },
724- content ,
757+ conversational_content ,
725758 {
726- "conversationalData" : content ['row_data' ]['messages' ]
759+ "conversationalData" : conversational_content ['row_data' ]['messages' ]
727760 } # Old way to check for backwards compatibility
728761 ]
729762 dataset .create_data_rows_sync (examples )
@@ -733,77 +766,55 @@ def test_create_conversational_text(dataset):
733766 assert requests .get (data_row .row_data ).json () == content ['row_data' ]
734767
735768
736- def test_invalid_media_type (dataset ):
737- content = {
738- 'row_data' : {
739- "messages" : [{
740- "messageId" : "message-0" ,
741- "timestampUsec" : 1530718491 ,
742- "content" : "I love iphone! i just bought new iphone! 🥰 📲" ,
743- "user" : {
744- "userId" : "Bot 002" ,
745- "name" : "Bot"
746- },
747- "align" : "left" ,
748- "canLabel" : False
749- }],
750- "version" : 1 ,
751- "type" : "application/vnd.labelbox.conversational"
752- }
753- }
754-
769+ def test_invalid_media_type (dataset , conversational_content ):
755770 for error_message , invalid_media_type in [[
756771 "Found invalid contents for media type: 'IMAGE'" , 'IMAGE'
757772 ], ["Found invalid media type: 'totallyinvalid'" , 'totallyinvalid' ]]:
758773 # TODO: What error kind should this be? It looks like for global key we are
759774 # using malformed query. But for invalid contents in FileUploads we use InvalidQueryError
760775 with pytest .raises (labelbox .exceptions .InvalidQueryError ):
761776 dataset .create_data_rows_sync ([{
762- ** content , 'media_type' : invalid_media_type
777+ ** conversational_content , 'media_type' : invalid_media_type
763778 }])
764779
765780 task = dataset .create_data_rows ([{
766- ** content , 'media_type' : invalid_media_type
781+ ** conversational_content , 'media_type' : invalid_media_type
767782 }])
768783 task .wait_till_done ()
769784 assert task .errors == {'message' : error_message }
770785
771786
772- def test_create_tiled_layer (dataset ):
773- content = {
774- "row_data" : {
775- "tileLayerUrl" :
776- "https://s3-us-west-1.amazonaws.com/lb-tiler-layers/mexico_city/{z}/{x}/{y}.png" ,
777- "bounds" : [[19.405662413477728 , - 99.21052827588443 ],
778- [19.400498983095076 , - 99.20534818927473 ]],
779- "minZoom" :
780- 12 ,
781- "maxZoom" :
782- 20 ,
783- "epsg" :
784- "EPSG4326" ,
785- "alternativeLayers" : [{
786- "tileLayerUrl" :
787- "https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw" ,
788- "name" :
789- "Satellite"
790- }, {
791- "tileLayerUrl" :
792- "https://api.mapbox.com/styles/v1/mapbox/navigation-guidance-night-v4/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw" ,
793- "name" :
794- "Guidance"
795- }]
796- }
797- }
787+ def test_create_tiled_layer (dataset , tile_content ):
798788 examples = [
799789 {
800- ** content , 'media_type' : 'TMS_SIMPLE'
790+ ** tile_content , 'media_type' : 'TMS_SIMPLE'
801791 },
802- content ,
803- content ['row_data' ] # Old way to check for backwards compatibility
792+ tile_content ,
793+ tile_content ['row_data' ] # Old way to check for backwards compatibility
804794 ]
805795 dataset .create_data_rows_sync (examples )
806796 data_rows = list (dataset .data_rows ())
807797 assert len (data_rows ) == len (examples )
808798 for data_row in data_rows :
809799 assert json .loads (data_row .row_data ) == content ['row_data' ]
800+
801+
802+ def test_create_data_row_with_attachments (dataset ):
803+ attachment_value = 'attachment value'
804+ dr = dataset .create_data_row (row_data = "123" ,
805+ attachments = [{
806+ 'type' : 'TEXT' ,
807+ 'value' : attachment_value
808+ }])
809+ attachments = list (dr .attachments ())
810+ assert len (attachments ) == 1
811+
812+
813+ def test_create_data_row_with_media_type (dataset , image_url ):
814+ with pytest .raises (labelbox .exceptions .InvalidQueryError ) as exc :
815+ dr = dataset .create_data_row (
816+ row_data = {'invalid_object' : 'invalid_value' }, media_type = "IMAGE" )
817+ assert "Found invalid contents for media type: \' IMAGE\' " in str (exc .value )
818+
819+ dataset .create_data_row (row_data = image_url , media_type = "IMAGE" )
820+
0 commit comments