Exemplo n.º 1
0
 def test_put_with_trailing_slash(self):
     # given
     entry = Entry('1234', name='Charlie', phone='5678')
     # when
     response = self.app.put_json(url='/phonebook/1234/',
                                  params=objToDict(entry))
     # then
     assert_that(response.status_int, is_(200))
     assert_that(response.json, json_equal_to_entry(entry))
     assert_that(
         self.app.get(url='/phonebook/1234').json,
         json_equal_to_entry(entry))
Exemplo n.º 2
0
 def test_put_new_entry_id_only_in_url(self):
     # given
     entry = Entry(name='Charlie', phone='5678')
     # when
     response = self.app.put_json(url='/phonebook/1234',
                                  params=objToDict(entry))
     # then
     expected = Entry('1234', name='Charlie', phone='5678')
     assert_that(response.status_int, is_(200))
     assert_that(response.json, json_equal_to_entry(expected))
     assert_that(
         self.app.get(url='/phonebook/1234').json,
         json_equal_to_entry(expected))
Exemplo n.º 3
0
 def test_post_entry_without_id_should_generate_random_id(self):
     # when
     response = self.app.post_json('/phonebook/',
                                   params={
                                       'name': 'Alice',
                                       'phone': '1234'
                                   })
     # then
     assert_that(response.status_int, is_(200))
     entry_id = response.json['id']
     expected = Entry(entry_id, name='Alice', phone='1234')
     assert_that(response.json, json_equal_to_entry(expected))
     get_result = self.app.get('/phonebook/' + entry_id).json
     assert_that(get_result, json_equal_to_entry(expected))
Exemplo n.º 4
0
 def test_put_should_modify_whole_entry(self):
     # given
     entry = Entry('1234', name='Charlie', phone='5678')
     self.app.post_json(url='/phonebook/', params=objToDict(entry))
     # when
     entry2 = Entry('1234', name='Bob', mobile='9876')
     response = self.app.put_json(url='/phonebook/1234',
                                  params=objToDict(entry2))
     # then
     assert_that(response.status_int, is_(200))
     assert_that(response.json, json_equal_to_entry(entry2))
     assert_that(
         self.app.get(url='/phonebook/1234').json,
         json_equal_to_entry(entry2))
Exemplo n.º 5
0
 def test_patch_with_trailing_slash(self):
     # given
     entry = Entry('1234', name='Charlie', phone='5678')
     self.app.post_json(url='/phonebook/', params=objToDict(entry))
     # when
     response = self.app.patch_json(url='/phonebook/1234/',
                                    params={
                                        'name': 'David',
                                        'phone': None,
                                        'mobile': 5555
                                    })
     # then
     expected = Entry('1234', name='David', mobile=5555)
     assert_that(response.status_int, is_(200))
     assert_that(response.json, json_equal_to_entry(expected))
     assert_that(
         self.app.get(url='/phonebook/1234').json,
         json_equal_to_entry(expected))
Exemplo n.º 6
0
 def test_get_entry_by_id(self):
     # given
     entry = Entry('1234', name='Charlie')
     self.app.post_json(url='/phonebook/', params=objToDict(entry))
     # when
     response = self.app.get('/phonebook/1234')
     # then
     assert_that(response.status_int, is_(200))
     assert_that(response.json, json_equal_to_entry(entry))