diff --git a/htmlcov/index.html b/htmlcov/index.html index 126dc28..4cb60e8 100644 --- a/htmlcov/index.html +++ b/htmlcov/index.html @@ -143,7 +143,7 @@

Coverage report:

coverage.py v4.2, - created at 2016-12-10 22:39 + created at 2017-01-01 14:17

diff --git a/htmlcov/server_app_py.html b/htmlcov/server_app_py.html index 1b138f0..f56f8c1 100644 --- a/htmlcov/server_app_py.html +++ b/htmlcov/server_app_py.html @@ -1052,7 +1052,7 @@

« index     coverage.py v4.2, - created at 2016-12-10 22:08 + created at 2017-01-01 14:13

diff --git a/htmlcov/server_config_py.html b/htmlcov/server_config_py.html index ef57ab6..9b138ed 100644 --- a/htmlcov/server_config_py.html +++ b/htmlcov/server_config_py.html @@ -98,7 +98,7 @@

« index     coverage.py v4.2, - created at 2016-12-10 22:08 + created at 2017-01-01 14:13

diff --git a/htmlcov/server_test_app_py.html b/htmlcov/server_test_app_py.html index c83ad29..010a941 100644 --- a/htmlcov/server_test_app_py.html +++ b/htmlcov/server_test_app_py.html @@ -80,231 +80,231 @@

9

10

11

-

12

-

13

-

14

-

15

+

12

+

13

+

14

+

15

16

17

-

18

-

19

-

20

-

21

-

22

+

18

+

19

+

20

+

21

+

22

23

24

-

25

+

25

26

27

-

28

-

29

+

28

+

29

30

-

31

-

32

+

31

+

32

33

-

34

-

35

+

34

+

35

36

-

37

+

37

38

39

40

41

-

42

-

43

-

44

+

42

+

43

+

44

45

-

46

+

46

47

48

49

50

51

-

52

-

53

+

52

+

53

54

55

56

57

58

-

59

-

60

-

61

-

62

+

59

+

60

+

61

+

62

63

64

-

65

-

66

+

65

+

66

67

68

69

-

70

-

71

-

72

-

73

+

70

+

71

+

72

+

73

74

75

76

-

77

-

78

-

79

-

80

+

77

+

78

+

79

+

80

81

82

83

-

84

-

85

-

86

-

87

+

84

+

85

+

86

+

87

88

89

90

-

91

-

92

+

91

+

92

93

-

94

-

95

-

96

-

97

+

94

+

95

+

96

+

97

98

99

-

100

+

100

101

102

-

103

-

104

-

105

+

103

+

104

+

105

106

-

107

-

108

+

107

+

108

109

110

111

112

-

113

+

113

114

-

115

-

116

-

117

-

118

+

115

+

116

+

117

+

118

119

-

120

-

121

+

120

+

121

122

-

123

+

123

124

125

-

126

-

127

-

128

+

126

+

127

+

128

129

-

130

+

130

131

132

-

133

-

134

-

135

+

133

+

134

+

135

136

-

137

+

137

138

139

-

140

-

141

-

142

-

143

-

144

-

145

+

140

+

141

+

142

+

143

+

144

+

145

146

147

-

148

+

148

149

150

-

151

-

152

+

151

+

152

153

-

154

-

155

+

154

+

155

156

-

157

-

158

+

157

+

158

159

160

-

161

+

161

162

163

164

-

165

-

166

-

167

-

168

+

165

+

166

+

167

+

168

169

170

-

171

+

171

172

173

-

174

-

175

+

174

+

175

176

-

177

-

178

-

179

-

180

-

181

+

177

+

178

+

179

+

180

+

181

182

183

184

185

186

-

187

-

188

+

187

+

188

189

190

191

192

-

193

+

193

194

-

195

+

195

196

-

197

+

197

198

-

199

+

199

200

-

201

+

201

202

-

203

-

204

-

205

-

206

-

207

+

203

+

204

+

205

+

206

+

207

208

209

210

-

211

-

212

-

213

-

214

+

211

+

212

+

213

+

214

215

216

-

217

+

217

218

-

219

+

219

220

-

221

+

221

222

-

223

-

224

-

225

-

226

-

227

+

223

+

224

+

225

+

226

+

227

228

229

-

230

+

230

231

-

232

-

233

-

234

-

235

-

236

+

232

+

233

+

234

+

235

+

236

237

238

239

@@ -313,42 +313,42 @@

242

243

244

-

245

-

246

-

247

-

248

+

245

+

246

+

247

+

248

249

-

250

+

250

251

-

252

+

252

253

-

254

-

255

-

256

-

257

+

254

+

255

+

256

+

257

258

259

-

260

+

260

261

262

-

263

-

264

-

265

-

266

-

267

+

263

+

264

+

265

+

266

+

267

268

269

270

271

272

-

273

+

273

274

-

275

+

275

276

277

-

278

+

278

279

-

280

+

280

281

282

283

@@ -357,73 +357,73 @@

286

287

288

-

289

-

290

-

291

-

292

+

289

+

290

+

291

+

292

293

294

295

-

296

-

297

-

298

+

296

+

297

+

298

299

-

300

-

301

+

300

+

301

302

-

303

+

303

304

-

305

-

306

-

307

-

308

+

305

+

306

+

307

+

308

309

-

310

-

311

-

312

+

