Skip to content

Commit

Permalink
improved test to check all children of deleted project
Browse files Browse the repository at this point in the history
better output of org structure
added more fake data
  • Loading branch information
tmaybe committed Jan 14, 2015
1 parent be5b5fe commit f53d530
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 8 deletions.
131 changes: 131 additions & 0 deletions meetup_events_another.json
@@ -0,0 +1,131 @@
{
"results": [
{
"rsvp_limit": 50,
"status": "past",
"visibility": "public",
"maybe_rsvp_count": 0,
"venue": {
"id": 1394669,
"zip": "28205",
"lon": -71.4543,
"repinned": false,
"name": "Brown TRI LAB",
"state": "RI",
"address_1": "10 Davol Sq.",
"lat": 41.4887,
"city": "Providence",
"country": "us"
},
"id": "156302132",
"utc_offset": -18000000,
"time": 1389916800000,
"waitlist_count": 0,
"updated": 1390198416000,
"yes_rsvp_count": 48,
"created": 1387484285000,
"event_url": "http://www.meetup.com/Rhode-Island-Code-for-America-Brigade/events/206703972/",
"description": "<p>Open to all! Join us to learn, create, hack, and do, all for the civic good!</p>",
"how_to_find_us": "",
"name": "September 16th Hack Night!",
"headcount": 0,
"rating": {
"count": 7,
"average": 4.710000038146973
},
"group": {
"id": 10916672,
"group_lat": 35.220001220703125,
"name": "Code For Rhode Island",
"group_lon": -80.79000091552734,
"join_mode": "approval",
"urlname": "Code-For-Rhode-Island",
"who": "Citizens"
}
},
{
"status": "past",
"visibility": "public",
"maybe_rsvp_count": 0,
"venue": {
"zip": "28202",
"phone": "704-930-7444",
"lon": -80.844313,
"state": "RI",
"address_1": "201 S. Tryon",
"address_2": "15th Floor",
"city": "Providence",
"country": "us",
"id": 1543691,
"repinned": false,
"name": "Skookum Digital Works",
"lat": 35.226253
},
"id": "162140372",
"utc_offset": -18000000,
"time": 1392939000000,
"waitlist_count": 0,
"updated": 1392989659000,
"yes_rsvp_count": 56,
"created": 1390494047000,
"event_url": "http://www.meetup.com/Rhode-Island-Code-for-America-Brigade/events/209442472/",
"description": "<p>Save the date for our public launch event. You'll have a chance to meet the fellows, and check up on all the progress we've mLet's hack. More specifically, let's get together and chat about current affairs and projects etc.</p>",
"how_to_find_us": "Final details pending",
"name": "November 4th Brigade Meetup",
"headcount": 0,
"rating": {
"count": 2,
"average": 5
},
"group": {
"id": 10916672,
"group_lat": 35.220001220703125,
"name": "Code For Rhode Island",
"group_lon": -80.79000091552734,
"join_mode": "approval",
"urlname": "Code-For-Rhode-Island",
"who": "Citizens"
}
},
{
"status": "past",
"visibility": "public",
"maybe_rsvp_count": 0,
"venue": {
"id": 17502142,
"lon": -80.846367,
"repinned": false,
"name": "Packard Place",
"state": "RI",
"address_1": "222 S. Church Street",
"lat": 35.227127,
"city": "Providence",
"country": "us"
},
"id": "167558762",
"utc_offset": -18000000,
"duration": 10800000,
"time": 1394058600000,
"waitlist_count": 0,
"updated": 1394125991000,
"yes_rsvp_count": 38,
"created": 1393013397000,
"event_url": "http://www.meetup.com/cleveland-civic-hacking/events/197969772/",
"description": "<p>Come join us for the OSM Edit-a-thon as we join in the celebration of OpenStreetMap's 10th Birthday! Help put Cleveland on the map in OpenStreetMap, the free global map that everyone can edit and use with minimal restrictions, like wikipedia.</p>",
"name": "Summer OpenStreetMap Editathon",
"headcount": 0,
"rating": {
"count": 3,
"average": 4.670000076293945
},
"group": {
"id": 10916672,
"group_lat": 35.220001220703125,
"name": "Code For Rhode Island",
"group_lon": -80.79000091552734,
"join_mode": "approval",
"urlname": "Code-For-Rhode-Island",
"who": "Citizens"
}
}]
}
54 changes: 46 additions & 8 deletions run_update_test.py
Expand Up @@ -53,7 +53,7 @@ def setup_mock_rss_response(self):
def get_raw_organization_list(self, count=3):
if type(count) is not int:
count = 3
lines = [u'''name,website,events_url,rss,projects_list_url'''.encode('utf8'), u'''Cöde for Ameriça,http://codeforamerica.org,http://www.meetup.com/events/Code-For-Charlotte/,http://www.codeforamerica.org/blog/feed/,http://example.com/cfa-projects.csv'''.encode('utf8'), u'''Code for America (2),,,,https://github.com/codeforamerica'''.encode('utf8'), u'''Code for America (3),,,http://www.codeforamerica.org/blog/another/feed/,https://www.github.com/orgs/codeforamerica'''.encode('utf8')]
lines = [u'''name,website,events_url,rss,projects_list_url'''.encode('utf8'), u'''Cöde for Ameriça,http://codeforamerica.org,http://www.meetup.com/events/Code-For-Charlotte/,http://www.codeforamerica.org/blog/feed/,http://example.com/cfa-projects.csv'''.encode('utf8'), u'''Code for America (2),,,,https://github.com/codeforamerica'''.encode('utf8'), u'''Code for America (3),,http://www.meetup.com/events/Code-For-Rhode-Island/,http://www.codeforamerica.org/blog/another/feed/,https://www.github.com/orgs/codeforamerica'''.encode('utf8')]
return '\n'.join(lines[0:count + 1])

