Tuesday, October 7, 2014

How to send an email with Mandrill and jquery by submit contact form

It's easy to send notification email just by ajax request. Sure would be good to add some validation.
Create simple form contact.html
 <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"></link>  
 <form class="form-horizontal" id="contact">  
 <fieldset>  
 <!-- Form Name -->  
 <legend>Contact Us</legend>  
   
 <!-- Text input-->  
 <div class="form-group">  
  <label class="col-md-4 control-label" for="name">Name</label>   
  <div class="col-md-5">  
  <input id="name" name="name" type="text" placeholder="Your name*" class="form-control input-md" required="">       
  </div>  
 </div>  
   
 <!-- Text input-->  
 <div class="form-group">  
  <label class="col-md-4 control-label" for="email">Email</label>   
  <div class="col-md-5">  
  <input id="email" name="email" type="text" placeholder="Your email*" class="form-control input-md" required="">  
     
  </div>  
 </div>  
   
 <!-- Textarea -->  
 <div class="form-group">  
  <label class="col-md-4 control-label" for="message">Message</label>  
  <div class="col-md-4">             
   <textarea class="form-control" id="message" name="message" cols="6" rows="6"></textarea>  
  </div>  
 </div>  
   
 <!-- Button -->  
 <div class="form-group">  
  <label class="col-md-4 control-label" for="submit"></label>  
  <div class="col-md-4">  
   <button id="submit" name="submit" class="btn btn-primary">Send Message</button>  
  </div>  
 </div>  
   
 </fieldset>  
 </form>  
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script></code>  

And following ajax call:
 jQuery(function($)   
 {  
   $("#contact").submit(function()  
   {  
     var email = $("#email").val(); // get email field value  
     var name = $("#name").val(); // get name field value  
     var msg = $("#message").val(); // get message field value  
     $.ajax(  
     {  
       type: "POST",  
       url: "https://mandrillapp.com/api/1.0/messages/send.json",  
       data: {  
         'key': '#PUT_YOUR_MANDRILL_API_KEY_HERE',  
         'message': {  
           'from_email': email,  
           'from_name': name,  
           'headers': {  
             'Reply-To': email  
           },  
           'subject': 'Message from Contact form',  
           'text': message,  
           'to': [  
           {  
             'email': 'johndoe@email.com',  
             'name': 'John Doe',  
             'type': 'to'  
           }]  
         }  
       }  
     })  
     .done(function(response) {  
       alert('Your message has been sent successfully'); 
       //reset input fields after successful submission  
       $("#name").val('');  
       $("#email").val(''); 
       $("#message").val('');  
     })  
     .fail(function(response) {  
       alert('Error sending message.');  
     });  
     return false; // prevent page refresh  
   });  
 });  

Tuesday, May 20, 2014

Do we really need testers? or Don't do everything by youself

Recently we have had a conversation with colleagues about "Do we really need testers?" Why should we have someone dedicated to this role? Can't I do testing, documenting by myself or with a  help of another developer to get a different point of view? Code review and automation would be done faster by developers. They know product, architecture, they're experienced in development, unit testing, automation. And end-to-end testing could be done with a whole team including product owners and managers. So, why do we need them?

Of course we as engineers can do everything, but one person should not do everything! Developer or tester should be exited about what he/she is doing and it's very rare case when developers like to test thoroughly and waste their time writing test plans, thinking about test strategies, assuming customer point of view, spending time on a long discussions and so on. We are already doing a log of different tasks in today's software development era especially those engineers who are working withing DevOps model. I't not every time possible to do everything with the highest quality and that's basically why we should split our roles at some point. Testers becoming more technical, they're developing automation frameworks, supporting environments, deploying, maintaining and more responsibilities are coming all the time. Not only test plans, reporting and manual testing anymore. And are you still really want to do everything and more by yourself?

What to choose as an IDE for python development is up to you...

... It's your choice whether you develop in vim, Notepad++ or modern IDE. There are always pros and cons and every developer has his own preferences. I use several of them daily: Notepad++ if I need to write short script very fast, iPython command line if I need to check some expressions or object properties, Eclipse from historical reason for big projects, PyCharm for personal usage (and thinking to move from Eclipse to it), vim if I'm working in Linux. Didn't try sublime, but I'm satisfied with the tools above.

Wednesday, May 22, 2013

How to setup Jenkins for python for tests

How to configure jenkins to run python tests after every commit or by schedule:
Download and install java on your computer.
Download last stable version of jenkins for your operating system from the official site
Run with the following command:
java -jar jenkins.war
Assuming that you already have virtualenv and create your virtual environment
$virtualenv mytestenv
$source mytestenv/bin/activate
Install dependencies for python, in our case: nose and nosexunit (for writing and running tests),
pip install nose
pip install nosexunit
pip install selenium

open a browser and go to http://127.0.0.1:8080 jenkins web interface
install git plugin

Create new job and select run bash:
Put the path to your git working copy: /home/yourname/your_repository

And add the following script:
#!/bin/bash -ex
source /home/andrii/Downloads/mytestdir/bin/activate
nosetests tests.py --with-nosexunit

And add it for reporting:
target/NoseXUnit/core/*.xml