310

+

311

+

312

313

-

314

+

314

315

-

316

-

317

-

318

-

319

+

316

+

317

+

318

+

319

320

-

321

-

322

-

323

+

321

+

322

+

323

324

-

325

+

325

326

-

327

-

328

-

329

-

330

-

331

-

332

+

327

+

328

+

329

+

330

+

331

+

332

333

334

-

335

+

335

336

337

-

338

-

339

-

340

-

341

-

342

+

338

+

339

+

340

+

341

+

342

343

344

345

346

347

-

348

+

348

349

-

350

+

350

351

352

-

353

+

353

354

-

355

+

355

356

357

358

@@ -432,70 +432,70 @@

361

362

363

-

364

-

365

-

366

-

367

+

364

+

365

+

366

+

367

368

369

370

-

371

-

372

-

373

+

371

+

372

+

373

374

-

375

-

376

+

375

+

376

377

-

378

+

378

379

-

380

+

380

381

-

382

-

383

+

382

+

383

384

-

385

+

385

386

387

-

388

-

389

-

390

-

391

+

388

+

389

+

390

+

391

392

-

393

+

393

394

-

395

-

396

+

395

+

396

397

-

398

+

398

399

400

-

401

-

402

-

403

-

404

+

401

+

402

+

403

+

404

405

-

406

+

406

407

-

408

-

409

-

410

+

408

+

409

+

410

411

412

-

413

-

414

-

415

-

416

+

413

+

414

+

415

+

416

417

-

418

+

418

419

-

420

-

421

-

422

+

420

+

421

+

422

423

424

425

426

-

427

+

427

428

429

430

@@ -503,9 +503,10 @@

432

433

434

-

435

-

436

+

435

+

436

437

+

438

@@ -519,433 +520,434 @@

from coverage import coverage 

cov = coverage(branch=True, omit=['/usr/local/lib/python2.7/dist-packages/*', 

'/usr/local/lib/python2.7/site-packages/*', 

-

'test_app.py', 'config.py', 'test_config.py']) 

-

cov.start() 

-

cov.exclude('pragma') 

-

 

-

import unittest 

-

import json 

-

from app import db, app, Person, Event, Group 

-

 

-

class SignupTestCase(unittest.TestCase): 

-

 

-

def setUp(self): 

-

""" 

-

Creates a new database for the unit test to use 

-

""" 

-

app.config.from_pyfile('test_config.py') 

-

db.init_app(app) 

-

db.create_all() 

-

 

-

self.app = app.test_client() 

-

return self.app 

-

 

-

def tearDown(self): 

-

db.drop_all() 

-

 

-

def test_user_signup(self): 

-

response = self.app.post('/signup', data = json.dumps(dict( 

-

email='abc@columbia.edu', 

-

password='passwd', 

-

lastname='ab', 

-

firstname='cd' 

-

))) 

-

assert response.status_code == 200 

-

 

-

def test_existant_user(self): 

-

self.app.post('/signup', data = json.dumps(dict( 

-

email='abc@columbia.edu', 

-

password='passwd', 

-

lastname='ab', 

-

firstname='cd' 

-

))) 

-

# Duplicate accounts 

-

response = self.app.post('/signup', data = json.dumps(dict( 

-

email='abc@columbia.edu', 

-

password='passwd', 

-

lastname='ab', 

-

firstname='cd' 

-

))) 

-

 

-

assert response.status_code == 409 

-

 

-

def test_incomplete_data(self): 

-

''' 

-

Missing email, password, firstname, lastname 

-

''' 

-

resp = self.app.post('/signup', data = json.dumps(dict( 

-

password='passwd', 

-

firstname='cd', 

-

lastname='ab' 

-

))) 

-

assert resp.status_code == 400 

-

 

-

resp = self.app.post('/signup', data = json.dumps(dict( 

-

email='abc@columbia.edu', 

-

firstname='cd', 

-

lastname='ab' 

-

))) 

-

assert resp.status_code == 400 

-

 

-

resp = self.app.post('/signup', data = json.dumps(dict( 

-

email='abc@columbia.edu', 

-

password='passwd', 

-

lastname='ab' 

-

))) 

-

assert resp.status_code == 400 

-

 

-

resp = self.app.post('/signup', data = json.dumps(dict( 

-

email='abc@columbia.edu', 

-

password='passwd', 

-

firstname='cd' 

-

))) 

-

assert resp.status_code == 400 

-

 

+

'/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/*', 

+

'test_app.py', 'config.py', 'test_config.py']) 

+

cov.start() 

+

cov.exclude('pragma') 

+

 

+

import unittest 

+

import json 

+

from app import db, app, Person, Event, Group 

+

 

+

class SignupTestCase(unittest.TestCase): 

+

 

+

def setUp(self): 

+

""" 

+

Creates a new database for the unit test to use 

+

""" 

+

app.config.from_pyfile('test_config.py') 

+

db.init_app(app) 

+

db.create_all() 

+

 

+

self.app = app.test_client() 

+

return self.app 

+

 

+

def tearDown(self): 

+

db.drop_all() 

+

 

+

def test_user_signup(self): 

+

response = self.app.post('/signup', data = json.dumps(dict( 

+

email='abc@columbia.edu', 

+

password='passwd', 

+

lastname='ab', 

+

firstname='cd' 

+

))) 

+

