def add_schema(self, workspace, model_class):
     schema_string = serialize(model_class)
     schema = json.loads(schema_string)
     workspace.sm.store_data(
         os.path.join(
             '_schemas',
             '%(namespace)s.%(name)s.avsc' % schema),
         schema_string, 'Writing the schema.')
 def test_get_schema(self):
     schema_string = serialize(TestPerson)
     schema = json.loads(schema_string)
     self.workspace.sm.store_data(
         os.path.join('_schemas', '%(namespace)s.%(name)s.avsc' % schema),
         schema_string, 'Writing the schema.')
     found_schema = get_schema(self.workspace.repo,
                               '%(namespace)s.%(name)s' % schema).to_json()
     self.assertEqual(found_schema['namespace'], schema['namespace'])
     self.assertEqual(found_schema['name'], schema['name'])
 def test_format_content_type_object(self):
     p = TestPerson({'name': 'Foo', 'age': 1})
     schema_string = serialize(TestPerson)
     schema = json.loads(schema_string)
     self.workspace.sm.store_data(
         os.path.join('_schemas', '%(namespace)s.%(name)s.avsc' % schema),
         schema_string, 'Writing the schema.')
     self.workspace.save(p, 'Saving a person.')
     model_obj = format_content_type_object(
         self.workspace.repo, '%(namespace)s.%(name)s' % schema, p.uuid)
     self.assertEqual(TestPerson(model_obj), p)
 def setUp(self):
     self.workspace = self.mk_workspace()
     schema_string = serialize(TestPerson)
     schema = json.loads(schema_string)
     self.workspace.sm.store_data(
         os.path.join('_schemas', '%(namespace)s.%(name)s.avsc' % schema),
         schema_string, 'Writing the schema.')
     self.person = TestPerson({'name': 'Foo', 'age': 1})
     self.workspace.save(self.person, 'Saving a person.')
     self.config = testing.setUp(settings={
         'repo.storage_path': self.WORKING_DIR,
     })
    def test_put(self):
        request = testing.DummyRequest()
        request.schema = avro.schema.parse(serialize(TestPerson)).to_json()
        request.schema_data = dict(self.person)
        request.matchdict = {
            'name': os.path.basename(self.workspace.working_dir),
            'content_type': fqcn(TestPerson),
            'uuid': self.person.uuid,
        }
        request.registry = self.config.registry
        resource = ContentTypeResource(request)

        with patch.object(request.registry, 'notify') as mocked_notify:
            object_data = resource.put()
            self.assertEqual(TestPerson(object_data), self.person)
            (event, ) = mocked_notify.call_args[0]
            self.assertIsInstance(event, ContentTypeObjectUpdated)
            self.assertEqual(event.repo, self.workspace.repo)
            self.assertEqual(event.model, self.person)
            self.assertEqual(event.change_type, 'update')