Example #1
0
 def test_invalid(self):
     with pytest.raises(TypeError):
         jsonobject.parse_text('null')
     with pytest.raises(TypeError):
         jsonobject.parse_text('"foo"')
     with pytest.raises(TypeError):
         jsonobject.parse_text('123')
     with pytest.raises(TypeError):
         jsonobject.parse_text('["foo", "bar"]')
     with pytest.raises(ValueError):
         # Looks like a map, but corrupted.
         jsonobject.parse_text('{"foo": "bar}')
Example #2
0
 def test_invalid(self):
     with pytest.raises(TypeError):
         jsonobject.parse_text('null')
     with pytest.raises(TypeError):
         jsonobject.parse_text('"foo"')
     with pytest.raises(TypeError):
         jsonobject.parse_text('123')
     with pytest.raises(TypeError):
         jsonobject.parse_text('["foo", "bar"]')
     with pytest.raises(ValueError):
         # Looks like a map, but corrupted.
         jsonobject.parse_text('{"foo": "bar}')
Example #3
0
 def test_readonly_not_omittable(self):
     s = jsonobject.parse_text('{"foo": "FOO", "bar": null}',
                               readonly=True, omittable=False)
     assert s.foo == u'FOO'
     assert s.bar is None
     # No property is omittable.
     assert s.json(sort_keys=True) == '{"bar": null, "foo": "FOO"}'
Example #4
0
 def pytest_funcarg__ship_data(self):
     return jsonobject.parse_text("""{
         "api_id": 1,
         "api_ship_id": 1001,
         "api_lv": 2,
         "api_nowhp": 3,
         "api_maxhp": 4,
         "api_cond": 5,
         "api_fuel": 6,
         "api_bull": 7,
         "api_soukou": [8, 9],
         "api_kaihi": [10, 11],
         "api_karyoku": [12, 13],
         "api_raisou": [14, 15],
         "api_taiku": [16, 17],
         "api_taisen": [18, 19],
         "api_sakuteki": [20, 21],
         "api_lucky": [22, 23],
         "api_kyouka": [1, 2, 3, 4, 0],
         "api_onslot": [5, 6, 0, 0, 0],
         "api_slot": [-1, -1, -1, -1, -1],
         "api_sortno": 1001,
         "api_backs": 1,
         "api_exp": [24, 25, 26],
         "api_locked": 1
     }""")
Example #5
0
 def test_readonly_not_omittable(self):
     s = jsonobject.parse_text('{"foo": "FOO", "bar": null}',
                               readonly=True,
                               omittable=False)
     assert s.foo == u'FOO'
     assert s.bar is None
     # No property is omittable.
     assert s.json(sort_keys=True) == '{"bar": null, "foo": "FOO"}'
Example #6
0
 def test_readwrite_omittable(self):
     s = jsonobject.parse_text('{"foo": "FOO", "bar": "BAR"}',
                               readonly=False, omittable=True)
     assert s.foo == u'FOO'
     assert s.bar == u'BAR'
     assert s.json(sort_keys=True) == '{"bar": "BAR", "foo": "FOO"}'
     s.foo = u'FOOFOO'
     s.bar = None
     # Note that every property is omittable.
     assert s.json(sort_keys=True) == '{"foo": "FOOFOO"}'
Example #7
0
 def test_update_fleet_clearance(self, fleet_list):
     # Remove all the ships except the flag ship.
     request = jsonobject.parse_text("""{
         "api_id": "1",
         "api_ship_idx": "0",
         "api_ship_id": "-2"
     }""")
     fleet_list.update(
         '/api_req_hensei/change', request, None, {}, False)
     assert fleet_list.fleets[0].ship_ids == [1]
Example #8
0
 def test_update_ship_removal(self, fleet_list):
     # Remove the ship at the index 1 (the second ship).
     request = jsonobject.parse_text("""{
         "api_id": "1",
         "api_ship_idx": "1",
         "api_ship_id": "-1"
     }""")
     fleet_list.update(
         '/api_req_hensei/change', request, None, {}, False)
     assert fleet_list.fleets[0].ship_ids == [1, 3]