assert response.status_code == 200 

+

 

+

def test_existant_user(self): 

+

self.app.post('/signup', data = json.dumps(dict( 

+

email='abc@columbia.edu', 

+

password='passwd', 

+

lastname='ab', 

+

firstname='cd' 

+

))) 

+

# Duplicate accounts 

+

response = self.app.post('/signup', data = json.dumps(dict( 

+

email='abc@columbia.edu', 

+

password='passwd', 

+

lastname='ab', 

+

firstname='cd' 

+

))) 

+

 

+

assert response.status_code == 409 

+

 

+

def test_incomplete_data(self): 

+

''' 

+

Missing email, password, firstname, lastname 

+

''' 

+

resp = self.app.post('/signup', data = json.dumps(dict( 

+

password='passwd', 

+

firstname='cd', 

+

lastname='ab' 

+

))) 

+

assert resp.status_code == 400 

+

 

+

resp = self.app.post('/signup', data = json.dumps(dict( 

+

email='abc@columbia.edu', 

+

firstname='cd', 

+

lastname='ab' 

+

))) 

+

assert resp.status_code == 400 

+

 

+

resp = self.app.post('/signup', data = json.dumps(dict( 

+

email='abc@columbia.edu', 

+

password='passwd', 

+

lastname='ab' 

+

))) 

+

assert resp.status_code == 400 

+

 

+

resp = self.app.post('/signup', data = json.dumps(dict( 

+

email='abc@columbia.edu', 

+

password='passwd', 

+

firstname='cd' 

+

))) 

+

assert resp.status_code == 400 

 

-

class LoginTestCase(unittest.TestCase): 

-

 

-

def setUp(self): 

-

""" 

-

Creates a new database for the unit test to use 

-

""" 

-

app.config.from_pyfile('test_config.py') 

-

db.init_app(app) 

-

db.create_all() 

-

 

-

self.app = app.test_client() 

-

 

-

# Create test user 

-

new_user = Person( 

-

'validuser@columbia.edu', 

-

'validpassword', 

-

'test', 

-

'testerson' 

-

) 

-

db.session.add(new_user) 

-

db.session.commit() 

-

 

-

return self.app 

-

 

-

def tearDown(self): 

-

db.drop_all() 

-

 

-

def test_user_login(self): 

-

response = self.app.post('/login', data = json.dumps(dict( 

-

exist_email='validuser@columbia.edu', 

-

exist_password='validpassword' 

-

))) 

-

assert response.status_code == 200 

-

 

-

def test_invalid_username(self): 

-

response = self.app.post('/login', data = json.dumps(dict( 

-

exist_email='wronguser@columbia.edu', 

-

exist_password='validpassword' 

-

))) 

-

assert response.status_code == 400 

-

 

-

def test_invalid_password(self): 

-

response = self.app.post('/login', data = json.dumps(dict( 

-

exist_email='validuser@columbia.edu', 

-

exist_password='wrongpassword' 

-

))) 

-

assert response.status_code == 400 

-

 

-

class BrowseTestCase(unittest.TestCase): 

-

 

-

def setUp(self): 

-

""" 

-

Creates a new database for the unit test to use 

-

""" 

-

app.config.from_pyfile('test_config.py') 

-

db.init_app(app) 

-

db.create_all() 

-

 

-

self.app = app.test_client() 

-

return self.app 

-

 

-

def tearDown(self): 

-

db.drop_all() 

-

 

-

def test_root_unlogined(self): 

-

response = self.app.get('/') 

-

assert response.location == 'http://localhost/login/index.html' 

-

 

+

 

+

class LoginTestCase(unittest.TestCase): 

+

 

+

def setUp(self): 

+

""" 

+

Creates a new database for the unit test to use 

+

""" 

+

app.config.from_pyfile('test_config.py') 

+

db.init_app(app) 

+

db.create_all() 

+

 

+

self.app = app.test_client() 

+

 

+

# Create test user 

+

new_user = Person( 

+

'validuser@columbia.edu', 

+

'validpassword', 

+

'test', 

+

'testerson' 

+

) 

+

db.session.add(new_user) 

+

db.session.commit() 

+

 

+

return self.app 

+

 

+

def tearDown(self): 

+

db.drop_all() 

+

 

+

def test_user_login(self): 

+

response = self.app.post('/login', data = json.dumps(dict( 

+

exist_email='validuser@columbia.edu', 

+

exist_password='validpassword' 

+

))) 

+

assert response.status_code == 200 

+

 

+

def test_invalid_username(self): 

+

response = self.app.post('/login', data = json.dumps(dict( 

+

exist_email='wronguser@columbia.edu', 

+

exist_password='validpassword' 

+

))) 

+

assert response.status_code == 400 

+

 

+

def test_invalid_password(self): 

+

response = self.app.post('/login', data = json.dumps(dict( 

+

exist_email='validuser@columbia.edu', 

+

exist_password='wrongpassword' 

+

))) 

+

assert response.status_code == 400 

+

 

+

class BrowseTestCase(unittest.TestCase): 

+

 

+

def setUp(self): 

+

""" 

+

Creates a new database for the unit test to use 

+

""" 

+

app.config.from_pyfile('test_config.py') 

+

db.init_app(app) 

+

db.create_all() 

+

 

+

self.app = app.test_client() 

+

return self.app 

+

 

+

def tearDown(self): 

+

db.drop_all() 

+

 

+

def test_root_unlogined(self): 

+

response = self.app.get('/') 

+

assert response.location == 'http://localhost/login/index.html' 

 

 

 

-

class EventsTestCase(unittest.TestCase): 

-

 

-

def setUp(self): 

-

""" 

-

Creates a new database for the unit test to use 

-

""" 

-

app.config.from_pyfile('test_config.py') 

-

db.init_app(app) 

-

db.create_all() 

-

 

-

app.config['TESTING'] = True 

-

app.login_manager.init_app(app) 

-

 

-

self.app = app.test_client() 

-

 

-

self.app.post('/signup', data = json.dumps(dict( 

-

email='abc@columbia.edu', 

-

password='passwd', 

-

lastname='ab', 

-

firstname='cd' 

-

))) 

-

 

-

self.app.post('/login', data = json.dumps(dict( 

-

exist_email='abc@columbia.edu', 

-

exist_password='passwd' 

-

))) 

-

 

+

 

+

class EventsTestCase(unittest.TestCase): 

+

 

+

def setUp(self): 

+

""" 

+

Creates a new database for the unit test to use 

+

""" 

+

app.config.from_pyfile('test_config.py') 

+

db.init_app(app) 

+

db.create_all() 

+

 

+

app.config['TESTING'] = True 

+

app.login_manager.init_app(app) 

+

 

+

self.app = app.test_client() 

+

 

+

self.app.post('/signup', data = json.dumps(dict( 

+

email='abc@columbia.edu', 

+

password='passwd', 

+

lastname='ab', 

+

firstname='cd' 

+

))) 

+

 

+

self.app.post('/login', data = json.dumps(dict( 

+

exist_email='abc@columbia.edu', 

+

exist_password='passwd' 

+

))) 

 

-

def tearDown(self): 

-

db.drop_all() 

-

 

+

 

+

def tearDown(self): 

+

db.drop_all() 

 

-

def test_no_events(self): 

-

response = self.app.get('/events', 

-

content_type='application/json' 

-

) 

-

data = json.loads(response.data) 

-

assert len(data['events']) == 0 

-

 

-

def test_insert_event_lackinfo(self): 

-

# Add a group to test DB 

-

db.session.add(Group({ 

-

'group_id': '456', 

-

'group': 'testgroup' 

-

})) 

-

# Add an event to test DB 

-

db.session.commit() 

-

 

-

db.session.add(Event({ 

-

'id': '000', 

-

'group_id': '456' 

-

})) 

-

db.session.commit() 

-

response = self.app.get('/events', 

-

content_type='application/json' 

-

) 

-

data = json.loads(response.data) 

-

assert len(data['events']) == 1 

-

 

-

def test_events_returned(self): 

-

# Add a group to test DB 

-

agroup = Group({ 

-

'group_id': '456', 

-

'group': 'testgroup' 

-

}) 

-

print agroup 

-

db.session.add(agroup) 

-

# Add an event to test DB 

-

db.session.commit() 

-

 

-

db.session.add(Event({ 

-

'id': '123', 

-

'datetime': '1993-11-17T12:00:00', 

-

'location': 'mars', 

-

'group_id': '456', 

-

'title': 'a new event', 

-

'url': 'http://www.testevent.com', 

-

'photo_url': 'http://www.testphotourl.com' 

-

})) 

-

 

-

db.session.commit() 

-

 

-

response = self.app.get('/events', 

-

content_type='application/json' 

-

) 

-

data = json.loads(response.data) 

-

assert len(data['events']) == 1 

-

 

+

 

+

def test_no_events(self): 

+

response = self.app.get('/events', 

+

content_type='application/json' 

+

) 

+

data = json.loads(response.data) 

+

assert len(data['events']) == 0 

+

 

+

def test_insert_event_lackinfo(self): 

+

# Add a group to test DB 

+

db.session.add(Group({ 

+

'group_id': '456', 

+

'group': 'testgroup' 

+

})) 

+

# Add an event to test DB 

+

db.session.commit() 

+

 

+

db.session.add(Event({ 

+

'id': '000', 

+

'group_id': '456' 

+

})) 

+

db.session.commit() 

+

response = self.app.get('/events', 

+

content_type='application/json' 

+

) 

+

data = json.loads(response.data) 

+

assert len(data['events']) == 1 

+

 

+

def test_events_returned(self): 

+

# Add a group to test DB 

+

agroup = Group({ 

+

'group_id': '456', 

+

'group': 'testgroup' 

+

}) 

+

print agroup 

+

db.session.add(agroup) 

+

# Add an event to test DB 

+

db.session.commit() 

+

 

+

db.session.add(Event({ 

+

'id': '123', 

+

'datetime': '1993-11-17T12:00:00', 

+

'location': 'mars', 

+

'group_id': '456', 

+

'title': 'a new event', 

+

'url': 'http://www.testevent.com', 

+

'photo_url': 'http://www.testphotourl.com' 

+

})) 

+

 

+

db.session.commit() 

+

 

+

response = self.app.get('/events', 

+

content_type='application/json' 

+

) 

+

data = json.loads(response.data) 

+

assert len(data['events']) == 1 

 

-

class FavoritesTestCase(unittest.TestCase): 

-

 

-

def setUp(self): 

-

""" 

-

Creates a new database for the unit test to use 

-

""" 

-

app.config.from_pyfile('test_config.py') 

-

db.init_app(app) 

-

db.create_all() 

-

 

-

self.app = app.test_client() 

-

 

-

new_user = Person( 

-

'asdf123@columbia.edu', 

-

'asdf', 

-

'test', 

-

'testerson' 

-

) 

-

 

-

db.session.add(new_user) 

-

db.session.add(Group({ 

-

'group_id':'12345', 

-

'group':'groupname' 

-

})) 

-

db.session.commit() 

-

db.session.add(Event({ 

-

'id': '123', 

-

'datetime': '1993-11-17T12:00:00', 

-

'location': 'mars', 

-

'group_id':'12345', 

-

'group': 'columbiagroup', 

-

'title': 'a new event', 

-

'group_url': 'http://www.google.com' 

-

})) 

-

 

-

db.session.commit() 

-

 

-

self.app.post('/login', data = json.dumps(dict( 

-

exist_email='asdf123@columbia.edu', 

-

exist_password='asdf' 

-

))) 

-

 

-

return self.app 

-

 

-

def tearDown(self): 

-

db.drop_all() 

-

 

-

def test_set_unset_favorite(self): 

-

response = self.app.post('/favorite', data = json.dumps(dict( 

-

id='123' 

-

))) 

-

assert response.status_code == 200 

-

 

-

response = self.app.delete('/favorite', data = json.dumps(dict( 

-

id='123' 

-

))) 

-

assert response.status_code == 200 

-

 

-

def test_dup_set_fav(self): 

-

response = self.app.post('/favorite', data = json.dumps(dict( 

-

id='123' 

-

))) 

-

assert response.status_code == 200 

-

 

-

response = self.app.post('/favorite', data = json.dumps(dict( 

-

id='123' 

-

))) 

-

assert response.status_code == 409 

-

 

-

def test_unset_nothing(self): 

-

response = self.app.delete('/favorite', data = json.dumps(dict( 

-

id='123' 

-

))) 

-

assert response.status_code == 404 

-

 

-

class RatingTestCase(unittest.TestCase): 

-

 

-

def setUp(self): 

-

""" 

-

Creates a new database for the unit test to use 

-

""" 

-

app.config.from_pyfile('test_config.py') 

-

db.init_app(app) 

-

db.create_all() 

-

 

-

self.app = app.test_client() 

-

 

-

new_user = Person( 

-

'asdf123@columbia.edu', 

-

'asdf', 

-

'test', 

-

'testerson' 

-

) 

-

 

-

db.session.add(new_user) 

-

db.session.add(Group({ 

-

'group_id':'12345', 

-

'group':'groupname' 

-

})) 

-

db.session.commit() 

-

db.session.add(Event({ 

-

'id': '123', 

-

'datetime': '1993-11-17T12:00:00', 

-

'location': 'mars', 

-

'group_id': '12345', 

-

'title': 'a new event', 

-

'url': 'http://www.testevent.com', 

-

'photo_url': 'http://www.testphotourl.com' 

-

})) 

-

 

-

db.session.commit() 

-

 

-

self.app.post('/login', data = json.dumps(dict( 

-

exist_email='asdf123@columbia.edu', 

-

exist_password='asdf' 

-

))) 

-

 

-

return self.app 

-

 

-

def tearDown(self): 

-

db.drop_all() 

-

 

-

def test_show_default_rating(self): 

-

response = self.app.get('/events', 

-

content_type='application/json' 

-

) 

-

data = json.loads(response.data) 

-

assert data['events'][0]['rating'] == 5 

-

 

-

def test_rate(self): 

-

response = self.app.post('/rate', data = json.dumps(dict( 

-

group_id='12345', 

-

rate_value=1 

-

))) 

-

assert response.status_code == 200 

-

 

-

response = self.app.get('/events', 

-

content_type='application/json' 

-

) 

-

data = json.loads(response.data) 

-

assert data['events'][0]['rating'] == 3 

-

 

-

def test_duprate(self): 

-

response = self.app.post('/rate', data = json.dumps(dict( 

-

group_id='12345', 

-

rate_value=1 

-

))) 

-

assert response.status_code == 200 

-

 

-

response = self.app.get('/events', 

-

content_type='application/json' 

-

) 

-

data = json.loads(response.data) 

-

assert data['events'][0]['rating'] == 3 

-

 

-

response = self.app.post('/rate', data = json.dumps(dict( 

-

group_id='12345', 

-

rate_value=3 

-

))) 

-

assert response.status_code == 200 

-

 

-

response = self.app.get('/events', 

-

content_type='application/json' 

-

) 

-

data = json.loads(response.data) 

-

assert data['events'][0]['rating'] == 4 

-

 

-

if __name__ == '__main__': 

-

# with open('test_app.py') as f: 

-

# for l in f: 

-

# if 'def test_' in l and 'if' not in l: 

-

# print l.strip() 

-

 

-

try: 

-

unittest.main() 

-

except: 

-

pass 

-

cov.stop() 

-

cov.save() 

-

print("\n\nCoverage Report:\n") 

-

cov.report() 

-

 

-

cov.html_report() 

-

cov.erase() 

+

 

+

class FavoritesTestCase(unittest.TestCase): 

+

 

+

def setUp(self): 

+

""" 

+

Creates a new database for the unit test to use 

+

""" 

