Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle session in Clojure web application tests written with ring-mock?

In my application, I need a functionality where one request fetches a token(random string) from the server which is stored in the session and the second request is made with this token.

When I make the requests in my tests using ring-mock, the second request says the token is not in session. I assume both requests are independent in test scenario.

How do I maintain a session when issuing multiple requests using ring-mock for writing tests? Or is there any other library that I can use for tests in such cases?

like image 976
Devasia Joseph Avatar asked May 03 '14 08:05

Devasia Joseph


People also ask

What is ring in Clojure?

Introduction Ring is a library for writing web applications in Clojure. It supports everything needed to write fully-featured web apps and has a thriving ecosystem to make it even more powerful. In this tutorial, we'll give an introduction to Ring, and show some of the things that can we can achieve with it.

What are threading macros in CL Clojure?

Clojure also offers a way to chain many together in a more natural way – by the use of Threading Macros. These are a way to provide a list of functions to call, each with the output of the previous one. In particular, we want the Thread First macro, ->.

Where does ring store session data?

By default, this stores session data in memory. We can change this if needed, and Ring comes with an alternative store that uses cookies to store all of the session data.


1 Answers

As per the suggestion by James Reeves through twitter, I was able to solve this problem by using peridot. It has session handling for writing tests.

like image 200
Devasia Joseph Avatar answered Nov 15 '22 04:11

Devasia Joseph