Example #9
0
 def test_update_ship_deployment(self, fleet_list):
     # Add the ship 4 to the end of the ship list.
     request = jsonobject.parse_text("""{
         "api_id": "1",
         "api_ship_idx": "3",
         "api_ship_id": "4"
     }""")
     fleet_list.update(
         '/api_req_hensei/change', request, None, {}, False)
     assert fleet_list.fleets[0].ship_ids == [1, 2, 3, 4]
Example #10
0
 def test_update_ship_swapping(self, fleet_list):
     # Swap the ship at the index 1 with the ship 3.
     request = jsonobject.parse_text("""{
         "api_id": "1",
         "api_ship_idx": "1",
         "api_ship_id": "3"
     }""")
     fleet_list.update(
         '/api_req_hensei/change', request, None, {}, False)
     assert fleet_list.fleets[0].ship_ids == [1, 3, 2]
Example #11
0
 def test_readwrite_omittable(self):
     s = jsonobject.parse_text('{"foo": "FOO", "bar": "BAR"}',
                               readonly=False,
                               omittable=True)
     assert s.foo == u'FOO'
     assert s.bar == u'BAR'
     assert s.json(sort_keys=True) == '{"bar": "BAR", "foo": "FOO"}'
     s.foo = u'FOOFOO'
     s.bar = None
     # Note that every property is omittable.
     assert s.json(sort_keys=True) == '{"foo": "FOOFOO"}'
Example #12
0
 def test_update_repair_speedchange(self, repair_dock, ship_list):
     request = jsonobject.parse_text("""{
         "api_ndock_id": "1"
     }""")
     objects = {'ShipList': ship_list}
     repair_dock.update(
         '/api_req_nyukyo/speedchange', request, None, objects, False)
     assert repair_dock.slots[0].ship_id == 0
     assert repair_dock.slots[0].eta == 0L
     ship_100 = ship_list.ships['100']
     assert ship_100.hitpoint.current == ship_100.hitpoint.maximum
Example #13
0
 def test_update_repair_start(self, repair_dock, ship_list):
     request = jsonobject.parse_text("""{
         "api_ndock_id": "2",
         "api_ship_id": "101",
         "api_highspeed": "0"
     }""")
     objects = {'ShipList': ship_list}
     repair_dock.update(
         '/api_req_nyukyo/start', request, None, objects, False)
     assert repair_dock.slots[1].ship_id == 101
     assert ship_list.ships['101'].hitpoint.current == 56
Example #14
0
 def test_update_ship_swapping_between_fleets(self, fleet_list_2):
     # Swap the ship at the index 1 with the ship 5.
     # Note that the ship 5 is in the second fleet.
     request = jsonobject.parse_text("""{
         "api_id": "1",
         "api_ship_idx": "1",
         "api_ship_id": "5"
     }""")
     fleet_list_2.update(
         '/api_req_hensei/change', request, None, {}, False)
     assert fleet_list_2.fleets[0].ship_ids == [1, 5, 3]
     assert fleet_list_2.fleets[1].ship_ids == [4, 2, 6, 7]
Example #15
0
 def test_readonly_omittable(self):
     s = jsonobject.parse_text('{"foo": "FOO", "bar": null}',
                               readonly=True, omittable=True)
     assert s.foo == u'FOO'
     assert s.bar is None
     with pytest.raises(AttributeError):
         s.foo = u'FOOFOO'
     with pytest.raises(AttributeError):
         s.bar = u'BARBAR'
     # Every property is omittable, so bar should be omitted even though it
     # appeared in the input.
     assert s.json(sort_keys=True) == '{"foo": "FOO"}'
Example #16
0
 def test_readonly_omittable(self):
     s = jsonobject.parse_text('{"foo": "FOO", "bar": null}',
                               readonly=True,
                               omittable=True)
     assert s.foo == u'FOO'
     assert s.bar is None
     with pytest.raises(AttributeError):
         s.foo = u'FOOFOO'
     with pytest.raises(AttributeError):
         s.bar = u'BARBAR'
     # Every property is omittable, so bar should be omitted even though it
     # appeared in the input.
     assert s.json(sort_keys=True) == '{"foo": "FOO"}'
