How to use getContenttype method in autotest

Best Python code snippet using autotest_python

test_contenttype.py

Source:test_contenttype.py Github

copy

Full Screen

1##########################################################################2#3# Copyright (c) 2002-2005, Benjamin Saller <bcsaller@ideasuite.com>, and4# the respective authors. All rights reserved.5# For a list of Archetypes contributors see docs/CREDITS.txt.6#7# Redistribution and use in source and binary forms, with or without8# modification, are permitted provided that the following conditions are met:9#10# * Redistributions of source code must retain the above copyright notice, this11# list of conditions and the following disclaimer.12# * Redistributions in binary form must reproduce the above copyright notice,13# this list of conditions and the following disclaimer in the documentation14# and/or other materials provided with the distribution.15# * Neither the name of the author nor the names of its contributors may be used16# to endorse or promote products derived from this software without specific17# prior written permission.18#19# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED20# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED21# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS22# FOR A PARTICULAR PURPOSE.23#24##########################################################################25"""26"""27import os28from Products.Archetypes.tests.attestcase import ATTestCase29from Products.Archetypes.tests.utils import PACKAGE_HOME30# this trigger zope imports31from Products.Archetypes.tests.test_classgen import Dummy32from Products.Archetypes.tests.test_classgen import gen_dummy33from Products.Archetypes.tests.test_classgen import default_text34from Products.Archetypes.atapi import *35class GetContentTypeTest(ATTestCase):36 def afterSetUp(self):37 gen_dummy()38 self._dummy = dummy = Dummy(oid='dummy')39 self._dummy.initializeArchetype()40 def test_textfieldwithmime(self):41 obj = self._dummy42 field = obj.getField('atextfield')43 self.assertEqual(field.getContentType(obj), 'text/x-rst')44 self.assertEqual(field.getRaw(obj), default_text)45 obj.setAtextfield('Bla', mimetype='text/x-rst')46 self.assertEqual(field.getContentType(obj), 'text/x-rst')47 self.assertEqual(field.getRaw(obj), 'Bla')48 def test_textfieldwithmime2(self):49 obj = self._dummy50 field = obj.getField('atextfield')51 obj.setAtextfield('Bla', mimetype='text/structured')52 self.assertEqual(field.getRaw(obj), 'Bla')53 self.assertEqual(field.getContentType(obj), 'text/structured')54 def test_textfieldwithoutmime(self):55 obj = self._dummy56 field = obj.getField('atextfield')57 obj.setAtextfield('Bla')58 self.assertEqual(str(field.getRaw(obj)), 'Bla')59 self.assertEqual(field.getContentType(obj), 'text/plain')60 def test_textfielduploadwithoutmime(self):61 obj = self._dummy62 file = open(os.path.join(PACKAGE_HOME, 'input', 'rest1.tgz'), 'r')63 field = obj.getField('atextfield')64 obj.setAtextfield(file)65 file.close()66 self.assertEqual(field.getContentType(obj), 'application/x-tar')67 def test_filefieldwithmime(self):68 obj = self._dummy69 field = obj.getField('afilefield')70 obj.setAfilefield('Bla', mimetype='text/x-rst')71 self.assertEqual(str(obj.getAfilefield()), 'Bla')72 self.assertEqual(field.getContentType(obj), 'text/x-rst')73 def test_filefieldwithmime2(self):74 obj = self._dummy75 field = obj.getField('afilefield')76 obj.setAfilefield('Bla', mimetype='text/structured')77 self.assertEqual(str(obj.getAfilefield()), 'Bla')78 self.assertEqual(field.getContentType(obj), 'text/structured')79 def test_filefieldwithoutmime(self):80 obj = self._dummy81 field = obj.getField('afilefield')82 obj.setAfilefield('Bla')83 self.assertEqual(str(obj.getAfilefield()), 'Bla')84 self.assertEqual(field.getContentType(obj), 'text/plain')85 def test_filefielduploadwithoutmime(self):86 obj = self._dummy87 file = open(os.path.join(PACKAGE_HOME, 'input', 'rest1.tgz'), 'r')88 field = obj.getField('afilefield')89 obj.setAfilefield(file)90 file.close()91 self.assertEqual(field.getContentType(obj), 'application/x-tar')92class SetContentTypeTest(ATTestCase):93 def afterSetUp(self):94 gen_dummy()95 self._dummy = dummy = Dummy(oid='dummy')96 self._dummy.initializeArchetype()97 file1 = open(os.path.join(PACKAGE_HOME, 'input', 'rest1.tgz'), 'r')98 file2 = open(os.path.join(PACKAGE_HOME, 'input', 'word.doc'), 'r')99 # afilefield is the primary field100 dummy.setAfilefield(file1)101 dummy.setAnotherfilefield(file2)102 file1.close()103 file2.close()104 def testMutatorSetContentType(self):105 obj = self._dummy106 field1 = obj.getField('afilefield')107 field2 = obj.getField('anotherfilefield')108 mimetype1 = 'application/x-tar'109 mimetype2 = 'application/msword'110 self.assertEqual(field1.getContentType(obj), mimetype1)111 self.assertEqual(field2.getContentType(obj), mimetype2)112 def testBaseObjectPrimaryFieldSetContentType(self):113 obj = self._dummy114 mimetype1 = 'application/x-gzip'115 mimetype2 = 'application/pdf'116 obj.setContentType(mimetype1)117 obj.setContentType(mimetype2, 'anotherfilefield')118 self.assertEqual(obj.getContentType(), mimetype1)119 self.assertEqual(obj.getContentType('afilefield'), mimetype1)120 self.assertEqual(obj.getContentType('anotherfilefield'), mimetype2)121 def testBaseObjectSetContentType(self):122 obj = self._dummy123 mimetype1 = 'application/x-deb'124 mimetype2 = 'application/x-compressed-tar'125 obj.setContentType(mimetype1, 'afilefield')126 obj.setContentType(mimetype2, 'anotherfilefield')127 self.assertEqual(obj.getContentType(), mimetype1)128 self.assertEqual(obj.getContentType('afilefield'), mimetype1)129 self.assertEqual(obj.getContentType('anotherfilefield'), mimetype2)130 def testFieldSetContentType(self):131 obj = self._dummy132 field1 = obj.getField('afilefield')133 field2 = obj.getField('anotherfilefield')134 mimetype1 = 'image/jpeg'135 mimetype2 = 'audio/mpeg'136 field1.setContentType(obj, mimetype1)137 field2.setContentType(obj, mimetype2)138 self.assertEqual(field1.getContentType(obj), mimetype1)...

