def test_update_entry_field_that_was_undefined_in_the_webapp(self):
entry = None
with vcr.use_cassette('fixtures/entry/undefined_fields.yaml'):
entry = CLIENT.entries(PLAYGROUND_SPACE).find('33uj74Wln2Oc02CAyEY8CK')
self.assertEqual(entry.fields(), {})
with vcr.use_cassette('fixtures/entry/undefined_fields_write.yaml'):
entry.name = 'foo'
self.assertEqual(entry.fields()['name'], 'foo')
entry.save()
updated_entry = CLIENT.entries(PLAYGROUND_SPACE).find('33uj74Wln2Oc02CAyEY8CK')
self.assertEqual(updated_entry.fields(), {'name': 'foo'})
python类use_cassette()的实例源码
def test_update_entry_field_with_field_that_was_not_present(self):
entry = None
with vcr.use_cassette('fixtures/entry/added_fields_1.yaml'):
entry = CLIENT.entries(PLAYGROUND_SPACE).find('3fTNzlQsDmge6YQEikEuME')
self.assertEqual(entry.fields(), {'name': 'A Name', 'other': 'Other Stuff'})
with vcr.use_cassette('fixtures/entry/added_fields_2.yaml'):
entry.different = 'A Different Field'
self.assertEqual(entry.different, 'A Different Field')
self.assertEqual(entry.fields(), {'name': 'A Name', 'other': 'Other Stuff', 'different': 'A Different Field'})
self.assertEqual(entry.to_json()['fields']['different']['en-US'], 'A Different Field')
entry.save()
with vcr.use_cassette('fixtures/entry/added_fields_3.yaml'):
entry = CLIENT.entries(PLAYGROUND_SPACE).find('3fTNzlQsDmge6YQEikEuME')
self.assertEqual(entry.different, 'A Different Field')
test_weight_watchers.py 文件源码
项目:weight-watchers-sync
作者: Bachmann1234
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def test_get_calories_ww_defined_food(session):
with vcr.use_cassette("{}/{}.yaml".format(CASSETTES_HOME, 'egg_log.yaml')):
# This object is actually quite more complicated. But I don't care
food_log = {'portionId': '563c6669305d6e1834ab948d', 'sourceId': 58783, '_displayName': 'Egg(s)',
'sourcePortionName': 'serving(s)', 'points': 4, 'isCore': True, 'name': 'Egg(s)',
'entryId': 'ee1e26a0-4e37-11e6-8aa7-21442c64eff3', 'smartPointsPrecise': 2.0201, 'timeOfDay': 'morning',
'sourcePortionId': 9, 'versionId': '563c6669305d6e1834ab9485', 'smartPoints': 4, 'portionTypeId': 800,
'isActive': True, 'portionName': 'item(s)', 'portionSize': 2, 'isPowerFood': True, 'trackedDate': '2016-07-20',
'sourceType': WW_FOOD, '_servingDesc': '2 item(s)', '_id': '561dcbbae33175473413d475',
'pointsPrecise': 1.8347}
food_detail = get_food_detail(session, food_log)
result = get_nutrition(food_detail, food_log)
assert result == {
'calories': 144.0,
'sodium': 142.0,
'saturatedFat': 3.12,
'carbs': 0.72,
'sugar': 0.36,
'fat': 9.5,
'protein': 12.56
}
test_weight_watchers.py 文件源码
项目:weight-watchers-sync
作者: Bachmann1234
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def test_get_calories_ww_recipe(session):
with vcr.use_cassette("{}/{}.yaml".format(CASSETTES_HOME, 'steak_recipe.yaml')):
# This object is actually quite more complicated. But I don't care
food_log = {'smartPoints': 4, '_servingDesc': '1 serving(s)',
'_displayName': 'Coffee-Chili Rubbed Flank Steak with Peppers and Onions', 'trackedDate': '2016-07-20',
'pointsPrecise': 4.8926, 'portionSize': 1, 'isActive': True, 'entryId': '6fc42740-4e38-11e6-8237-3d072975d999',
'points': 5, 'sourceId': 523991, 'smartPointsPrecise': 4, 'portionName': 'serving(s)',
'name': 'Coffee-Chili Rubbed Flank Steak with Peppers and Onions', 'portionTypeId': None,
'versionId': '57516df7f9984a6a3682ac0d', '_id': '57516df7f9984a6a3682ac0c', 'timeOfDay': 'morning',
'sourcePortionName': 'serving(s)', 'sourcePortionId': None, 'sourceType': WW_RECIPE, 'portionId': None}
result = get_nutrition(get_food_detail(session, food_log), food_log)
assert result == {
'sodium': 1089.58948,
'protein': 26.27602775,
'fiber': 2.48177325,
'fat': 7.102034249999999,
'sugar': 3.51908025,
'saturatedFat': 2.4551232499999998,
'carbs': 7.944517,
'calories': 201.15632675
}
def test_send_schedule(self):
talks = self.generate_mockup_talks()
talk_like_numbers = {talk.id: 0 for talk in talks}
liked_talk_ids = []
with vcr.use_cassette('vcr_cassettes/send_schedule.yaml'):
response = messaging.send_schedule(
self.access_token,
self.user_id,
talks,
talk_like_numbers,
liked_talk_ids
)
self.assertTrue('recipient_id' in response)
self.assertTrue('message_id' in response)
self.assertEqual(response['recipient_id'], self.user_id)
def test_send_talk_info(self):
talk = self.create_mockup_talk_with_speaker()
with vcr.use_cassette('vcr_cassettes/send_more_talk_info.yaml'):
response = messaging.send_talk_info(self.access_token, self.user_id, talk)
self.assertTrue('recipient_id' in response)
self.assertTrue('message_id' in response)
self.assertEqual(response['recipient_id'], self.user_id)
def test_send_rate_menu(self):
talk = self.create_mockup_talk()
talk_liked = False
with vcr.use_cassette('vcr_cassettes/send_rate_menu.yaml'):
response = messaging.send_rate_menu(self.access_token, self.user_id, talk, talk_liked)
self.assertTrue('recipient_id' in response)
self.assertTrue('message_id' in response)
self.assertEqual(response['recipient_id'], self.user_id)
messenger_profile_test.py 文件源码
项目:meetup-facebook-bot
作者: Stark-Mountain
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def test_get_started_button_set_get_delete(self):
payload = 'test payload'
with vcr.use_cassette('vcr_cassettes/set_get_started_button.yaml'):
response = messenger_profile.set_get_started_button(self.access_token, payload)
self.assertEqual(response, {'result': 'success'})
with vcr.use_cassette('vcr_cassettes/get_get_started_button.yaml'):
response = messenger_profile.get_field(self.access_token, 'get_started')
self.assertEqual(response['data'][0]['get_started']['payload'], payload)
with vcr.use_cassette('vcr_cassettes/delete_get_started_button.yaml'):
response = messenger_profile.delete_field(self.access_token, 'get_started')
self.assertEqual(response, {'result': 'success'})
messenger_profile_test.py 文件源码
项目:meetup-facebook-bot
作者: Stark-Mountain
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def test_greeting_set_get_delete(self):
greeting_text = 'test greeting'
with vcr.use_cassette('vcr_cassettes/set_greeting.yaml'):
response = messenger_profile.set_greeting(self.access_token, greeting_text)
self.assertEqual(response, {'result': 'success'})
with vcr.use_cassette('vcr_cassettes/get_greeting.yaml'):
response = messenger_profile.get_field(self.access_token, 'greeting')
self.assertEqual(response['data'][0]['greeting'][0]['text'], greeting_text)
with vcr.use_cassette('vcr_cassettes/delete_greeting.yaml'):
response = messenger_profile.delete_field(self.access_token, 'greeting')
self.assertEqual(response, {'result': 'success'})
def test_commit():
with vcr.use_cassette('test/fixtures/commit.yaml'):
ret = on_message({"text": u"!commit"}, None)
assert 'stuff' in ret
def test_basic():
with vcr.use_cassette('test/fixtures/wiki_basic.yaml'):
ret = on_message({"text": u"!wiki dog"}, None)
assert "member of the canidae family" in ret
assert "http://en.wikipedia.org/wiki/Dog" in ret
def test_unicode():
with vcr.use_cassette('test/fixtures/wiki_unicode.yaml'):
ret = on_message({"text": u"!wiki ?????"}, None)
# not blowing up == success
def test_gif():
with vcr.use_cassette('test/fixtures/gif_bananas.yaml'):
ret = on_message({"text": u"!gif bananas"}, None)
assert ret in bananas_gifs, "{0} not in {1}".format(ret, bananas_gifs)
def test_unicode():
with vcr.use_cassette('test/fixtures/gif_unicode.yaml'):
ret = on_message({"text": u"!gif Mötörhead"}, None)
# not blowing up == success, for our purposes
def test_unicode():
with vcr.use_cassette('test/fixtures/weather_unicode.yaml'):
ret = on_message({"text": u"!weather Provençal"}, None)
# not blowing up == success
def test_apple():
with vcr.use_cassette('test/fixtures/stock_apple.yaml'):
ret = on_message({"text": u"$aapl"}, None)
assert ':chart_with_upwards_trend:' in ret
assert 'Apple Inc.' in ret
assert '130.41' in ret
assert '+1.62' in ret
def test_nonexistent():
with vcr.use_cassette('test/fixtures/stock_none'):
ret = on_message({"text": u"bana"}, None)
eq_(ret, None)
def test_unicode():
with vcr.use_cassette('test/fixtures/stock_unicode.yaml'):
ret = on_message({"text": u"$äapl"}, None)
eq_(ret, None)
def test_multiple():
with vcr.use_cassette('test/fixtures/stock_multiple.yaml'):
ret = on_message({"text": u"$goog $aapl"}, None)
assert 'Google Inc' in ret
def test_calc():
with vcr.use_cassette('test/fixtures/calc_basic.yaml'):
ret = on_message({"text": u"!calc 2469*5"}, None)
assert '12,345' in ret
def test_unicode():
with vcr.use_cassette('test/fixtures/calc_unicode.yaml'):
# ??? is the Thai Bhat (spelled in Thai, obvs)
ret = on_message({"text": u"!calc 10 dollars in ???"}, None)
# no exception == success
def test_basic():
with vcr.use_cassette('test/fixtures/mlb_basic.yaml'):
ret = on_message({"text": u"!mlb Red Sox"}, None)
assert "Boston Red Sox" in ret
def test_image():
with vcr.use_cassette('test/fixtures/image_bananas.yaml'):
ret = on_message({"text": u"!image bananas"}, None)
assert ret in bananas_images, "{0} not in {1}".format(ret, bananas_images)
def test_unicode():
with vcr.use_cassette('test/fixtures/image_unicode.yaml'):
ret = on_message({"text": u"!image Mötörhead"}, None)
# not blowing up == success, for our purposes
def test_basic():
with vcr.use_cassette('test/fixtures/stockphoto_basic.yaml'):
ret = on_message({"text": u"!stock woman eating salad"}, None)
assert ret in women_eating_salad
def test_unicode():
with vcr.use_cassette('test/fixtures/stockphoto_unicode.yaml'):
ret = on_message({"text": u"!stock übermensch"}, None)
# not blowing up == success
def test_basic():
with vcr.use_cassette('test/fixtures/youtube_basic.yaml'):
ret = on_message({"text": u"!youtube live long and prosper"}, None)
assert ret == "https://www.youtube.com/watch?v=DyiWkWcR86I"
def test_unicode():
with vcr.use_cassette('test/fixtures/youtube_unicode.yaml'):
ret = on_message({"text": u"!youtube ???????"}, None)
# not blowing up == success
def test_update_role(self):
role = CLIENT.roles(PLAYGROUND_SPACE).find('1a6FSwjdLnKifppXvfELau')
with vcr.use_cassette('fixtures/role/update.yaml'):
role.name = 'Not Klingon'
role.save()
self.assertEqual(role.name, 'Not Klingon')
def test_delete_role(self):
role = CLIENT.roles(PLAYGROUND_SPACE).find('1a6FSwjdLnKifppXvfELau')
with vcr.use_cassette('fixtures/role/delete.yaml'):
role.delete()
with vcr.use_cassette('fixtures/role/not_found.yaml'):
with self.assertRaises(NotFoundError):
CLIENT.roles(PLAYGROUND_SPACE).find('1a6FSwjdLnKifppXvfELau')