Example #17
0
 def test_update_remodeling(self, ship_list, ship_defs):
     assert '1' in ship_list.ships
     ship_ = ship_list.ships['1']
     assert ship_.name == u'Ship 1001'
     assert ship_.armor.baseline == 1
     assert ship_.armor.maximum == 2
     request = jsonobject.parse_text("""{
         "api_id": "1"
     }""")
     ship_list.update('/api_req_kaisou/remodeling', request, None,
                      {'ShipDefinitionList': ship_defs}, False)
     ship_ = ship_list.ships['1']
     assert ship_.name == u'Ship 1002'
     assert ship_.armor.baseline == 11
     assert ship_.armor.maximum == 12
     assert ship_.upgrade_to == 0
Example #18
0
 def test_update_repair_end_ndock(self, repair_dock, ship_list):
     response = jsonobject.parse_text("""{
         "api_data": [
             {
                 "api_id": 1,
                 "api_ship_id": 0,
                 "api_state": 0,
                 "api_complete_time": 0
             },
             {
                 "api_id": 2,
                 "api_ship_id": 0,
                 "api_state": 0,
                 "api_complete_time": 0
             }
         ]
     }""")
     objects = {'ShipList': ship_list}
     repair_dock.update(
         '/api_get_member/ndock', None, response, objects, False)
     assert repair_dock.slots[0].ship_id == 0
     ship_100 = ship_list.ships['100']
     assert ship_100.hitpoint.current == ship_100.hitpoint.maximum
Example #19
0
 def test_update(self):
     response = jsonobject.parse_text("""{
         "api_data": {
             "api_deck_port": [
                 {
                     "api_id": 1,
                     "api_name": "FleetName",
                     "api_ship": [
                         123,
                         456,
                         789,
                         -1,
                         -1,
                         -1
                     ],
                     "api_mission": [
                         1,
                         111,
                         0,
                         0
                     ]
                 }
             ],
             "api_combined_flag": 0
         }
     }""")
     fleet_list = fleet.FleetList()
     fleet_list.update('/api_port/port', None, response, {}, False)
     assert len(fleet_list.fleets) == 1
     fleet_ = fleet_list.fleets[0]
     assert fleet_.id == 1
     assert fleet_.name == u'FleetName'
     assert fleet_.ship_ids == [123, 456, 789]
     assert fleet_.mission_id == 111
     assert not fleet_.mission_complete
     assert (fleet_list.combined_fleet_type ==
             fleet.FleetList.COMBINED_FLEET_TYPE_SINGLE)
Example #20
0
 def test_list(self):
     # List should create a list of JSONSerializableObject.
     s = jsonobject.parse_text('{"foo": [{"bar": 1}, {"bar": 2}]}')
     assert len(s.foo) == 2
     assert s.foo[0].bar == 1
     assert s.foo[1].bar == 2
Example #21
0
 def test_nested_map(self):
     # Nested map should create a nested JSONSerializableObject.
     s = jsonobject.parse_text('{"foo": "FOO", "bar": {"baz": "BAZ"}}')
     assert s.foo == u'FOO'
     assert s.bar.baz == u'BAZ'
Example #22
0
 def test_nested_map(self):
     # Nested map should create a nested JSONSerializableObject.
     s = jsonobject.parse_text('{"foo": "FOO", "bar": {"baz": "BAZ"}}')
     assert s.foo == u'FOO'
     assert s.bar.baz == u'BAZ'
Example #23
0
 def test_list(self):
     # List should create a list of JSONSerializableObject.
     s = jsonobject.parse_text('{"foo": [{"bar": 1}, {"bar": 2}]}')
     assert len(s.foo) == 2
     assert s.foo[0].bar == 1
     assert s.foo[1].bar == 2