+

app.config.from_pyfile('test_config.py') 

+

db.init_app(app) 

+

db.create_all() 

+

 

+

self.app = app.test_client() 

+

 

+

new_user = Person( 

+

'asdf123@columbia.edu', 

+

'asdf', 

+

'test', 

+

'testerson' 

+

) 

+

 

+

db.session.add(new_user) 

+

db.session.add(Group({ 

+

'group_id':'12345', 

+

'group':'groupname' 

+

})) 

+

db.session.commit() 

+

db.session.add(Event({ 

+

'id': '123', 

+

'datetime': '1993-11-17T12:00:00', 

+

'location': 'mars', 

+

'group_id':'12345', 

+

'group': 'columbiagroup', 

+

'title': 'a new event', 

+

'group_url': 'http://www.google.com' 

+

})) 

+

 

+

db.session.commit() 

+

 

+

self.app.post('/login', data = json.dumps(dict( 

+

exist_email='asdf123@columbia.edu', 

+

exist_password='asdf' 

+

))) 

+

 

+

return self.app 

+

 

+

def tearDown(self): 

+

db.drop_all() 

+

 

+

def test_set_unset_favorite(self): 

+

response = self.app.post('/favorite', data = json.dumps(dict( 

+

id='123' 

+

))) 

+

assert response.status_code == 200 

+

 

+

response = self.app.delete('/favorite', data = json.dumps(dict( 

+

id='123' 

+

))) 

+

assert response.status_code == 200 

+

 

+

def test_dup_set_fav(self): 

+

response = self.app.post('/favorite', data = json.dumps(dict( 

+

id='123' 

+

))) 

+

assert response.status_code == 200 

+

 

+

response = self.app.post('/favorite', data = json.dumps(dict( 

+

id='123' 

+

))) 

+

assert response.status_code == 409 

+

 

+

def test_unset_nothing(self): 

+

response = self.app.delete('/favorite', data = json.dumps(dict( 

+

id='123' 

+

))) 

+

assert response.status_code == 404 

+

 

+

class RatingTestCase(unittest.TestCase): 

+

 

+

def setUp(self): 

+

""" 

+

Creates a new database for the unit test to use 

+

""" 

+

app.config.from_pyfile('test_config.py') 

+

db.init_app(app) 

+

db.create_all() 

+

 

+

self.app = app.test_client() 

+

 

+

new_user = Person( 

+

'asdf123@columbia.edu', 

+

'asdf', 

+

'test', 

+

'testerson' 

+

) 

+

 

+

db.session.add(new_user) 

+

db.session.add(Group({ 

+

'group_id':'12345', 

+

'group':'groupname' 

+

})) 

+

db.session.commit() 

+

db.session.add(Event({ 

+

'id': '123', 

+

'datetime': '1993-11-17T12:00:00', 

+

'location': 'mars', 

+

'group_id': '12345', 

+

'title': 'a new event', 

+

'url': 'http://www.testevent.com', 

+

'photo_url': 'http://www.testphotourl.com' 

+

})) 

+

 

+

db.session.commit() 

+

 

+

self.app.post('/login', data = json.dumps(dict( 

+

exist_email='asdf123@columbia.edu', 

+

exist_password='asdf' 

+

))) 

+

 

+

return self.app 

+

 

+

def tearDown(self): 

+

db.drop_all() 

+

 

+

def test_show_default_rating(self): 

+

response = self.app.get('/events', 

+

content_type='application/json' 

+

) 

+

data = json.loads(response.data) 

+

assert data['events'][0]['rating'] == 5 

+

 

+

def test_rate(self): 

+

response = self.app.post('/rate', data = json.dumps(dict( 

+

group_id='12345', 

+

rate_value=1 

+

))) 

+

assert response.status_code == 200 

+

 

+

response = self.app.get('/events', 

+

content_type='application/json' 

+

) 

+

data = json.loads(response.data) 

+

assert data['events'][0]['rating'] == 3 

+

 

+

def test_duprate(self): 

+

response = self.app.post('/rate', data = json.dumps(dict( 

+

group_id='12345', 

+

rate_value=1 

+

))) 

+

assert response.status_code == 200 

+

 

+

response = self.app.get('/events', 

+

content_type='application/json' 

+

) 

+

data = json.loads(response.data) 

+

assert data['events'][0]['rating'] == 3 

+

 

+

response = self.app.post('/rate', data = json.dumps(dict( 

+

group_id='12345', 

+

rate_value=3 

+

))) 

+

assert response.status_code == 200 

+

 

+

response = self.app.get('/events', 

+

content_type='application/json' 

+

) 

+

data = json.loads(response.data) 

+

assert data['events'][0]['rating'] == 4 

+

 

+

if __name__ == '__main__': 

+

# with open('test_app.py') as f: 

+

# for l in f: 

+

# if 'def test_' in l and 'if' not in l: 

+

# print l.strip() 

+

 

+

try: 

+

unittest.main() 

+

except: 

+

pass 

+

cov.stop() 

+

cov.save() 

+

print("\n\nCoverage Report:\n") 

+

cov.report() 

+

 

+

cov.html_report() 

+

cov.erase() 

@@ -956,7 +958,7 @@

« index     coverage.py v4.2, - created at 2016-12-10 22:08 + created at 2017-01-01 14:13