def response_content(self, url, request):
Expand Down Expand Up @@ -92,6 +92,12 @@ def response_content(self, url, request):
events_file.close()
return response(200, events_content)

elif match(r'https:\/\/api\.meetup\.com\/2\/events\?status=past,upcoming&format=json&group_urlname=Code-For-Rhode-Island&key=', url.geturl()):
events_file=open('meetup_events_another.json')
events_content = events_file.read()
events_file.close()
return response(200, events_content)

elif url.geturl() == 'http://www.codeforamerica.org/blog/feed/' or match(r'http:\/\/.+\.rss', url.geturl()):
stories_file=open('blog.xml')
stories_content = stories_file.read()
Expand Down Expand Up @@ -656,38 +662,53 @@ def test_orphaned_project_deleted(self):
events = self.db.session.query(Event).filter(Event.organization_name == org_check['name']).all()
print "org %s has %s events!" % (org_check['name'], len(events))
for event in events:
print "-> %s" % event.name
print "-> %s (id:%s)" % (event.name, event.id)

# check stories
stories = self.db.session.query(Story).filter(Story.organization_name == org_check['name']).all()
print "org %s has %s stories!" % (org_check['name'], len(stories))
for story in stories:
print "-> %s" % story.title
print "-> %s (id:%s)" % (story.title, story.id)

# check projects
projects = self.db.session.query(Project).filter(Project.organization_name == org_check['name']).all()
print "org %s has %s projects!" % (org_check['name'], len(projects))
for project in projects:
print "-> %s" % project.name
print "-> %s (id:%s)" % (project.name, project.id)

# check issues
issues = self.db.session.query(Issue).filter(Issue.project_id == project.id).all()
print "- project %s has %s issues!" % (project.name, len(issues))
for issue in issues:
print "--> %s" % issue.title
print "--> %s (id:%s)" % (issue.title, issue.id)

# check labels
labels = self.db.session.query(Label).filter(Label.issue_id == issue.id).all()
print "-- issue %s has %s labels!" % (issue.title, len(labels))
for label in labels:
print "---> %s" % label.name
print "---> %s (id:%s)" % (label.name, label.id)


# reset with just two projects
self.project_count = 2
partial_orgs_list = []
with HTTMock(self.response_content):
partial_orgs_list = run_update.get_organizations(test_sources)

orphaned_org_names = list(set([item['name'] for item in full_orgs_list]) - set([item['name'] for item in partial_orgs_list]))
orphaned_issue_ids = []
orphaned_label_ids = []
for org_name in orphaned_org_names:
projects = self.db.session.query(Project).filter(Project.organization_name == org_check['name']).all()
for project in projects:
issues = self.db.session.query(Issue).filter(Issue.project_id == project.id).all()
for issue in issues:
orphaned_issue_ids.append(issue.id)
labels = self.db.session.query(Label).filter(Label.issue_id == issue.id).all()
for label in labels:
orphaned_label_ids.append(label.id)

with HTTMock(self.response_content):
run_update.main(org_sources=test_sources)

# confirm that the two projects are in the database
Expand All @@ -696,14 +717,31 @@ def test_orphaned_project_deleted(self):
organization = self.db.session.query(Organization).filter(filter).first()
self.assertIsNotNone(organization)
self.assertEqual(organization.name, org_check['name'])
#self.assertTrue(organization.keep)

# confirm that the orphaned project is no longer in the database
orphaned_org_names = list(set([item['name'] for item in full_orgs_list]) - set([item['name'] for item in partial_orgs_list]))
# confirm that the orphaned organization and its children are no longer in the database
for org_name_check in orphaned_org_names:
filter = Organization.name == org_name_check
organization = self.db.session.query(Organization).filter(filter).first()
self.assertIsNone(organization)

events = self.db.session.query(Event).filter(Event.organization_name == org_name_check).all()
self.assertEqual(len(events), 0)

stories = self.db.session.query(Story).filter(Story.organization_name == org_name_check).all()
self.assertEqual(len(stories), 0)

projects = self.db.session.query(Project).filter(Project.organization_name == org_name_check).all()
self.assertEqual(len(projects), 0)

for issue_id in orphaned_issue_ids:
issue = self.db.session.query(Issue).filter(Issue.id == issue_id).first()
self.assertIsNone(issue)

for label_id in orphaned_label_ids:
label = self.db.session.query(Label).filter(Label.id == label_id).first()
self.assertIsNone(label)

# reset to three projects
self.project_count = 3

Expand Down

0 comments on commit f53d530

Please sign in to comment.