Full Screen

Full Screen

getContentType-test.js

Source:getContentType-test.js Github

copy

Full Screen

1import getContentType from '../getContentType.js';2describe('getContentType', () => {3 it('returns text/plain for LICENSE|README|CHANGES|AUTHORS|Makefile', () => {4 expect(getContentType('AUTHORS')).toBe('text/plain');5 expect(getContentType('CHANGES')).toBe('text/plain');6 expect(getContentType('LICENSE')).toBe('text/plain');7 expect(getContentType('Makefile')).toBe('text/plain');8 expect(getContentType('PATENTS')).toBe('text/plain');9 expect(getContentType('README')).toBe('text/plain');10 });11 it('returns text/plain for .*rc files', () => {12 expect(getContentType('.eslintrc')).toBe('text/plain');13 expect(getContentType('.babelrc')).toBe('text/plain');14 expect(getContentType('.anythingrc')).toBe('text/plain');15 });16 it('returns text/plain for .git* files', () => {17 expect(getContentType('.gitignore')).toBe('text/plain');18 expect(getContentType('.gitanything')).toBe('text/plain');19 });20 it('returns text/plain for .*ignore files', () => {21 expect(getContentType('.eslintignore')).toBe('text/plain');22 expect(getContentType('.anythingignore')).toBe('text/plain');23 });24 it('returns text/plain for .ts(x) files', () => {25 expect(getContentType('app.ts')).toBe('text/plain');26 expect(getContentType('app.d.ts')).toBe('text/plain');27 expect(getContentType('app.tsx')).toBe('text/plain');28 });29 it('returns text/plain for .flow files', () => {30 expect(getContentType('app.js.flow')).toBe('text/plain');31 });32 it('returns text/plain for .lock files', () => {33 expect(getContentType('yarn.lock')).toBe('text/plain');34 });35 it('returns application/json for .map files', () => {36 expect(getContentType('react.js.map')).toBe('application/json');37 expect(getContentType('react.json.map')).toBe('application/json');38 });...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful