def youckan_api_response(**kwargs): """A YouCKAN ME API response factory""" data = { "profile": { "website": faker.url(), "city": faker.city(), "about": faker.text(), "avatar": faker.url() + "avatar.png", }, "first_name": faker.first_name(), "last_name": faker.last_name(), "email": faker.email(), "is_active": True, "is_superuser": False, "date_joined": datetime.now().isoformat(), "slug": None, } for key in data.keys(): if key in kwargs: data[key] = kwargs[key] data["fullname"] = " ".join((data["first_name"], data["last_name"])) if not data["slug"]: data["slug"] = slugify.slugify(data["fullname"].lower()) return data
def resource_factory(): return { "resource_group_id": str(uuid4()), "cache_last_updated": None, "revision_timestamp": "2013-10-01T15:59:56.322481", "webstore_last_updated": "2013-10-01T17:59:56.238951", "id": str(uuid4()), "size": "1375", "state": "active", "hash": "689afc083c6316259955f499580bdf41bfc5e495", "description": faker.paragraph(), "format": "CSV", "tracking_summary": { "total": 0, "recent": 0 }, "mimetype_inner": None, "mimetype": "text/csv", "cache_url": None, "name": faker.sentence(), "created": "2013-08-01T09:43:09.031465", "url": faker.url(), "webstore_url": "active", "last_modified": "2013-10-01T17:59:55.552785", "position": 0, "revision_id": str(uuid4()), "resource_type": "file.upload" }
def test_create_source_with_owner(self): '''It should create and attach a new source to an owner''' user = self.login() data = {'name': faker.word(), 'url': faker.url(), 'backend': 'factory'} response = self.post(url_for('api.harvest_sources'), data) self.assert201(response) source = response.json self.assertEqual(source['validation']['state'], VALIDATION_PENDING) self.assertEqual(source['owner']['id'], str(user.id)) self.assertIsNone(source['organization'])
def test_create_source_with_org_not_member(self): '''It should create and attach a new source to an organization''' user = self.login() member = Member(user=user, role='editor') org = OrganizationFactory(members=[member]) data = { 'name': faker.word(), 'url': faker.url(), 'backend': 'factory', 'organization': str(org.id) } response = self.post(url_for('api.harvest_sources'), data) self.assert403(response)
def test_create_source_with_owner(self): '''It should create and attach a new source to an owner''' user = self.login() data = { 'name': faker.word(), 'url': faker.url(), 'backend': 'factory' } response = self.post(url_for('api.harvest_sources'), data) self.assert201(response) source = response.json self.assertEqual(source['validation']['state'], VALIDATION_PENDING) self.assertEqual(source['owner']['id'], str(user.id)) self.assertIsNone(source['organization'])
def test_create_source_with_org(self): '''It should create and attach a new source to an organization''' user = self.login() member = Member(user=user, role='admin') org = OrganizationFactory(members=[member]) data = { 'name': faker.word(), 'url': faker.url(), 'backend': 'factory', 'organization': str(org.id) } response = self.post(url_for('api.harvest_sources'), data) self.assert201(response) source = response.json self.assertEqual(source['validation']['state'], VALIDATION_PENDING) self.assertIsNone(source['owner']) self.assertEqual(source['organization']['id'], str(org.id))
def test_create_source(self): source_url = faker.url() with self.assert_emit(signals.harvest_source_created): source = actions.create_source('Test source', source_url, 'factory') self.assertEqual(source.name, 'Test source') self.assertEqual(source.slug, 'test-source') self.assertEqual(source.url, source_url) self.assertEqual(source.backend, 'factory') self.assertEqual(source.frequency, 'manual') self.assertTrue(source.active) self.assertIsNone(source.owner) self.assertIsNone(source.organization) self.assertEqual(source.validation.state, VALIDATION_PENDING) self.assertIsNone(source.validation.on) self.assertIsNone(source.validation.by) self.assertIsNone(source.validation.comment)
def test_defaults(self): source = HarvestSource.objects.create(name='Test', url=faker.url()) self.assertEqual(source.name, 'Test') self.assertEqual(source.slug, 'test')