From 77d6df6531591ece9d50e177bec6045f13c97ff5 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Mon, 18 Feb 2013 16:09:40 -0500 Subject: [PATCH] basic ec2 and s3 working --- Makefile | 11 ++ README.md | 2 +- moto/__init__.py | 2 + moto/__init__.pyc | Bin 0 -> 233 bytes moto/core/__init__.py | 1 + moto/core/__init__.pyc | Bin 0 -> 197 bytes moto/core/models.py | 40 +++++++ moto/core/models.pyc | Bin 0 -> 1762 bytes moto/ec2/__init__.py | 2 + moto/ec2/__init__.pyc | Bin 0 -> 234 bytes moto/ec2/models.py | 44 +++++++ moto/ec2/models.pyc | Bin 0 -> 2063 bytes moto/ec2/responses.py | 224 ++++++++++++++++++++++++++++++++++++ moto/ec2/responses.pyc | Bin 0 -> 9317 bytes moto/ec2/urls.py | 5 + moto/ec2/urls.pyc | Bin 0 -> 194 bytes moto/ec2/utils.py | 15 +++ moto/ec2/utils.pyc | Bin 0 -> 1121 bytes moto/s3/__init__.py | 2 + moto/s3/__init__.pyc | Bin 0 -> 231 bytes moto/s3/models.py | 57 +++++++++ moto/s3/models.pyc | Bin 0 -> 2674 bytes moto/s3/responses.py | 72 ++++++++++++ moto/s3/responses.pyc | Bin 0 -> 2541 bytes moto/s3/urls.py | 6 + moto/s3/urls.pyc | Bin 0 -> 278 bytes requirements.txt | 6 + setup.py | 14 +++ tests/__init__.pyc | Bin 0 -> 135 bytes tests/test_ec2/test_ec2.py | 29 +++++ tests/test_ec2/test_ec2.pyc | Bin 0 -> 1167 bytes tests/test_s3/test_s3.py | 30 +++++ tests/test_s3/test_s3.pyc | Bin 0 -> 1514 bytes 33 files changed, 561 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 moto/__init__.py create mode 100644 moto/__init__.pyc create mode 100644 moto/core/__init__.py create mode 100644 moto/core/__init__.pyc create mode 100644 moto/core/models.py create mode 100644 moto/core/models.pyc create mode 100644 moto/ec2/__init__.py create mode 100644 moto/ec2/__init__.pyc create mode 100644 moto/ec2/models.py create mode 100644 moto/ec2/models.pyc create mode 100644 moto/ec2/responses.py create mode 100644 moto/ec2/responses.pyc create mode 100644 moto/ec2/urls.py create mode 100644 moto/ec2/urls.pyc create mode 100644 moto/ec2/utils.py create mode 100644 moto/ec2/utils.pyc create mode 100644 moto/s3/__init__.py create mode 100644 moto/s3/__init__.pyc create mode 100644 moto/s3/models.py create mode 100644 moto/s3/models.pyc create mode 100644 moto/s3/responses.py create mode 100644 moto/s3/responses.pyc create mode 100644 moto/s3/urls.py create mode 100644 moto/s3/urls.pyc create mode 100644 requirements.txt create mode 100644 setup.py create mode 100644 tests/__init__.pyc create mode 100644 tests/test_ec2/test_ec2.py create mode 100644 tests/test_ec2/test_ec2.pyc create mode 100644 tests/test_s3/test_s3.py create mode 100644 tests/test_s3/test_s3.pyc diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..94deffdd0 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +SHELL := /bin/bash + +init: + python setup.py develop + pip install -r requirements.txt + +test: + nosetests ./tests/ + +travis: + nosetests ./tests/ diff --git a/README.md b/README.md index 962983d9f..204f20bc4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ Imagine you have the following code that you want to test: ```python import boto from boto.s3.key import Key -conn = boto.connect_s3() class MyModel(object): def __init__(self, name, value): @@ -17,6 +16,7 @@ class MyModel(object): self.value = value def save(self): + conn = boto.connect_s3() bucket = conn.get_bucket('mybucket') k = Key(bucket) k.key = self.name diff --git a/moto/__init__.py b/moto/__init__.py new file mode 100644 index 000000000..8da1c85e7 --- /dev/null +++ b/moto/__init__.py @@ -0,0 +1,2 @@ +from .ec2 import mock_ec2 +from .s3 import mock_s3 diff --git a/moto/__init__.pyc b/moto/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0969fbd608532b765edf72fff4d50ba922b6c5bd GIT binary patch literal 233 zcmX|)K?=e!5Je}Apa_Cz5W%ht*sX{Q*Mb!{-DHtwQB0cRM8TVQPcPt4tA^xF=FjJk ze9xw<*WzU8dot8L9xs6!SCAv}f+|5G^%=R0yrfE^mvqiYFg60n6XFE$!CbX9n?V`> z6fTavJ4z@Rmnam|MlQ-eAqn{(tngJAwl`MX-JLb+U?0|n&f7LBA7U7wb<;Lc>vi|+ Q_iufuVc(@pPWf~30UQ4+l>h($ literal 0 HcmV?d00001 diff --git a/moto/core/__init__.py b/moto/core/__init__.py new file mode 100644 index 000000000..a4f19aed2 --- /dev/null +++ b/moto/core/__init__.py @@ -0,0 +1 @@ +from .models import BaseBackend \ No newline at end of file diff --git a/moto/core/__init__.pyc b/moto/core/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3679b00700431210bafc1bd2ac34c8db3371eb4b GIT binary patch literal 197 zcmY+7zX}2|493$t5K-KG0;f)PaTJlmSx|8ip&V_7V*hcef^Xpa`U0ltVn}{T2;Z0X zJ)69)i-Un*G~BmbG-p^&0UjU-xCjuofs<_c-~>ZflqsX@3A^6hFxtJW4rRm$$)cwt zPayw6E8f+aa3Dqb?$M|nKG3HeFcuY3Nne;Wpwik!SF~Q{XBo3_&BmR3s#yh{TBls;W|?av*?HREVf7$KJF_o!IqmA3+V5 zBIt=LXMQ6;0KOUbDRH7$-tl;LXXe|PZ`b{Gv-RP~wPvoPwtB!6)WqXX80Xnua(c z>IuA&?58P^E&&U}IE{=6!xAe8GCJ+}_>u_o1X}%_(S@m-d@t2;eO2%4G|T&XVC((N zW~GR;LPJY*Y98l9%T*|}(Y6Z3@a{+nM4sR@0&y8i39+YWr07Ud&*3s+cgGHm9I`GQ z!Q!%IOJVP71dB^Ok47FHc_=tXYuE~8nclKtuSkuZfYK?le%duw`Vue@ffR;VjO~P> z9fz&Zc^btf+A!?)^Q^F87;wO)py-4vNZ;_HFjDBR!Y33ORc`w1+K3^D+r-R$ zfMI?@z_nzOvR5=T3avfdBsROWx*2fW4qu9cN4+tgU)_94AJI>jo5l;lUvwJ?(BX0F zO~~p=ZtMa8qTT51F}Z4Yi8gk9+W0g>Cqfl4KAZn*tIPmJl`r7N&rqoqVZP#je>%OryEHCsHXrzmfLvo>T zpqV;x*3Y{L!DMUWWMe*+iKJ^dw(v(VM8%d7&z*ySsU!e*ba`0zqjXP817vMyZx9E( zfoq*Y#&=Led9I6jsD{}}PSvTZsxz(bf-My_ucjPV%{XOl?m6eSS%w3|EMR}*GZeuS z++*!Ngdh{Ii-~`|E;wzXafd`UE9UTHxJ{%MXB$2jR;n9@e5!CP#lj03*+2&iP^7D} zC@(VX)()kO!6N2LoKUV+%Yg4zuBYMb6;*L2-KhzmZ-{^oNx-OuHrv+ba@k+7ENl04 ZY$e41K_gpzR$gICjLa~QnyNX|?jHhXXMz9# literal 0 HcmV?d00001 diff --git a/moto/ec2/__init__.py b/moto/ec2/__init__.py new file mode 100644 index 000000000..f64708fee --- /dev/null +++ b/moto/ec2/__init__.py @@ -0,0 +1,2 @@ +from .models import ec2_backend +mock_ec2 = ec2_backend.decorator \ No newline at end of file diff --git a/moto/ec2/__init__.pyc b/moto/ec2/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..aad71507dad0bda4393b30aea7d51b4c9acc4713 GIT binary patch literal 234 zcmYL^JqrRc42IJ?5kC-I99^6`S&T^C0Mzm<{S(GGKhCSza$9D{-ZLk9N@iX3zXXP#4qVFaEK#{^U>c`H?gwLb7( ziuMW4Yqa4+Cx}CWM&;Ww`Zf-_tg0jldCLD0)^rt@fNc<=d013pk59C|aac#;eDq(C aR7h!R6Qx`>ude5YMv`Qk9v0GLj3)-eEI52- z!E`t(#=$5cw1_c4Xafd>fEWRU4(VYOz{owGzBo6wPX_~&KI%{Hwn?npe%MdSGnC->8U*XSxD<+Qv@QJ36rUr0l1%m?OM`a|&<^Z) zT9|aOYmQA(k4sazL0P-Hnb<8_?u)UW`wzm<24wCSER&Aqzyxy{K$fnOrI-q z3W+{b6no^D5_9wD!V^u4TpO$BycEbb58HV2fub{(JD54x!!CqFkDl{mC`Gcz82A|E zYK(kW2T{nfhE^kH2lw(!gCARGVq8$pXsC4?O6;Fkgw?PlmNm-H0cK@RE=$H;n<?0@ zb;FZF{)_PrZvbOOr;nEzKS0Hv{wov}?SASBbAFlVxx>Ta4ma^{sGH3-hNl=(VQ>p~kH2z<=Yhxt!flaE zA1B4sG_6K5y|RC|*fNaF+Kc=*%z96ilqQZH9FJpeOx(Kowac&j-1+0_q|nj>Kv{2L zLa=&nadmcRBZypTCs2VG`r(x@3_E)fE`h^w``kYJXzKGKZdwwsO7D@jgC5Hreqywb w-{E3SU0zt}T+*F1&XNjXTk(GLueN|I(h80Id4ul-+_E6}kGG+={H^ + 59dbff89-35bd-4eac-99ed-be587EXAMPLE + {{ reservation.id }} + 111122223333 + + + sg-245f6a01 + default + + + + {% for instance in reservation.instances %} + + {{ instance.id }} + ami-60a54009 + + 0 + pending + + + + + 0 + m1.small + 2007-08-07T11:51:50.000Z + + us-east-1b + + default + + + enabled + + true + + + sg-245f6a01 + default + + + paravirtual + + xen + false + + {% endfor %} + + """ + +EC2_DESCRIBE_INSTANCES = """ + fdcdcab1-ae5c-489e-9c33-4637c5dda355 + + {% for reservation in reservations %} + + {{ reservation.id }} + 111122223333 + + + sg-1a2b3c4d + my-security-group + + + + {% for instance in reservation.instances %} + + {{ instance.id }} + ami-1a2b3c4d + + 16 + {{ instance.state }} + + + + + gsg-keypair + 0 + + c1.medium + YYYY-MM-DDTHH:MM:SS+0000 + + us-west-2a + + default + + windows + + disabled + + subnet-1a2b3c4d + vpc-1a2b3c4d + 10.0.0.12 + 46.51.219.63 + true + + + sg-1a2b3c4d + my-security-group + + + x86_64 + ebs + /dev/sda1 + + + /dev/sda1 + + vol-1a2b3c4d + attached + YYYY-MM-DDTHH:MM:SS.SSSZ + true + + + + hvm + ABCDE1234567890123 + + + Name + Windows Instance + + + xen + + + eni-1a2b3c4d + subnet-1a2b3c4d + vpc-1a2b3c4d + Primary network interface + 111122223333 + in-use + 10.0.0.12 + 1b:2b:3c:4d:5e:6f + true + + + sg-1a2b3c4d + my-security-group + + + + eni-attach-1a2b3c4d + 0 + attached + YYYY-MM-DDTHH:MM:SS+0000 + true + + + 46.51.219.63 + 111122223333 + + + + 10.0.0.12 + true + + 46.51.219.63 + 111122223333 + + + + 10.0.0.14 + false + + 46.51.221.177 + 111122223333 + + + + + + + {% endfor %} + + + {% endfor %} + +""" + +EC2_TERMINATE_INSTANCES = """ + + 59dbff89-35bd-4eac-99ed-be587EXAMPLE + + {% for instance in instances %} + + {{ instance.id }} + + 32 + shutting-down + + + 16 + running + + + {% endfor %} + +""" \ No newline at end of file diff --git a/moto/ec2/responses.pyc b/moto/ec2/responses.pyc new file mode 100644 index 0000000000000000000000000000000000000000..83c92271b2cc7a3bb0f6ded1839a8b260aeb0c5c GIT binary patch literal 9317 zcmc&){Z8b_5$}NocDc>nCKp|F|3ssePKOkEJTowS$+5x#(jpz~Wrj;~{DVAp177?w z=WfHY3x6b=*U4+-9r7G`faKThX}ibR!^f_4!;G=3tE#K2tGcS&J^SBZE&j`Y`Dd4m zKQs9MC;ZrJTs(XmBp@VgkfR1^i02s+%#d)F9L?f+mUvG{@PveO=CEinV^o)4V$Y5y^JpKRSv(&&He~QboQ(xd@;LmVJ z-R|+wanEVwxwCkFhM)MqjUW3DE}W3-2Kmq+H?!m#f;Gt35ccbvC*=AGfu!d%BzZ-6 zgYX%NHAk-J$Q!8ve?s2Okq-pl#z0`tN$hJP8s}6O7c;p4aMd zVQ^pd!@j`NLCl*z28)I?;?!FbBz^oyUk>kAxZB#2#z(mGRYm!J64@ajRnL0j|Unr;RL6Y^DhM>rAJQ0`0oH0REN9$ z{k?;&LtPHxkbiN4lBrb2f{Lp4k16MG`V6t@uO3z zh$9C@dNUvUE*IvB=%ucZ92%v|vG1|I=xzzW?7~)XXa0zxVtCdO?GDB+P4u zF^{tgBEf{AMi^bnTB9q;N5m5Qyi2(0La}&LwNPacFw6Yj)e6u7Pj6W4^Q(n@uaBumKQ}YTVLD#+t&UM-|t$GTj6Kaxub%^`}a+4{9C@)ytxq+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e zHuq-chV@t1L(suQS9(!5hui_jbrN!%{AT&~X4yjWUw}=t=etg=sRH2GHf7;k7iO;; zJvNKrX4<$GEh)=g5 zJUSQ&d~gz{fp?U@;C=oOrX_j_vjv3FTI&IBBm4pI;qnGk2Nv!wt;5(nG2^R8#ztdk vt_yE$g@!(V#7w!lIX5@w-sBvU??9fUOPu$hv3r~C cP$8A7nkpzYZ|`BqZA%`=9jmw%#d{{=4RHi7@Bjb+ literal 0 HcmV?d00001 diff --git a/moto/s3/models.py b/moto/s3/models.py new file mode 100644 index 000000000..c24fb89c3 --- /dev/null +++ b/moto/s3/models.py @@ -0,0 +1,57 @@ +# from boto.s3.bucket import Bucket +# from boto.s3.key import Key +import md5 + +from moto.core import BaseBackend + + +class FakeKey(object): + def __init__(self, name, value): + self.name = name + self.value = value + + @property + def etag(self): + value_md5 = md5.new() + value_md5.update(self.value) + return '"{0}"'.format(value_md5.hexdigest()) + +class FakeBucket(object): + def __init__(self, name): + self.name = name + self.keys = [] + + +class MockS3(BaseBackend): + base_url = "https://(.+).s3.amazonaws.com" + + def __init__(self): + self.buckets = {} + + def create_bucket(self, bucket_name): + new_bucket = FakeBucket(name=bucket_name) + self.buckets[bucket_name] = new_bucket + return new_bucket + + def get_bucket(self, bucket_name): + return self.buckets.get(bucket_name) + + def set_key(self, bucket_name, key_name, value): + bucket = self.buckets[bucket_name] + new_key = FakeKey(name=key_name, value=value) + bucket.keys.append(new_key) + + return new_key + + def get_key(self, bucket_name, key_name): + bucket = self.buckets[bucket_name] + found_key = None + for key in bucket.keys: + if key.name == key_name: + found_key = key + break + + return found_key + + +s3_backend = MockS3() diff --git a/moto/s3/models.pyc b/moto/s3/models.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d515c95f1f83d93b878e4728fa14a00a2c9a352e GIT binary patch literal 2674 zcmb_eU2hvj6uq;yH*uTLP#~f})DTs|P|2jl>icu@yNtQdH%&$SaXQx>YG^%hht5a~e8bkvWwzUHggHO@xX*D!dV4QIANE4uFN@I0Zt zgi8&y(78t#wSIGU>RN6x8``{eYMg6UP{y6xaZT9 zm^dCSrfzb=!edshw=nS{eM21Qh`~r-1L#*6wL$#-s;<_!14{vfwqq1We?OWZHDcPJ z-=pGdeU9x5&&AoK$h_5%bbek=N169@>6v|5^e(LPicLZXbzN~uVQ5nfXwmxYVi!+G zXC&G&d!|9R7XUFCY3grbB~5`I;7!wHwP7+XCwA&DlO1eWyQ8BUDJ)u`Z~y) z#YgBqq}xlrDZvw_AbF1+H>?lY0LeWV`T)%_`q(JDelGJt=lE?5zr&UlhN$XL(p}Vc zq;(F(sptSAqdL@$sX?z*SAaIj;||b0^M2yKZM7QBhhH|`aWflbf0g6xg=^;JNK0#3 zUQhT6!|sJNsPrwxfSXi`&NS&x)2S7(hUVt@f5xMUiWsE`>yk}fI>Z3g4g^r=uf)tz z>Y>_om5i}brwDY=UUgrk>B3%9oP=cE)LDiOs|!ybV77#xNRd2by?Xf# z2Ej|XcyC@6kNO1i;3TpD!IfxUldCEv82Wn!$%O>t(NXBz*KP>f)~Hle66%B&K{lD- zrc=%;r8Gpg}c{v*wbXqC$j&L9+V5*5j9L0|~#JGX(px=%fgl4UbnxQlNRY_;lp~_@J zIZr-jN9{>IN4HLoj&3FrcVXxrn&Y(=n>eah>NT{j;1YpSQ25^h!Zx)DRsy-ov%bxJ pV4SJ~ZRs86j?=U7C+l7KsAxP6H}dzSi(`@PM0=I}+xzkU;r|TR`g{NY literal 0 HcmV?d00001 diff --git a/moto/s3/responses.py b/moto/s3/responses.py new file mode 100644 index 000000000..57a44dd08 --- /dev/null +++ b/moto/s3/responses.py @@ -0,0 +1,72 @@ +from jinja2 import Template + +from .models import s3_backend + +def bucket_response(uri, body, headers): + hostname = uri.hostname + bucket_name = hostname.replace(".s3.amazonaws.com", "") + + if uri.method == 'GET': + bucket = s3_backend.get_bucket(bucket_name) + if bucket: + template = Template(S3_BUCKET_GET_RESPONSE) + return template.render(bucket=bucket) + else: + return "", dict(status=404) + else: + new_bucket = s3_backend.create_bucket(bucket_name) + template = Template(S3_BUCKET_CREATE_RESPONSE) + return template.render(bucket=new_bucket) + + +def key_response(uri_info, body, headers): + + key_name = uri_info.path.lstrip('/') + hostname = uri_info.hostname + bucket_name = hostname.replace(".s3.amazonaws.com", "") + + if uri_info.method == 'GET': + key = s3_backend.get_key(bucket_name, key_name) + if key: + return key.value + else: + return "", dict(status=404) + + if uri_info.method == 'PUT': + if body: + new_key = s3_backend.set_key(bucket_name, key_name, body) + return S3_OBJECT_RESPONSE, dict(etag=new_key.etag) + key = s3_backend.get_key(bucket_name, key_name) + if key: + return "", dict(etag=key.etag) + else: + return "" + elif uri_info.method == 'HEAD': + key = s3_backend.get_key(bucket_name, key_name) + return S3_OBJECT_RESPONSE, dict(etag=key.etag) + else: + import pdb;pdb.set_trace() + + +S3_BUCKET_GET_RESPONSE = """\ + {{ bucket.name }}\ + notes/\ + /\ + 1000\ + AKIAIOSFODNN7EXAMPLE\ + 2006-03-01T12:00:00.183Z\ + Iuyz3d3P0aTou39dzbqaEXAMPLE=\ + """ + +S3_BUCKET_CREATE_RESPONSE = """ + + {{ bucket.name }} + +""" + +S3_OBJECT_RESPONSE = """ + + "asdlfkdalsjfsalfkjsadlfjsdjkk" + 2006-03-01T12:00:00.183Z + + """ \ No newline at end of file diff --git a/moto/s3/responses.pyc b/moto/s3/responses.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b1f545e196188fd6038df01f6a95faf3ae05a528 GIT binary patch literal 2541 zcmb_d&2A$_5U%lW>`h2E(nfGVM3GoUpv^e3#KPjWa1z6YBu*GR0-1v~@pO`z%#SnO z-c7RhDLew=%qwu>$fI!M1$Y4Xs%NrRet^R=vU|F#s=uo0{;DSX=S=yxpO(JqQ~G4^ z{sMpb0)vB}K|WDnP}d;C$&iyJKSM#5x>>Aq^aD{hM^0W(^5hh#TOg-M-6AHB37LD>WUrMmr-cHk}LfvP!KX6(O1n5 z!XP>vB2}fQQrT)K-5+rr%MaL&Q$LBM3hh8B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-0,0 +1,29 @@ +import boto +from boto.ec2.instance import Reservation +from sure import expect + +from moto import mock_ec2 + + + +@mock_ec2 +def test_instance_launch_and_terminate(): + conn = boto.connect_ec2('the_key', 'the_secret') + reservation = conn.run_instances('') + reservation.should.be.a(Reservation) + reservation.instances.should.have.length_of(1) + instance = reservation.instances[0] + + reservations = conn.get_all_instances() + reservations.should.have.length_of(1) + reservations[0].id.should.equal(reservation.id) + instances = reservations[0].instances + instances.should.have.length_of(1) + instances[0].id.should.equal(instance.id) + instances[0].state.should.equal('pending') + + conn.terminate_instances(instances[0].id) + + reservations = conn.get_all_instances() + instance = reservations[0].instances[0] + instance.state.should.equal('shutting-down') diff --git a/tests/test_ec2/test_ec2.pyc b/tests/test_ec2/test_ec2.pyc new file mode 100644 index 0000000000000000000000000000000000000000..50053ae6920d0a62fcb0a4f522e1e713bda1f9bb GIT binary patch literal 1167 zcmbtTOK;Oa5T3Q2q|Kubihy!LJ%vLXi5pT?A%VoL2v=Nkv0QseoZ9O&J1$g8PURo- z1K^vrn}lAmyyJQ8H{Z^z{ojM`=i=mRLe1mh`vJ>-fk^Qx%8ACc?oqC&@M!Fjl9*4q zPenlEptb|bTU4}Z+$N>ll(y&>(SxFKM{ur&ZD3}9@LUcRRPI59+Umt!%vot_rzGj0 zbDeN)@4zm~Xwo7TS}V*>1Q8m*&_v5ac~m`|3!&Py?@z?`t)1@}>72_Mvj~4yDnqS2CD0lstPpP2Fqh suB{e2bpNDSLNk;;hOZztr*qnW9#Oh^UX&?%b0Gz-IQr^99e4-9U!lwRlmGw# literal 0 HcmV?d00001 diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py new file mode 100644 index 000000000..0f8444766 --- /dev/null +++ b/tests/test_s3/test_s3.py @@ -0,0 +1,30 @@ +import boto +from boto.s3.key import Key + +from moto import mock_s3 + + +class MyModel(object): + def __init__(self, name, value): + self.name = name + self.value = value + + def save(self): + conn = boto.connect_s3('the_key', 'the_secret') + bucket = conn.get_bucket('mybucket') + k = Key(bucket) + k.key = self.name + k.set_contents_from_string(self.value) + + +@mock_s3 +def test_my_model_save(): + # Create Bucket so that test can run + conn = boto.connect_s3('the_key', 'the_secret') + conn.create_bucket('mybucket') + #################################### + + model_instance = MyModel('steve', 'is awesome') + model_instance.save() + + assert conn.get_bucket('mybucket').get_key('steve').get_contents_as_string() == 'is awesome' diff --git a/tests/test_s3/test_s3.pyc b/tests/test_s3/test_s3.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8fe1e7deb573aede2baf0e881fae82d6a27c594f GIT binary patch literal 1514 zcmb_cyKWOf6uq;%c1TD_6rl(~gQ&KO3kn*9cvdKu7%K&CM)rCfZ0{rTOoA*W4dEO3 zK|X;GfOGCT38D?_o!NWmabM?Lr@wZ#e*Sp&sgU)P;`e` z_vgNBPAgx>Ue&~=7k!99XJmK%Jv?2-d${Y|te!>ZCu1;t>cA>QvBg?V)PerGvFgo|!{4#Pe`)1c{Qwt zH4{MVoMlXQAJc6xD&2(!mNX^j75=W-%nB$<-W&L*SojxyFc}zM!*5XR3A(QH7d0}r zqv5H}nk1kB4uJ!6Fae$1kwqe5EJ*s>x*?ci-!dLc(CsE&6PXY}Y^~TVJRN=Yp{ab% zUCS!k`#iUU3FH|?e@zA^rxmj-xblruAuHIGly6uu3TsZp2iSTO&{c8P)E}11W~nV| zcWHy0K*X15oe)QL;cwBn3lNdOvRPfVBIIyDqCCWEOO$lq?4-M9E75k)v?J4IPaKBl xhe%4vuN-FUTm7SBMVs*)&7x4-C(v&rzB7N6urFJRzM{iG+_ueLvX>t0`~f2}Je~jm literal 0 HcmV?d00001