Skip to content

Commit

Permalink
mock opengraph calls under test
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Nov 3, 2020
1 parent dba12ad commit f40fa37
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions foundation/organisation/tests/test_views.py
Expand Up @@ -713,23 +713,34 @@ def test_relatable_person_updates_entries_with_last_updated_flag(self, *args):
email='donatello@tmnt.org')
donatello.save()

payload = {"username": "donnie",
"text": "#reading https://www.goodreads.com/book/show/486625.Close_to_the_Machine"
}

self.app.post_json(reverse('relatable-person'),
headers={'Authorization': 'secretkey'},
status=200,
params=payload)

payload = {"username": "donnie",
"text": "#watching https://www.youtube.com/watch?v=IAISUDbjXj0"
}

self.app.post_json(reverse('relatable-person'),
headers={'Authorization': 'secretkey'},
status=200,
params=payload)
mock_values = [
("Close to the machine", "https://www.goodreads.com/book/show/486625.Close_to_the_Machine"),
("Video unavailable", "https://www.youtube.com/watch?v=IAISUDbjXj0")
]
with patch('foundation.organisation.views.extract_ograph_title', side_effect=mock_values):
payload = {
"username": "donnie",
"text": "#reading https://www.goodreads.com/book/show/486625.Close_to_the_Machine"
}

self.app.post_json(
reverse('relatable-person'),
headers={'Authorization': 'secretkey'},
status=200,
params=payload
)

payload = {
"username": "donnie",
"text": "#watching https://www.youtube.com/watch?v=IAISUDbjXj0"
}

self.app.post_json(
reverse('relatable-person'),
headers={'Authorization': 'secretkey'},
status=200,
params=payload
)
donnie = Person.objects.filter(username_on_slack='donnie').first()
self.assertEqual(donnie.nowdoing_set.count(), 2)
self.assertTrue(donnie.nowdoing_with_latest[0].is_newest_update)
Expand Down

0 comments on commit f40fa37

Please sign in to comment.