def test_delete_endpoint(self): """ User's contact DELETE delete endpoint """ # not found res = self.get(self.DELETE_URN.format(uuid=generate_uuid())) self.assert404(res) # adding datesets to db contacts = [Contact(userId=self.user.id, **item) for item in datasets.delete.CONTACTS] db.session.add_all(contacts) db.session.commit() # success delete res = self.get(self.DELETE_URN.format(uuid=contacts[0].uuid)) self.assert200(res) data = res.json['data'] self.assert200(res) self.assertEqual(data['id'], contacts[0].id) self.assertEqual(data['uuid'], contacts[0].uuid) self.assertEqual(data['firstName'], contacts[0].firstName) self.assertEqual(data['lastName'], contacts[0].lastName) self.assertEqual(data['phoneNumber'], contacts[0].phoneNumber) self.assertEqual(data['email'], contacts[0].email) self.assertIsNotNone(data['created'])
def test_get_endpoint(self): """ User's contact GET get endpoint """ # not found res = self.get(self.GET_URN.format(uuid=generate_uuid())) self.assert404(res) # adding datesets to db contacts = [Contact(userId=self.user.id, **item) for item in datasets.get.CONTACTS] db.session.add_all(contacts) db.session.commit() # getting template for contact in contacts: res = self.get(self.GET_URN.format(uuid=contact.uuid)) data = res.json['data'] self.assert200(res) self.assertIsNotNone(data['id']) self.assertIsNotNone(data['uuid']) self.assertEqual(data['firstName'], contact.firstName) self.assertEqual(data['lastName'], contact.lastName) self.assertEqual(data['phoneNumber'], contact.phoneNumber) self.assertEqual(data['email'], contact.email) self.assertIsNotNone(data['created'])
def test_delete_endpoint(self): """ Testing user template DELETE endpoint """ # not found res = self.delete(self.DELETE_URN.format(uuid=generate_uuid())) self.assert404(res) # import datasets templates = [ Template(userId=self.user.id, **item) for item in datasets.delete.TEMPLATES ] db.session.add_all(templates) db.session.commit() # success delete res = self.delete(self.DELETE_URN.format(uuid=templates[0].uuid)) templates = Template.query.filter_by(userId=self.user.id).all() self.assert200(res) self.assertEqual(len(templates), 1) # success delete res = self.delete(self.DELETE_URN.format(uuid=templates[0].uuid)) templates = Template.query.filter_by(userId=self.user.id).all() self.assert200(res) self.assertEqual(len(templates), 0) self.assertIsNotNone(res.json['data']['uuid']) self.assertIsNotNone(res.json['data']['label']) self.assertIsNotNone(res.json['data']['text']) self.assertIsNotNone(res.json['data']['created'])
def test_delete_endpoint(self): """ Testing user template DELETE endpoint """ # not found res = self.delete(self.DELETE_URN.format(uuid=generate_uuid())) self.assert404(res) # import datasets templates = [Template(userId=self.user.id, **item) for item in datasets.delete.TEMPLATES] db.session.add_all(templates) db.session.commit() # success delete res = self.delete(self.DELETE_URN.format(uuid=templates[0].uuid)) templates = Template.query.filter_by(userId=self.user.id).all() self.assert200(res) self.assertEqual(len(templates), 1) # success delete res = self.delete(self.DELETE_URN.format(uuid=templates[0].uuid)) templates = Template.query.filter_by(userId=self.user.id).all() self.assert200(res) self.assertEqual(len(templates), 0) self.assertIsNotNone(res.json['data']['uuid']) self.assertIsNotNone(res.json['data']['label']) self.assertIsNotNone(res.json['data']['text']) self.assertIsNotNone(res.json['data']['created'])
def test_put_endpoint(self): """ Testing user application PUT update endpoint """ res = self.put(self.PUT_URN.format(uuid=generate_uuid())) self.assert404(res) # import datasets to DB apps = [Application(userId=self.user.id, **item) for item in datasets.put.APPS] db.session.add_all(apps) db.session.commit() # no label res = self.put(self.PUT_URN.format(uuid=apps[0].uuid), data={}) self.assert400(res) # short label res = self.put(self.PUT_URN.format(uuid=apps[0].uuid), data=datasets.put.INVALID_LABEL) self.assert400(res) # invlid code res = self.put(self.PUT_URN.format(uuid=apps[0].uuid), data=datasets.put.INVALID_CODE) self.assert400(res) # invalid url res = self.put(self.PUT_URN.format(uuid=apps[0].uuid), data=datasets.put.INVALID_URL) self.assert400(res) # already existing code res = self.put(self.PUT_URN.format(uuid=apps[0].uuid), data=datasets.put.DUPLICATED_CODE) self.assert409(res) # success res = self.put(self.PUT_URN.format(uuid=apps[0].uuid), data=datasets.put.VALID) data = res.json['data'] self.assert200(res) self.assertIsNotNone(data['id']) self.assertIsNotNone(data['uuid']) self.assertIsNotNone(data['token']) self.assertEqual(data['label'], datasets.put.VALID['label']) self.assertEqual(data['prefix'], datasets.put.VALID['prefix']) self.assertEqual(data['callbackUrl'], datasets.put.VALID['callbackUrl']) self.assertIsNone(data['note']) apps = Application.query.filter_by(userId=self.user.id).all() self.assertEqual(len(apps), 3)
def test_regenerate_endpoint(self): """ Testing user application PUT regenerate endpoint """ res = self.put(self.REG_URN.format(uuid=generate_uuid())) self.assert404(res) # import template datasets to DB app = Application(userId=self.user.id, **datasets.regenerate.APP) db.session.add(app) db.session.commit() res = self.put(self.REG_URN.format(uuid=app.uuid)) db.session.refresh(app) data = res.json['data'] self.assert200(res) self.assertEqual(data['uuid'], app.uuid) self.assertEqual(data['token'], app.token)
def test_put_endpoint(self): """ Testing user tag PUT update endpoint """ res = self.put(self.PUT_URN.format(uuid=generate_uuid())) self.assert404(res) # import template datasets to DB tags = [Tag(userId=self.user.id, **item) for item in datasets.put.TAGS] db.session.add_all(tags) db.session.commit() # no label res = self.put(self.PUT_URN.format(uuid=tags[0].uuid), data={}) self.assert400(res) # short label res = self.put(self.PUT_URN.format(uuid=tags[0].uuid), data=datasets.put.INVALID_LABEL) self.assert400(res) # long label res = self.put(self.PUT_URN.format(uuid=tags[0].uuid), data=datasets.put.INVALID_LONGLABEL) self.assert400(res) # already existing label res = self.put(self.PUT_URN.format(uuid=tags[0].uuid), data=datasets.put.INVALID_EXISTS) self.assert409(res) # success res = self.put(self.PUT_URN.format(uuid=tags[0].uuid), data=datasets.put.VALID) data = res.json['data'] self.assert200(res) self.assertIsNotNone(data['id']) self.assertIsNotNone(data['uuid']) self.assertEqual(data['label'], datasets.put.VALID['label']) self.assertIsNotNone(data['reference']) self.assertEqual(data['note'], datasets.put.VALID['note']) self.assertEqual(len(Tag.query.filter_by(userId=self.user.id).all()), 3)
def test_put_endpoint(self): """ Testing user template PUT endpoint """ # no found res = self.put(self.PUT_URN.format(uuid=generate_uuid())) self.assert404(res) # insert dataset template = Template(userId=self.user.id, **datasets.put.VALID) db.session.add(template) db.session.commit() # short label res = self.put(self.PUT_URN.format(uuid=template.uuid), data=datasets.put.INVALID_SHORTLABEL) self.assert400(res) # long label res = self.put(self.PUT_URN.format(uuid=template.uuid), data=datasets.put.INVALID_LONGLABEL) self.assert400(res) # no text res = self.put(self.PUT_URN.format(uuid=template.uuid), data=datasets.put.INVALID_NOTEXT) self.assert400(res) # short text res = self.put(self.PUT_URN.format(uuid=template.uuid), data=datasets.put.INVALID_SHORTTEXT) self.assert400(res) # successfull update res = self.put(self.PUT_URN.format(uuid=template.uuid), data=datasets.put.VALID_UPDATE) data = res.json['data'] db.session.refresh(template) self.assert200(res) self.assertEqual(data['label'], datasets.put.VALID_UPDATE['label']) self.assertEqual(data['text'], datasets.put.VALID_UPDATE['text']) self.assertEqual(data['label'], template.label) self.assertEqual(data['text'], template.text)
def test_get_endpoint(self): """ Testing user tag GET get endpoint """ res = self.get(self.GET_URN.format(uuid=generate_uuid())) self.assert404(res) # import template datasets to DB tag = Tag(userId=self.user.id, **datasets.get.TAG) db.session.add(tag) db.session.commit() db.session.refresh(tag) res = self.get(self.GET_URN.format(uuid=tag.uuid)) data = res.json['data'] self.assert200(res) self.assertEqual(data['id'], tag.id) self.assertEqual(data['uuid'], tag.uuid) self.assertEqual(data['label'], tag.label) self.assertEqual(data['reference'], tag.reference) self.assertEqual(data['note'], tag.note)
def test_put_endpoint(self): """ User's contact PUT update endpoint""" # not found res = self.put(self.PUT_URN.format(uuid=generate_uuid())) self.assert404(res) # adding contact to DB contact = Contact(userId=self.user.id, **datasets.put.VALID) db.session.add(contact) db.session.commit() # invalid email res = self.put(self.PUT_URN.format(uuid=contact.uuid), data=datasets.put.INVALID_EMAIL) self.assert400(res) # invalid number res = self.put(self.PUT_URN.format(uuid=contact.uuid), data=datasets.put.INVALID_NUMBER) self.assert400(res) # missing field res = self.put(self.PUT_URN.format(uuid=contact.uuid), data=datasets.put.MISSING_FIELD) self.assert400(res) # success res = self.put(self.PUT_URN.format(uuid=contact.uuid), data=datasets.put.UPDATE) self.assert200(res) db.session.refresh(contact) data = res.json['data'] self.assertEqual(data['id'], contact.id) self.assertEqual(data['uuid'], contact.uuid) self.assertEqual(data['firstName'], contact.firstName) self.assertEqual(data['lastName'], contact.lastName) self.assertEqual(data['phoneNumber'], contact.phoneNumber) self.assertEqual(data['email'], contact.email) self.assertIsNone(data['note']) self.assertIsNotNone(data['created'])
def test_delete_endpoint(self): """ Testing user tag DELETE remove endpoint """ res = self.delete(self.DELETE_URN.format(uuid=generate_uuid())) self.assert404(res) # import template datasets to DB tag = Tag(userId=self.user.id, **datasets.delete.TAG) db.session.add(tag) db.session.commit() db.session.refresh(tag) res = self.delete(self.DELETE_URN.format(uuid=tag.uuid)) data = res.json['data'] self.assert200(res) self.assertEqual(data['id'], tag.id) self.assertEqual(data['uuid'], tag.uuid) self.assertEqual(data['label'], tag.label) self.assertEqual(data['reference'], tag.reference) self.assertEqual(data['note'], tag.note) self.assertEqual(len(Tag.query.filter_by(userId=self.user.id).all()), 0)
def test_get_endpoint(self): """ Testing user application GET get endpoint """ res = self.get(self.GET_URN.format(uuid=generate_uuid())) self.assert404(res) # import template datasets to DB app = Application(userId=self.user.id, **datasets.get.APP) db.session.add(app) db.session.commit() db.session.refresh(app) res = self.get(self.GET_URN.format(uuid=app.uuid)) data = res.json['data'] self.assert200(res) self.assertEqual(data['id'], app.id) self.assertEqual(data['uuid'], app.uuid) self.assertEqual(data['label'], app.label) self.assertEqual(data['prefix'], app.prefix) self.assertEqual(data['token'], app.token) self.assertEqual(data['callbackUrl'], app.callbackUrl) self.assertEqual(data['note'], app.note)
def test_get_endpoint(self): """ Testing user template GET get endpoint """ # not found res = self.get(self.GET_URN.format(uuid=generate_uuid())) self.assert404(res) # adding datesets to db templates = [Template(userId=self.user.id, **item) for item in datasets.get.TEMPLATES] db.session.add_all(templates) db.session.commit() # getting template for template in templates: res = self.get(self.GET_URN.format(uuid=template.uuid)) data = res.json['data'] self.assert200(res) self.assertEqual(data['uuid'], template.uuid) self.assertEqual(data['label'], template.label) self.assertEqual(data['text'], template.text) self.assertIsNotNone(data['created'])
def test_get_endpoint(self): """ Testing user template GET get endpoint """ # not found res = self.get(self.GET_URN.format(uuid=generate_uuid())) self.assert404(res) # adding datesets to db templates = [ Template(userId=self.user.id, **item) for item in datasets.get.TEMPLATES ] db.session.add_all(templates) db.session.commit() # getting template for template in templates: res = self.get(self.GET_URN.format(uuid=template.uuid)) data = res.json['data'] self.assert200(res) self.assertEqual(data['uuid'], template.uuid) self.assertEqual(data['label'], template.label) self.assertEqual(data['text'], template.text) self.assertIsNotNone(data['created'])
def test_delete_endpoint(self): """ Testing user application DELETE remove endpoint """ res = self.delete(self.DELETE_URN.format(uuid=generate_uuid())) self.assert404(res) # import template datasets to DB app = Application(userId=self.user.id, **datasets.delete.APP) db.session.add(app) db.session.commit() db.session.refresh(app) res = self.delete(self.DELETE_URN.format(uuid=app.uuid)) data = res.json['data'] self.assert200(res) self.assertEqual(data['id'], app.id) self.assertEqual(data['uuid'], app.uuid) self.assertEqual(data['label'], app.label) self.assertEqual(data['prefix'], app.prefix) self.assertEqual(data['token'], app.token) self.assertEqual(data['callbackUrl'], app.callbackUrl) self.assertEqual(data['note'], app.note) apps = Application.query.filter_by(userId=self.user.id).all() self.assertEqual(len(apps), 0)