diff --git a/htmlcov/server_test_config_py.html b/htmlcov/server_test_config_py.html index e31c5aa..5f03dc7 100644 --- a/htmlcov/server_test_config_py.html +++ b/htmlcov/server_test_config_py.html @@ -85,7 +85,7 @@

""" 

flask_sqlalchemy: test_config.py 

""" 

-

SQLALCHEMY_DATABASE_URI = "postgresql://ase4156:dbpass@0.0.0.0/testeventscalendar" 

+

SQLALCHEMY_DATABASE_URI = "postgresql://ase4156:dbpass@35.185.1.150/testeventscalendar" 

#Flask-SQLAlchemy will log all the statements issued to stderr 

SQLALCHEMY_ECHO = False 

#Flask-SQLAlchemy will track modifications of objects and emit signals. 

@@ -102,7 +102,7 @@

« index     coverage.py v4.2, - created at 2016-12-10 22:08 + created at 2017-01-01 14:13

diff --git a/htmlcov/status.json b/htmlcov/status.json index 83e0bcc..9246a65 100644 --- a/htmlcov/status.json +++ b/htmlcov/status.json @@ -1 +1 @@ -{"files": {"server_test_app_py": {"index": {"relative_filename": "server/test_app.py", "html_filename": "server_test_app_py.html", "nums": [1, 176, 1, 18, 2, 0, 2]}, "hash": "97b1e4175b3e16f6b955ffebd8abe0bc"}, "server_config_py": {"index": {"relative_filename": "server/config.py", "html_filename": "server_config_py.html", "nums": [1, 3, 0, 0, 0, 0, 0]}, "hash": "aa65279745905da77ce34bfec3a8c1a0"}, "server_app_py": {"index": {"relative_filename": "server/app.py", "html_filename": "server_app_py.html", "nums": [1, 215, 17, 12, 32, 3, 7]}, "hash": "f0dc20fc8acadee6f6e3816a8fc62615"}, "server_test_config_py": {"index": {"relative_filename": "server/test_config.py", "html_filename": "server_test_config_py.html", "nums": [1, 4, 0, 0, 0, 0, 0]}, "hash": "c957e107815286217551b0b1f72941ec"}}, "version": "4.2", "settings": "078bc25b6cf52e7b9c31ce9a016765a4", "format": 1} \ No newline at end of file +{"files": {"server_test_app_py": {"index": {"relative_filename": "server/test_app.py", "html_filename": "server_test_app_py.html", "nums": [1, 176, 1, 18, 2, 0, 2]}, "hash": "fea369e8fed0aab0182ed8079be8d218"}, "server_app_py": {"index": {"relative_filename": "server/app.py", "html_filename": "server_app_py.html", "nums": [1, 215, 17, 12, 32, 3, 7]}, "hash": "f0dc20fc8acadee6f6e3816a8fc62615"}, "server_config_py": {"index": {"relative_filename": "server/config.py", "html_filename": "server_config_py.html", "nums": [1, 3, 0, 0, 0, 0, 0]}, "hash": "aa65279745905da77ce34bfec3a8c1a0"}, "server_test_config_py": {"index": {"relative_filename": "server/test_config.py", "html_filename": "server_test_config_py.html", "nums": [1, 4, 0, 0, 0, 0, 0]}, "hash": "07d705d813384b9ab49a94245be19ee3"}}, "version": "4.2", "settings": "08925659c538384f15adb6b0cd6e2080", "format": 1} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 79255d7..dbc91af 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ Flask-Login==0.4.0 APScheduler==3.0.2 requests==2.3.0 coverage==4.2 -mock==2.0.0 \ No newline at end of file +mock==2.0.0 +newrelic \ No newline at end of file diff --git a/scraper/newrelic.ini b/scraper/newrelic.ini new file mode 100644 index 0000000..c23b265 --- /dev/null +++ b/scraper/newrelic.ini @@ -0,0 +1,199 @@ +# --------------------------------------------------------------------------- + +# +# This file configures the New Relic Python Agent. +# +# The path to the configuration file should be supplied to the function +# newrelic.agent.initialize() when the agent is being initialized. +# +# The configuration file follows a structure similar to what you would +# find for Microsoft Windows INI files. For further information on the +# configuration file format see the Python ConfigParser documentation at: +# +# http://docs.python.org/library/configparser.html +# +# For further discussion on the behaviour of the Python agent that can +# be configured via this configuration file see: +# +# http://newrelic.com/docs/python/python-agent-configuration +# + +# --------------------------------------------------------------------------- + +# Here are the settings that are common to all environments. + +[newrelic] + +# You must specify the license key associated with your New +# Relic account. This key binds the Python Agent's data to your +# account in the New Relic service. +license_key = c8b3033005cacd383c6313073a6b010de0002a26 + +# The appplication name. Set this to be the name of your +# application as you would like it to show up in New Relic UI. +# The UI will then auto-map instances of your application into a +# entry on your home dashboard page. +app_name = Python Application + +# When "true", the agent collects performance data about your +# application and reports this data to the New Relic UI at +# newrelic.com. This global switch is normally overridden for +# each environment below. +monitor_mode = true + +# Sets the name of a file to log agent messages to. Useful for +# debugging any issues with the agent. This is not set by +# default as it is not known in advance what user your web +# application processes will run as and where they have +# permission to write to. Whatever you set this to you must +# ensure that the permissions for the containing directory and +# the file itself are correct, and that the user that your web +# application runs as can write to the file. If not able to +# write out a log file, it is also possible to say "stderr" and +# output to standard error output. This would normally result in +# output appearing in your web server log. +#log_file = /tmp/newrelic-python-agent.log + +# Sets the level of detail of messages sent to the log file, if +# a log file location has been provided. Possible values, in +# increasing order of detail, are: "critical", "error", "warning", +# "info" and "debug". When reporting any agent issues to New +# Relic technical support, the most useful setting for the +# support engineers is "debug". However, this can generate a lot +# of information very quickly, so it is best not to keep the +# agent at this level for longer than it takes to reproduce the +# problem you are experiencing. +log_level = info + +# The Python Agent communicates with the New Relic service using +# SSL by default. Note that this does result in an increase in +# CPU overhead, over and above what would occur for a non SSL +# connection, to perform the encryption involved in the SSL +# communication. This work is though done in a distinct thread +# to those handling your web requests, so it should not impact +# response times. You can if you wish revert to using a non SSL +# connection, but this will result in information being sent +# over a plain socket connection and will not be as secure. +ssl = true + +# The Python Agent will attempt to connect directly to the New +# Relic service. If there is an intermediate firewall between +# your host and the New Relic service that requires you to use a +# HTTP proxy, then you should set both the "proxy_host" and +# "proxy_port" settings to the required values for the HTTP +# proxy. The "proxy_user" and "proxy_pass" settings should +# additionally be set if proxy authentication is implemented by +# the HTTP proxy. The "proxy_scheme" setting dictates what +# protocol scheme is used in talking to the HTTP protocol. This +# would normally always be set as "http" which will result in the +# agent then using a SSL tunnel through the HTTP proxy for end to +# end encryption. +# proxy_scheme = http +# proxy_host = hostname +# proxy_port = 8080 +# proxy_user = +# proxy_pass = + +# Tells the transaction tracer and error collector (when +# enabled) whether or not to capture the query string for the +# URL and send it as the request parameters for display in the +# UI. When "true", it is still possible to exclude specific +# values from being captured using the "ignored_params" setting. +capture_params = false + +# Space separated list of variables that should be removed from +# the query string captured for display as the request +# parameters in the UI. +ignored_params = + +# The transaction tracer captures deep information about slow +# transactions and sends this to the UI on a periodic basis. The +# transaction tracer is enabled by default. Set this to "false" +# to turn it off. +transaction_tracer.enabled = true + +# Threshold in seconds for when to collect a transaction trace. +# When the response time of a controller action exceeds this +# threshold, a transaction trace will be recorded and sent to +# the UI. Valid values are any positive float value, or (default) +# "apdex_f", which will use the threshold for a dissatisfying +# Apdex controller action - four times the Apdex T value. +transaction_tracer.transaction_threshold = apdex_f + +# When the transaction tracer is on, SQL statements can +# optionally be recorded. The recorder has three modes, "off" +# which sends no SQL, "raw" which sends the SQL statement in its +# original form, and "obfuscated", which strips out numeric and +# string literals. +transaction_tracer.record_sql = obfuscated + +# Threshold in seconds for when to collect stack trace for a SQL +# call. In other words, when SQL statements exceed this +# threshold, then capture and send to the UI the current stack +# trace. This is helpful for pinpointing where long SQL calls +# originate from in an application. +transaction_tracer.stack_trace_threshold = 0.5 + +# Determines whether the agent will capture query plans for slow +# SQL queries. Only supported in MySQL and PostgreSQL. Set this +# to "false" to turn it off. +transaction_tracer.explain_enabled = true + +# Threshold for query execution time below which query plans +# will not not be captured. Relevant only when "explain_enabled" +# is true. +transaction_tracer.explain_threshold = 0.5 + +# Space separated list of function or method names in form +# 'module:function' or 'module:class.function' for which +# additional function timing instrumentation will be added. +transaction_tracer.function_trace = + +# The error collector captures information about uncaught +# exceptions or logged exceptions and sends them to UI for +# viewing. The error collector is enabled by default. Set this +# to "false" to turn it off. +error_collector.enabled = true + +# To stop specific errors from reporting to the UI, set this to +# a space separated list of the Python exception type names to +# ignore. The exception name should be of the form 'module:class'. +error_collector.ignore_errors = + +# Browser monitoring is the Real User Monitoring feature of the UI. +# For those Python web frameworks that are supported, this +# setting enables the auto-insertion of the browser monitoring +# JavaScript fragments. +browser_monitoring.auto_instrument = true + +# A thread profiling session can be scheduled via the UI when +# this option is enabled. The thread profiler will periodically +# capture a snapshot of the call stack for each active thread in +# the application to construct a statistically representative +# call tree. +thread_profiler.enabled = true + +# --------------------------------------------------------------------------- + +# +# The application environments. These are specific settings which +# override the common environment settings. The settings related to a +# specific environment will be used when the environment argument to the +# newrelic.agent.initialize() function has been defined to be either +# "development", "test", "staging" or "production". +# + +[newrelic:development] +monitor_mode = false + +[newrelic:test] +monitor_mode = false + +[newrelic:staging] +app_name = Python Application (Staging) +monitor_mode = true + +[newrelic:production] +monitor_mode = true + +# ---------------------------------------------------------------------------